@Override protected Graph getGraph() { Graph graph = super.getGraph(); graph.defineProperty(VisalloProperties.TERM_MENTION_CONCEPT_TYPE.getPropertyName()).dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.defineProperty(VisalloProperties.TERM_MENTION_VISIBILITY_JSON.getPropertyName()).dataType(String.class).define(); graph.defineProperty(VisalloProperties.TERM_MENTION_TITLE.getPropertyName()).dataType(String.class).define(); graph.defineProperty(VisalloProperties.TERM_MENTION_PROCESS.getPropertyName()).dataType(String.class).define(); graph.defineProperty(VisalloProperties.TERM_MENTION_PROPERTY_KEY.getPropertyName()).dataType(String.class).define(); graph.defineProperty(VisalloProperties.TERM_MENTION_PROPERTY_NAME.getPropertyName()).dataType(String.class).define(); graph.defineProperty(VisalloProperties.TERM_MENTION_START_OFFSET.getPropertyName()).dataType(Integer.class).define(); graph.defineProperty(VisalloProperties.TERM_MENTION_END_OFFSET.getPropertyName()).dataType(Integer.class).define(); return graph; }
) { if (!graph.isPropertyDefined(propertyName)) { DefinePropertyBuilder builder = graph.defineProperty(propertyName).dataType(dataType).sortable(sortable); if (textIndexHint != null) { builder.textIndexHint(textIndexHint); builder.boost(boost); } else { LOGGER.warn("Field boosting is not support by the graph"); builder.define(); } else { PropertyDefinition propertyDefinition = graph.getPropertyDefinition(propertyName);
@Test public void testFieldBoost() throws Exception { assumeTrue("Boost not supported", graph.isFieldBoostSupported()); graph.defineProperty("a") .dataType(String.class) .textIndexHint(TextIndexHint.ALL) .boost(1) .define(); graph.defineProperty("b") .dataType(String.class) .textIndexHint(TextIndexHint.ALL) .boost(2) .define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("a", "Test Value", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("b", "Test Value", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); assertVertexIds(graph.query("Test", AUTHORIZATIONS_A).vertices(), "v2", "v1"); }
@Test public void testGraphQuerySortOnPropertyThatHasNoValuesInTheIndex() { graph.defineProperty("age").dataType(Integer.class).sortable(true).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("name", "joe", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("name", "bob", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).sort("age", SortDirection.ASCENDING).vertices(); Assert.assertEquals(2, count(vertices)); }
@Override public PropertyDefinition define() { PropertyDefinition propertyDefinition = super.define(); savePropertyDefinition(propertyDefinition); return propertyDefinition; } };
@Test public void testGraphQuerySortOnPropertyThatHasNoValuesInTheIndex() { graph.defineProperty("age").dataType(Integer.class).sortable(true).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("name", "joe", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("name", "bob", VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A).sort("age", SortDirection.ASCENDING).vertices(); Assert.assertEquals(2, count(vertices)); }
@Override public PropertyDefinition define() { PropertyDefinition propertyDefinition = super.define(); savePropertyDefinition(propertyDefinition); return propertyDefinition; } };
protected Graph getGraph() { if (graph == null) { Map graphConfiguration = getConfigurationMap(); InMemoryGraphConfiguration inMemoryGraphConfiguration = new InMemoryGraphConfiguration(graphConfiguration); graph = InMemoryGraph.create(inMemoryGraphConfiguration, getGraphIdGenerator(), getGraphSearchIndex(inMemoryGraphConfiguration)); graph.defineProperty(VisalloProperties.CONCEPT_TYPE.getPropertyName()).dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.defineProperty(VisalloProperties.MODIFIED_BY.getPropertyName()).dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.defineProperty(VisalloProperties.MODIFIED_DATE.getPropertyName()).dataType(Date.class).define(); graph.defineProperty(VisalloProperties.VISIBILITY_JSON.getPropertyName()).dataType(String.class).define(); graph.defineProperty(VisalloProperties.TEXT.getPropertyName()).dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define(); } return graph; }
@Test public void testFieldBoost() throws Exception { assumeTrue("Boost not supported", graph.isFieldBoostSupported()); graph.defineProperty("a") .dataType(String.class) .textIndexHint(TextIndexHint.ALL) .boost(1) .define(); graph.defineProperty("b") .dataType(String.class) .textIndexHint(TextIndexHint.ALL) .boost(2) .define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("a", "Test Value", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("b", "Test Value", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); assertVertexIds(graph.query("Test", AUTHORIZATIONS_A).vertices(), "v2", "v1"); }
@Override protected boolean migrate(Graph graph) { LOGGER.info("Updating Vertexium property definitions."); graph.defineProperty(OntologyProperties.DISPLAY_NAME.getPropertyName()) .dataType(String.class) .textIndexHint(TextIndexHint.EXACT_MATCH) .define(); graph.defineProperty(OntologyProperties.INTENT.getPropertyName()) .dataType(String.class) .textIndexHint(TextIndexHint.EXACT_MATCH) .define(); graph.defineProperty(OntologyProperties.USER_VISIBLE.getPropertyName()) .dataType(Boolean.TYPE) .define(); graph.defineProperty(OntologyProperties.SEARCHABLE.getPropertyName()) .dataType(Boolean.TYPE) .define(); graph.defineProperty(OntologyProperties.SORTABLE.getPropertyName()) .dataType(Boolean.TYPE) .define(); graph.defineProperty(OntologyProperties.ADDABLE.getPropertyName()) .dataType(Boolean.TYPE) .define(); return true; }
@Test public void testGraphQueryWithBoolean() { graph.defineProperty("boolean").dataType(Boolean.class).define(); graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "boolean", true, VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query("zzzzz", AUTHORIZATIONS_A).vertices(); assertResultsCount(0, 0, vertices); vertices = graph.query(AUTHORIZATIONS_A).has("boolean", true).vertices(); assertResultsCount(1, 1, vertices); vertices = graph.query(AUTHORIZATIONS_A).has("boolean", false).vertices(); assertResultsCount(0, 0, vertices); }
@Test public void testLargeFieldValuesThatAreMarkedWithExactMatch() { graph.defineProperty("field1").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); StringBuilder largeText = new StringBuilder(); for (int i = 0; i < 10000; i++) { largeText.append("test "); } graph.prepareVertex("v1", VISIBILITY_EMPTY) .addPropertyValue("", "field1", largeText.toString(), VISIBILITY_EMPTY) .save(AUTHORIZATIONS_EMPTY); graph.flush(); }
@Test public void testGraphQueryIn() { String namePropertyName = "full.name"; graph.defineProperty("age").dataType(Integer.class).sortable(true).define(); graph.defineProperty(namePropertyName).dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty(namePropertyName, "joe ferner", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty(namePropertyName, "bob smith", VISIBILITY_B) .setProperty("age", 25, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v3", VISIBILITY_A) .setProperty(namePropertyName, "tom thumb", VISIBILITY_A) .setProperty("age", 30, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); List<String> strings = new ArrayList<>(); strings.add("joe ferner"); strings.add("tom thumb"); Iterable<Vertex> results = graph.query(AUTHORIZATIONS_A_AND_B).has(namePropertyName, Contains.IN, strings).vertices(); assertEquals(2, ((IterableWithTotalHits) results).getTotalHits()); assertVertexIdsAnyOrder(results, "v1", "v3"); }
@Test public void testLargeFieldValuesThatAreMarkedWithExactMatch() { graph.defineProperty("field1").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); StringBuilder largeText = new StringBuilder(); for (int i = 0; i < 10000; i++) { largeText.append("test "); } graph.prepareVertex("v1", VISIBILITY_EMPTY) .addPropertyValue("", "field1", largeText.toString(), VISIBILITY_EMPTY) .save(AUTHORIZATIONS_EMPTY); graph.flush(); }
@Test public void testGraphQueryIn() { String namePropertyName = "full.name"; graph.defineProperty("age").dataType(Integer.class).sortable(true).define(); graph.defineProperty(namePropertyName).dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty(namePropertyName, "joe ferner", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty(namePropertyName, "bob smith", VISIBILITY_B) .setProperty("age", 25, VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v3", VISIBILITY_A) .setProperty(namePropertyName, "tom thumb", VISIBILITY_A) .setProperty("age", 30, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); List<String> strings = new ArrayList<>(); strings.add("joe ferner"); strings.add("tom thumb"); Iterable<Vertex> results = graph.query(AUTHORIZATIONS_A_AND_B).has(namePropertyName, Contains.IN, strings).vertices(); assertEquals(2, ((IterableWithTotalHits) results).getTotalHits()); assertVertexIdsAnyOrder(results, "v1", "v3"); }
@Test public void testGraphQueryWithBoolean() { graph.defineProperty("boolean").dataType(Boolean.class).define(); graph.prepareVertex("v1", VISIBILITY_A) .addPropertyValue("k1", "boolean", true, VISIBILITY_A) .save(AUTHORIZATIONS_A); graph.flush(); QueryResultsIterable<Vertex> vertices = graph.query("zzzzz", AUTHORIZATIONS_A).vertices(); assertResultsCount(0, 0, vertices); vertices = graph.query(AUTHORIZATIONS_A).has("boolean", true).vertices(); assertResultsCount(1, 1, vertices); vertices = graph.query(AUTHORIZATIONS_A).has("boolean", false).vertices(); assertResultsCount(0, 0, vertices); }