use of org.apache.jackrabbit.oak.spi.query.Cursor in project jackrabbit-oak by apache.
the class AggregateIndex method flatten.
private Cursor flatten(FullTextExpression constraint, final AggregateIndexPlan plan, final Filter filter, final NodeState state, final String path) {
if (constraint == null) {
return null;
}
final AtomicReference<Cursor> result = new AtomicReference<Cursor>();
constraint.accept(new FullTextVisitor() {
@Override
public boolean visit(FullTextContains contains) {
return contains.getBase().accept(this);
}
@Override
public boolean visit(FullTextTerm term) {
IndexPlan p = plan.getPlan(path);
result.set(newAggregationCursor(p, state));
return true;
}
@Override
public boolean visit(FullTextAnd and) {
Iterator<FullTextExpression> iterator = and.list.iterator();
int index = 0;
Cursor c = flatten(iterator.next(), plan, filter, state, path + " and(" + index + ")");
while (iterator.hasNext()) {
index++;
FullTextExpression input = iterator.next();
Cursor newC = flatten(input, plan, filter, state, path + " and(" + index + ")");
c = Cursors.newIntersectionCursor(c, newC, filter.getQueryLimits());
}
result.set(c);
return true;
}
@Override
public boolean visit(FullTextOr or) {
final int[] index = new int[1];
List<Cursor> cursors = Lists.transform(or.list, new Function<FullTextExpression, Cursor>() {
@Override
public Cursor apply(FullTextExpression input) {
return flatten(input, plan, filter, state, path + " or(" + index[0]++ + ")");
}
});
result.set(Cursors.newConcatCursor(cursors, filter.getQueryLimits()));
return true;
}
});
return result.get();
}
use of org.apache.jackrabbit.oak.spi.query.Cursor in project jackrabbit-oak by apache.
the class PropertyIndexPlan method execute.
Cursor execute() {
QueryLimits settings = filter.getQueryLimits();
List<Iterable<String>> iterables = Lists.newArrayList();
for (IndexStoreStrategy s : strategies) {
iterables.add(s.query(filter, name, definition, values));
}
Cursor cursor = Cursors.newPathCursor(Iterables.concat(iterables), settings);
if (depth > 1) {
cursor = Cursors.newAncestorCursor(cursor, depth - 1, settings);
}
return cursor;
}
use of org.apache.jackrabbit.oak.spi.query.Cursor in project jackrabbit-oak by apache.
the class SolrQueryIndexTest method testNoMoreThanThreeSolrRequests.
@Test
public void testNoMoreThanThreeSolrRequests() 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')";
SolrClient solrServer = mock(SolrClient.class);
SolrServerProvider solrServerProvider = mock(SolrServerProvider.class);
when(solrServerProvider.getSearchingSolrServer()).thenReturn(solrServer);
OakSolrConfigurationProvider configurationProvider = mock(OakSolrConfigurationProvider.class);
OakSolrConfiguration configuration = new DefaultSolrConfiguration() {
@Override
public boolean useForPropertyRestrictions() {
return true;
}
@Override
public int getRows() {
return 10;
}
};
when(configurationProvider.getConfiguration()).thenReturn(configuration);
SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, configurationProvider, solrServerProvider);
FilterImpl filter = new FilterImpl(selector, sqlQuery, new QueryEngineSettings());
CountingResponse response = new CountingResponse(0);
when(solrServer.query(any(SolrParams.class))).thenReturn(response);
List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, null, root);
for (QueryIndex.IndexPlan p : plans) {
Cursor cursor = solrQueryIndex.query(p, root);
assertNotNull(cursor);
while (cursor.hasNext()) {
IndexRow row = cursor.next();
assertNotNull(row);
}
assertEquals(3, response.getCounter());
}
}
use of org.apache.jackrabbit.oak.spi.query.Cursor in project jackrabbit-oak by apache.
the class LuceneIndexTest method testLuceneV1NonExistentProperty.
@Test
public void testLuceneV1NonExistentProperty() throws Exception {
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
NodeBuilder defn = newLuceneIndexDefinition(index, "lucene", ImmutableSet.of("String"));
defn.setProperty(LuceneIndexConstants.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());
}
use of org.apache.jackrabbit.oak.spi.query.Cursor in project jackrabbit-oak by apache.
the class SolrQueryIndex method query.
@Override
public Cursor query(final IndexPlan plan, final NodeState root) {
Cursor cursor;
try {
Filter filter = plan.getFilter();
final Set<String> relPaths = filter.getFullTextConstraint() != null ? getRelativePaths(filter.getFullTextConstraint()) : Collections.<String>emptySet();
final String parent = relPaths.size() == 0 ? "" : relPaths.iterator().next();
final int parentDepth = getDepth(parent);
String path = plan.getPlanName();
OakSolrConfiguration configuration = getConfiguration(path, root);
SolrClient solrServer = getServer(path, root);
LMSEstimator estimator = getEstimator(path);
AbstractIterator<SolrResultRow> iterator = getIterator(filter, plan, parent, parentDepth, configuration, solrServer, estimator);
cursor = new SolrRowCursor(iterator, plan, filter.getQueryLimits(), estimator, solrServer, configuration);
} catch (Exception e) {
throw new RuntimeException(e);
}
return cursor;
}
Aggregations