@Override public PropertyDefinition define() { PropertyDefinition propertyDefinition = super.define(); try { getSearchIndex().addPropertyDefinition(propertyDefinition); } catch (IOException e) { throw new SecureGraphException("Could not add property definition to search index", e); } setMetadata(METADATA_DEFINE_PROPERTY_PREFIX + propertyName, propertyDefinition); return propertyDefinition; } };
@Override public PropertyDefinition define() { PropertyDefinition propertyDefinition = super.define(); try { getSearchIndex().addPropertyDefinition(propertyDefinition); } catch (IOException e) { throw new SecureGraphException("Could not add property definition to search index", e); } setMetadata(METADATA_DEFINE_PROPERTY_PREFIX + propertyName, propertyDefinition); return propertyDefinition; } };
@Test public void testFieldBoost() throws Exception { if (!graph.isFieldBoostSupported()) { LOGGER.warn("Boost not supported"); return; } 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(), new String[]{"v2", "v1"}); }
@Test public void testFieldBoost() throws Exception { if (!graph.isFieldBoostSupported()) { LOGGER.warn("Boost not supported"); return; } 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(), new String[]{"v2", "v1"}); }
@Test public void testTextIndexStreamingPropertyValue() throws Exception { graph.defineProperty("none").dataType(String.class).textIndexHint(TextIndexHint.NONE).define(); graph.defineProperty("both").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.defineProperty("fullText").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("none", StreamingPropertyValue.create("Test Value"), VISIBILITY_A) .setProperty("both", StreamingPropertyValue.create("Test Value"), VISIBILITY_A) .setProperty("fullText", StreamingPropertyValue.create("Test Value"), VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("both", TextPredicate.CONTAINS, "Test").vertices())); assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("fullText", TextPredicate.CONTAINS, "Test").vertices())); assertEquals("un-indexed property shouldn't match partials", 0, count(graph.query(AUTHORIZATIONS_A).has("none", "Test").vertices())); assertEquals("un-indexed property shouldn't match partials", 0, count(graph.query(AUTHORIZATIONS_A).has("none", TextPredicate.CONTAINS, "Test").vertices())); }
@Test public void testTextIndexStreamingPropertyValue() throws Exception { graph.defineProperty("none").dataType(String.class).textIndexHint(TextIndexHint.NONE).define(); graph.defineProperty("both").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.defineProperty("fullText").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("none", StreamingPropertyValue.create("Test Value"), VISIBILITY_A) .setProperty("both", StreamingPropertyValue.create("Test Value"), VISIBILITY_A) .setProperty("fullText", StreamingPropertyValue.create("Test Value"), VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("both", TextPredicate.CONTAINS, "Test").vertices())); assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("fullText", TextPredicate.CONTAINS, "Test").vertices())); assertEquals("un-indexed property shouldn't match partials", 0, count(graph.query(AUTHORIZATIONS_A).has("none", "Test").vertices())); assertEquals("un-indexed property shouldn't match partials", 0, count(graph.query(AUTHORIZATIONS_A).has("none", TextPredicate.CONTAINS, "Test").vertices())); }
@Test public void testTextIndex() throws Exception { graph.defineProperty("none").dataType(String.class).textIndexHint(TextIndexHint.NONE).define(); graph.defineProperty("none").dataType(String.class).textIndexHint(TextIndexHint.NONE).define(); // try calling define twice graph.defineProperty("both").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.defineProperty("fullText").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define(); graph.defineProperty("exactMatch").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("none", "Test Value", VISIBILITY_A) .setProperty("both", "Test Value", VISIBILITY_A) .setProperty("fullText", "Test Value", VISIBILITY_A) .setProperty("exactMatch", "Test Value", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals("Test Value", v1.getPropertyValue("none")); assertEquals("Test Value", v1.getPropertyValue("both")); assertEquals("Test Value", v1.getPropertyValue("fullText")); assertEquals("Test Value", v1.getPropertyValue("exactMatch")); assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("both", TextPredicate.CONTAINS, "Test").vertices())); assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("fullText", TextPredicate.CONTAINS, "Test").vertices())); assertEquals("exact match shouldn't match partials", 0, count(graph.query(AUTHORIZATIONS_A).has("exactMatch", "Test").vertices())); assertEquals("un-indexed property shouldn't match partials", 0, count(graph.query(AUTHORIZATIONS_A).has("none", "Test").vertices())); assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("both", "Test Value").vertices())); assertEquals("default has predicate is equals which shouldn't work for full text", 0, count(graph.query(AUTHORIZATIONS_A).has("fullText", "Test Value").vertices())); assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("exactMatch", "Test Value").vertices())); if (count(graph.query(AUTHORIZATIONS_A).has("none", "Test Value").vertices()) != 0) { LOGGER.warn("default has predicate is equals which shouldn't work for un-indexed"); } }
@Test public void testTextIndex() throws Exception { graph.defineProperty("none").dataType(String.class).textIndexHint(TextIndexHint.NONE).define(); graph.defineProperty("none").dataType(String.class).textIndexHint(TextIndexHint.NONE).define(); // try calling define twice graph.defineProperty("both").dataType(String.class).textIndexHint(TextIndexHint.ALL).define(); graph.defineProperty("fullText").dataType(String.class).textIndexHint(TextIndexHint.FULL_TEXT).define(); graph.defineProperty("exactMatch").dataType(String.class).textIndexHint(TextIndexHint.EXACT_MATCH).define(); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("none", "Test Value", VISIBILITY_A) .setProperty("both", "Test Value", VISIBILITY_A) .setProperty("fullText", "Test Value", VISIBILITY_A) .setProperty("exactMatch", "Test Value", VISIBILITY_A) .save(AUTHORIZATIONS_A_AND_B); Vertex v1 = graph.getVertex("v1", AUTHORIZATIONS_A); assertEquals("Test Value", v1.getPropertyValue("none")); assertEquals("Test Value", v1.getPropertyValue("both")); assertEquals("Test Value", v1.getPropertyValue("fullText")); assertEquals("Test Value", v1.getPropertyValue("exactMatch")); assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("both", TextPredicate.CONTAINS, "Test").vertices())); assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("fullText", TextPredicate.CONTAINS, "Test").vertices())); assertEquals("exact match shouldn't match partials", 0, count(graph.query(AUTHORIZATIONS_A).has("exactMatch", "Test").vertices())); assertEquals("un-indexed property shouldn't match partials", 0, count(graph.query(AUTHORIZATIONS_A).has("none", "Test").vertices())); assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("both", "Test Value").vertices())); assertEquals("default has predicate is equals which shouldn't work for full text", 0, count(graph.query(AUTHORIZATIONS_A).has("fullText", "Test Value").vertices())); assertEquals(1, count(graph.query(AUTHORIZATIONS_A).has("exactMatch", "Test Value").vertices())); if (count(graph.query(AUTHORIZATIONS_A).has("none", "Test Value").vertices()) != 0) { LOGGER.warn("default has predicate is equals which shouldn't work for un-indexed"); } }