@Override public IndexRow next() { final IndexRow pathRow = pathCursor.next(); return new IndexRow() { @Override public boolean isVirtualRow() { return currentRow.isVirtual; } @Override public String getPath() { return pathRow.getPath(); } @Override public PropertyValue getValue(String columnName) { // overlay the score if (QueryConstants.JCR_SCORE.equals(columnName)) { return PropertyValues.newDouble(currentRow.score); } if (QueryConstants.REP_SPELLCHECK.equals(columnName) || QueryConstants.REP_SUGGEST.equals(columnName)) { return PropertyValues.newString(Iterables.toString(currentRow.suggestWords)); } if (QueryConstants.REP_EXCERPT.equals(columnName)) { return PropertyValues.newString(currentRow.excerpt); } return pathRow.getValue(columnName); } }; }
@Override public IndexRow next() { provider.incrementCount(); return c.next(); }
static String list(Cursor c) { StringBuilder buff = new StringBuilder(); while (c.hasNext()) { buff.append(buff.length() == 0 ? "" : ", "); buff.append(c.next()); } return buff.toString(); }
private void fetchNext() { if (aggregates != null && aggregates.hasNext()) { currentPath = aggregates.next(); init = true; return; } aggregates = null; if (cursor.hasNext()) { currentRow = cursor.next(); if (!currentRow.isVirtualRow()) { String path = currentRow.getPath(); aggregates = Iterators.filter(Iterators.concat( Iterators.singletonIterator(path), aggregator.getParents(rootState, path)), Predicates .not(Predicates.in(seenPaths))); } fetchNext(); return; } closed = true; }
private void fetchNext() { if (aggregates != null && aggregates.hasNext()) { currentPath = aggregates.next(); init = true; return; } aggregates = null; if (cursor.hasNext()) { currentRow = cursor.next(); if (!currentRow.isVirtualRow()) { String path = currentRow.getPath(); aggregates = Iterators.filter(Iterators.concat( Iterators.singletonIterator(path), aggregator.getParents(rootState, path)), Predicates .not(Predicates.in(seenPaths))); } fetchNext(); return; } closed = true; }
private void fetchNext() { if (aggregates != null && aggregates.hasNext()) { currentPath = aggregates.next(); init = true; return; } aggregates = null; if (cursor.hasNext()) { currentRow = cursor.next(); if (!currentRow.isVirtualRow()) { String path = currentRow.getPath(); aggregates = Iterators.filter(Iterators.concat( Iterators.singletonIterator(path), aggregator.getParents(rootState, path)), Predicates .not(Predicates.in(seenPaths))); } fetchNext(); return; } closed = true; }
private void fetchNext() { while (true) { if (!first.hasNext()) { closed = true; return; } IndexRow c = first.next(); String p = c.getPath(); if (seen.contains(p)) { continue; } if (secondSet.remove(p) != null) { current = c; markSeen(p); return; } while (second.hasNext()) { IndexRow s = second.next(); String p2 = s.getPath(); if (p.equals(p2)) { current = c; markSeen(p); return; } secondSet.put(p2, s); FilterIterators.checkMemoryLimit(secondSet.size(), settings); } } }
private void fetchNext() { while (true) { if (!first.hasNext()) { closed = true; return; } IndexRow c = first.next(); String p = c.getPath(); if (seen.contains(p)) { continue; } if (secondSet.remove(p) != null) { current = c; markSeen(p); return; } while (second.hasNext()) { IndexRow s = second.next(); String p2 = s.getPath(); if (p.equals(p2)) { current = c; markSeen(p); return; } secondSet.put(p2, s); FilterIterators.checkMemoryLimit(secondSet.size(), settings); } } }
private void fetchNext() { while (true) { while (!currentCursor.hasNext()) { nextCursor(); if (closed) { return; } } IndexRow c = currentCursor.next(); String p = c.getPath(); if (seen.contains(p)) { continue; } current = c; markSeen(p); return; } }
private void fetchNext() { while (true) { while (!currentCursor.hasNext()) { nextCursor(); if (closed) { return; } } IndexRow c = currentCursor.next(); String p = c.getPath(); if (seen.contains(p)) { continue; } current = c; markSeen(p); return; } }
private void fetchNext() { while (true) { while (!currentCursor.hasNext()) { nextCursor(); if (closed) { return; } } IndexRow c = currentCursor.next(); String p = c.getPath(); if (seen.contains(p)) { continue; } current = c; markSeen(p); return; } }
private static void checkCursor(Cursor cursor, String... matches) { // make sure the index is actually used // and does not traverse assertEquals(Cursors.class.getName() + "$PathCursor", cursor.getClass().getName()); Set<String> expected = Sets.newHashSet(); expected.addAll(Arrays.asList(matches)); Set<String> actual = Sets.newHashSet(); while (cursor.hasNext()) { actual.add(cursor.next().getPath()); } assertEquals(expected, actual); }
private static List<String> assertFilter(Filter filter, QueryIndex queryIndex, NodeState indexed, List<String> expected) { Cursor cursor = queryIndex.query(filter, 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) { 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; }
@Test public void intersectionCursorExceptions() { QueryEngineSettings s = new QueryEngineSettings(); Cursor a = new SimpleCursor("1:", "/x", "/b", "/c", "/e", "/e", "/c"); Cursor b = new SimpleCursor("2:", "/a", "/c", "/d", "/b", "/c"); Cursor c = Cursors.newIntersectionCursor(a, b, s); c.next(); c.next(); try { c.remove(); fail(); } catch (UnsupportedOperationException e) { // expected } try { c.next(); fail(); } catch (IllegalStateException e) { // expected } }
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()); }
@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()); }
@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()); }