use of org.apache.jackrabbit.oak.spi.query.Cursor in project jackrabbit-oak by apache.
the class LuceneIndexTest method testLucene2.
@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());
}
use of org.apache.jackrabbit.oak.spi.query.Cursor in project jackrabbit-oak by apache.
the class LuceneIndexTest method testLucene.
@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());
}
use of org.apache.jackrabbit.oak.spi.query.Cursor in project jackrabbit-oak by apache.
the class SolrQueryIndexTest method testSize.
@Test
public void testSize() throws Exception {
NodeState root = InitialContent.INITIAL_CONTENT;
SelectorImpl selector = newSelector(root, "a");
String sqlQuery = "select [jcr:path], [jcr:score] from [nt:base] as a where" + " contains([jcr:content/*], 'founded')";
SolrServerProvider solrServerProvider = mock(SolrServerProvider.class);
OakSolrConfigurationProvider configurationProvider = mock(OakSolrConfigurationProvider.class);
OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
@Override
public boolean useForPropertyRestrictions() {
return true;
}
};
when(configurationProvider.getConfiguration()).thenReturn(configuration);
SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, configurationProvider, solrServerProvider);
FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, null, root);
for (QueryIndex.IndexPlan p : plans) {
Cursor cursor = solrQueryIndex.query(p, root);
assertNotNull(cursor);
long sizeExact = cursor.getSize(Result.SizePrecision.EXACT, 100000);
long sizeApprox = cursor.getSize(Result.SizePrecision.APPROXIMATION, 100000);
long sizeFastApprox = cursor.getSize(Result.SizePrecision.FAST_APPROXIMATION, 100000);
assertTrue(Math.abs(sizeExact - sizeApprox) < 10);
assertTrue(Math.abs(sizeExact - sizeFastApprox) > 10000);
}
}
use of org.apache.jackrabbit.oak.spi.query.Cursor in project jackrabbit-oak by apache.
the class LuceneIndexTest method testLuceneLazyCursor.
@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());
}
use of org.apache.jackrabbit.oak.spi.query.Cursor in project jackrabbit-oak by apache.
the class TraversingIndexTest method traverse.
@Test
public void traverse() throws Exception {
NodeBuilder builder = EMPTY_NODE.builder();
NodeBuilder parents = builder.child("parents");
parents.child("p0").setProperty("id", 0);
parents.child("p1").setProperty("id", 1);
parents.child("p2").setProperty("id", 2);
NodeBuilder children = builder.child("children");
children.child("c1").setProperty("p", "1");
children.child("c2").setProperty("p", "1");
children.child("c3").setProperty("p", "2");
children.child("c4").setProperty("p", "3");
NodeState root = builder.getNodeState();
TraversingIndex t = new TraversingIndex();
FilterImpl f = FilterImpl.newTestInstance();
f.setPath("/");
Cursor c = t.query(f, root);
List<String> paths = new ArrayList<String>();
while (c.hasNext()) {
paths.add(c.next().getPath());
}
Collections.sort(paths);
assertEquals(Arrays.asList("/", "/children", "/children/c1", "/children/c2", "/children/c3", "/children/c4", "/parents", "/parents/p0", "/parents/p1", "/parents/p2"), paths);
assertFalse(c.hasNext());
// endure it stays false
assertFalse(c.hasNext());
f.setPath("/nowhere");
c = t.query(f, root);
assertFalse(c.hasNext());
// endure it stays false
assertFalse(c.hasNext());
}
Aggregations