private static List<String> assertFilter(Filter filter, AdvancedQueryIndex queryIndex, NodeState indexed, List<String> expected) { List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed); Cursor cursor = queryIndex.query(plans.get(0), indexed); List<String> paths = newArrayList(); while (cursor.hasNext()) { paths.add(cursor.next().getPath()); } Collections.sort(paths); for (String p : expected) { assertTrue("Expected path " + p + " not found", paths.contains(p)); } assertEquals("Result set size is different \nExpected: " + expected + "\nActual: " + paths, expected.size(), paths.size()); return paths; }
private static List<String> assertFilter(Filter filter, AdvancedQueryIndex queryIndex, NodeState indexed, List<String> expected, boolean ordered) { if (!ordered) { return assertFilter(filter, queryIndex, indexed, expected); } List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed); Cursor cursor = queryIndex.query(plans.get(0), indexed); List<String> paths = newArrayList(); while (cursor.hasNext()) { paths.add(cursor.next().getPath()); } for (String p : expected) { assertTrue("Expected path " + p + " not found", paths.contains(p)); } assertEquals("Result set size is different", expected.size(), paths.size()); return paths; }
List<IndexPlan> ipList = advIndex.getPlans( filter, sortOrder, rootState); cost = Double.POSITIVE_INFINITY;
List<IndexPlan> ipList = advIndex.getPlans( filter, sortOrder, rootState); cost = Double.POSITIVE_INFINITY;
List<IndexPlan> ipList = advIndex.getPlans( filter, sortOrder, rootState); cost = Double.POSITIVE_INFINITY;
FilterImpl filter = createFilter(NT_BASE); filter.restrictProperty("foo", Operator.GREATER_OR_EQUAL, PropertyValues.newLong(0L)); List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed); Cursor cursor = queryIndex.query(plans.get(0), indexed);
tracker.update(indexed); List<IndexPlan> list = queryIndex.getPlans(filter, null, indexed); assertEquals("There must be only one plan", 1, list.size()); IndexPlan plan = list.get(0);
@Test public void testLucene3() throws Exception { NodeBuilder index = newLucenePropertyIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", ImmutableSet.of("foo"), null); NodeBuilder rules = index.child(INDEX_RULES); NodeBuilder fooProp = rules.child("nt:base").child(FulltextIndexConstants.PROP_NODE).child("foo"); fooProp.setProperty(FulltextIndexConstants.PROP_PROPERTY_INDEX, true); fooProp.setProperty(FulltextIndexConstants.PROP_INCLUDED_TYPE, PropertyType.TYPENAME_STRING); NodeState before = builder.getNodeState(); builder.setProperty("foo", "bar"); builder.child("a").setProperty("foo", "bar"); builder.child("a").child("b").setProperty("foo", "bar", Type.NAME); builder.child("a").child("b").child("c") .setProperty("foo", "bar", Type.NAME); NodeState after = builder.getNodeState(); NodeState indexed = HOOK.processCommit(before, after,CommitInfo.EMPTY); tracker = new IndexTracker(); tracker.update(indexed); AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker); FilterImpl filter = createFilter(NT_BASE); // filter.restrictPath("/", Filter.PathRestriction.EXACT); filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar")); List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed); Cursor cursor = queryIndex.query(plans.get(0), indexed); assertTrue(cursor.hasNext()); assertEquals("/a", cursor.next().getPath()); assertEquals("/", cursor.next().getPath()); assertFalse(cursor.hasNext()); }
@Test public void testLuceneLazyCursor() throws Exception { NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME); newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo"), null); NodeState before = builder.getNodeState(); builder.setProperty("foo", "bar"); for(int i = 0; i < LuceneIndex.LUCENE_QUERY_BATCH_SIZE; i++){ builder.child("parent").child("child"+i).setProperty("foo", "bar"); } NodeState after = builder.getNodeState(); NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY); tracker = new IndexTracker(); tracker.update(indexed); AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker); FilterImpl filter = createFilter(NT_BASE); filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar")); List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed); Cursor cursor = queryIndex.query(plans.get(0), indexed); List<String> paths = copyOf(transform(cursor, new Function<IndexRow, String>() { public String apply(IndexRow input) { return input.getPath(); } })); assertTrue(!paths.isEmpty()); assertEquals(LuceneIndex.LUCENE_QUERY_BATCH_SIZE + 1, paths.size()); }
@Test public void testLuceneV1NonExistentProperty() throws Exception { NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME); NodeBuilder defn = newLuceneIndexDefinition(index, "lucene", ImmutableSet.of("String")); defn.setProperty(FulltextIndexConstants.COMPAT_MODE, IndexFormatVersion.V1.getVersion()); NodeState before = builder.getNodeState(); builder.setProperty("foo", "value-with-dash"); NodeState after = builder.getNodeState(); NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY); tracker = new IndexTracker(); tracker.update(indexed); AdvancedQueryIndex queryIndex = new LuceneIndex(tracker, null); FilterImpl filter = createFilter(NT_BASE); filter.restrictPath("/", Filter.PathRestriction.EXACT); filter.setFullTextConstraint(FullTextParser.parse("foo", "value-with*")); List<IndexPlan> plans = queryIndex.getPlans(filter, null, builder.getNodeState()); Cursor cursor = queryIndex.query(plans.get(0), indexed); assertTrue(cursor.hasNext()); assertEquals("/", cursor.next().getPath()); assertFalse(cursor.hasNext()); //Now perform a query against a field which does not exist FilterImpl filter2 = createFilter(NT_BASE); filter2.restrictPath("/", Filter.PathRestriction.EXACT); filter2.setFullTextConstraint(FullTextParser.parse("baz", "value-with*")); List<IndexPlan> plans2 = queryIndex.getPlans(filter2, null, builder.getNodeState()); Cursor cursor2 = queryIndex.query(plans2.get(0), indexed); assertFalse(cursor2.hasNext()); }
@Test public void testLucene2() throws Exception { NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME); newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo"), null); NodeState before = builder.getNodeState(); builder.setProperty("foo", "bar"); builder.child("a").setProperty("foo", "bar"); builder.child("a").child("b").setProperty("foo", "bar"); builder.child("a").child("b").child("c").setProperty("foo", "bar"); NodeState after = builder.getNodeState(); NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY); tracker = new IndexTracker(); tracker.update(indexed); AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker); FilterImpl filter = createFilter(NT_BASE); // filter.restrictPath("/", Filter.PathRestriction.EXACT); filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar")); List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed); Cursor cursor = queryIndex.query(plans.get(0), indexed); assertTrue(cursor.hasNext()); assertEquals("/a/b/c", cursor.next().getPath()); assertEquals("/a/b", cursor.next().getPath()); assertEquals("/a", cursor.next().getPath()); assertEquals("/", cursor.next().getPath()); assertFalse(cursor.hasNext()); }
@Test public void testLucene() throws Exception { NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME); newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo"), null); NodeState before = builder.getNodeState(); builder.setProperty("foo", "bar"); NodeState after = builder.getNodeState(); NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY); tracker = new IndexTracker(); tracker.update(indexed); AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker); FilterImpl filter = createFilter(NT_BASE); filter.restrictPath("/", Filter.PathRestriction.EXACT); filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar")); List<IndexPlan> plans = queryIndex.getPlans(filter, null, builder.getNodeState()); Cursor cursor = queryIndex.query(plans.get(0), indexed); assertTrue(cursor.hasNext()); assertEquals("/", cursor.next().getPath()); assertFalse(cursor.hasNext()); }
private void assertQuery(IndexTracker tracker, NodeState indexed, String key, String value){ AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker); FilterImpl filter = createFilter(NT_BASE); filter.restrictPath("/", Filter.PathRestriction.EXACT); filter.restrictProperty(key, Operator.EQUAL, PropertyValues.newString(value)); List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed); Cursor cursor = queryIndex.query(plans.get(0), indexed); assertTrue(cursor.hasNext()); assertEquals("/", cursor.next().getPath()); assertFalse(cursor.hasNext()); }