@Override public PropertyDefinition define() { PropertyDefinition propertyDefinition = super.define(); savePropertyDefinition(propertyDefinition); return propertyDefinition; } };
@Override public PropertyDefinition define() { PropertyDefinition propertyDefinition = super.define(); savePropertyDefinition(propertyDefinition); return propertyDefinition; } };
@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; }
@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 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(); }
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; }
@Override protected void importOntologyAnnotationProperty(OWLOntology o, OWLAnnotationProperty annotationProperty, File inDir, Authorizations authorizations) { super.importOntologyAnnotationProperty(o, annotationProperty, inDir, authorizations); String about = annotationProperty.getIRI().toString(); LOGGER.debug("disabling index for annotation property: " + about); if (!graph.isPropertyDefined(about)) { graph.defineProperty(about).dataType(String.class) .textIndexHint(TextIndexHint.NONE) .define(); } }
@Test public void testGraphQueryTextVertexDifferentAuths() { graph.defineProperty("title").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.defineProperty("fullText").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("title", "hello", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_B) .setProperty("fullText", StreamingPropertyValue.create("this is text with hello"), VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Vertex> vertices = graph.query("hello", AUTHORIZATIONS_A).vertices(); assertResultsCount(1, 1, (QueryResultsIterable) vertices); vertices = graph.query("hello", AUTHORIZATIONS_A_AND_B).vertices(); assertResultsCount(2, 2, (QueryResultsIterable) vertices); }
@Test public void testGraphQueryTextVertexDifferentAuths() { graph.defineProperty("title").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.defineProperty("fullText").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("title", "hello", VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_B) .setProperty("fullText", StreamingPropertyValue.create("this is text with hello"), VISIBILITY_EMPTY) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); Iterable<Vertex> vertices = graph.query("hello", AUTHORIZATIONS_A).vertices(); assertResultsCount(1, 1, (QueryResultsIterable) vertices); vertices = graph.query("hello", AUTHORIZATIONS_A_AND_B).vertices(); assertResultsCount(2, 2, (QueryResultsIterable) vertices); }
@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)); }
@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)); }
@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 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 testGraphQueryWithANDOperatorAndWithExactMatchFields() { graph.defineProperty("firstName").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("firstName", "Joe", VISIBILITY_A) .setProperty("lastName", "Ferner", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("firstName", "Joe", VISIBILITY_A) .setProperty("lastName", "Smith", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assumeTrue("lucene and queries not supported", isLuceneQueriesSupported() && isLuceneAndQueriesSupported()); Iterable<Vertex> vertices = graph.query("Joe AND ferner", AUTHORIZATIONS_A) .vertices(); Assert.assertEquals(1, count(vertices)); }
@Test public void testGraphQueryWithANDOperatorAndWithExactMatchFields() { graph.defineProperty("firstName").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("firstName", "Joe", VISIBILITY_A) .setProperty("lastName", "Ferner", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("firstName", "Joe", VISIBILITY_A) .setProperty("lastName", "Smith", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.flush(); assumeTrue("lucene and queries not supported", isLuceneQueriesSupported() && isLuceneAndQueriesSupported()); Iterable<Vertex> vertices = graph.query("Joe AND ferner", AUTHORIZATIONS_A) .vertices(); Assert.assertEquals(1, count(vertices)); }
@Test public void testGraphQueryHasWithSpacesAndFieldedQueryString() { assumeTrue("fielded query not supported", isFieldNamesInQuerySupported()); graph.defineProperty("http://vertexium.org#name").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("http://vertexium.org#name", "Joe Ferner", VISIBILITY_A) .setProperty("propWithHyphen", "hyphen-word", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("http://vertexium.org#name", "Joe Smith", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); assumeTrue("lucene queries", isLuceneQueriesSupported()); Iterable<Vertex> vertices = graph.query("http\\:\\/\\/vertexium.org#name:Joe", AUTHORIZATIONS_A) .vertices(); Assert.assertEquals(2, count(vertices)); vertices = graph.query("http\\:\\/\\/vertexium.org#name:\"Joe Ferner\"", AUTHORIZATIONS_A) .vertices(); Assert.assertEquals(1, count(vertices)); }
@Test public void testGraphQueryHasWithSpacesAndFieldedQueryString() { assumeTrue("fielded query not supported", isFieldNamesInQuerySupported()); graph.defineProperty("http://vertexium.org#name").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("http://vertexium.org#name", "Joe Ferner", VISIBILITY_A) .setProperty("propWithHyphen", "hyphen-word", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); graph.prepareVertex("v2", VISIBILITY_A) .setProperty("http://vertexium.org#name", "Joe Smith", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); assumeTrue("lucene queries", isLuceneQueriesSupported()); Iterable<Vertex> vertices = graph.query("http\\:\\/\\/vertexium.org#name:Joe", AUTHORIZATIONS_A) .vertices(); Assert.assertEquals(2, count(vertices)); vertices = graph.query("http\\:\\/\\/vertexium.org#name:\"Joe Ferner\"", AUTHORIZATIONS_A) .vertices(); Assert.assertEquals(1, count(vertices)); }
@Test public void testAddValuesToExistingProperties() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); graph.defineProperty("p1").dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); v1.addPropertyValue("k1", "p1", "val1", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds(), "v1"); v1.addPropertyValue("k2", "p1", "val2", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val2").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val3").vertexIds()); v1.addPropertyValue("k1", "p1", "val3", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val3").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val2").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds()); }
@Test public void testAddValuesToExistingProperties() { Vertex v1 = graph.addVertex("v1", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); graph.defineProperty("p1").dataType(String.class).sortable(true).textIndexHint(TextIndexHint.ALL).define(); v1.addPropertyValue("k1", "p1", "val1", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds(), "v1"); v1.addPropertyValue("k2", "p1", "val2", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val2").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val3").vertexIds()); v1.addPropertyValue("k1", "p1", "val3", VISIBILITY_A, AUTHORIZATIONS_ALL); getGraph().flush(); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val3").vertexIds(), "v1"); assertIdsAnyOrder(getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val2").vertexIds(), "v1"); assertResultsCount(0, 0, getGraph().query(AUTHORIZATIONS_ALL).has("p1", "val1").vertexIds()); }