use of org.apache.jackrabbit.oak.query.fulltext.FullTextExpression in project jackrabbit-oak by apache.
the class AggregateIndex method getPlans.
@Override
public List<IndexPlan> getPlans(Filter filter, List<OrderEntry> sortOrder, NodeState rootState) {
if (baseIndex == null) {
return Collections.emptyList();
}
FullTextExpression e = filter.getFullTextConstraint();
if (getNodeAggregator() == null || e == null) {
// no aggregation: path-though
return baseIndex.getPlans(filter, sortOrder, rootState);
}
if (!hasCompositeExpression(e)) {
// path-though, but without node type restriction
return baseIndex.getPlans(newAggregationFilter(filter, null), sortOrder, rootState);
}
AggregateIndexPlan plan = new AggregateIndexPlan(filter);
collectCombinedPlan(e, filter, sortOrder, rootState, plan, "");
if (plan.containsPathWithoutPlan()) {
// the full-text index didn't return a plan
LOG.debug("Full-text index without plan: " + e);
return Collections.emptyList();
}
return Collections.singletonList((IndexPlan) plan);
}
use of org.apache.jackrabbit.oak.query.fulltext.FullTextExpression 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.getQueryEngineSettings());
}
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.getQueryEngineSettings()));
return true;
}
});
return result.get();
}
use of org.apache.jackrabbit.oak.query.fulltext.FullTextExpression in project jackrabbit-oak by apache.
the class FullTextSearchImpl method getFullTextConstraint.
@Override
public FullTextExpression getFullTextConstraint(SelectorImpl s) {
if (!s.equals(selector)) {
return null;
}
PropertyValue v = fullTextSearchExpression.currentValue();
try {
String p = propertyName;
if (relativePath != null) {
if (p == null) {
p = "*";
}
p = PathUtils.concat(relativePath, p);
}
String p2 = normalizePropertyName(p);
String rawText = getRawText(v);
FullTextExpression e = FullTextParser.parse(p2, rawText);
return new FullTextContains(p2, rawText, e);
} catch (ParseException e) {
throw new IllegalArgumentException("Invalid expression: " + fullTextSearchExpression, e);
}
}
use of org.apache.jackrabbit.oak.query.fulltext.FullTextExpression in project jackrabbit-oak by apache.
the class IndexPlannerTest method fullTextQuery_DisjointPropertyPaths.
@Test
public void fullTextQuery_DisjointPropertyPaths() throws Exception {
NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo", "bar"), "async");
//Index all props and then perform fulltext
defn = IndexDefinition.updateDefinition(defn.getNodeState().builder());
NodeBuilder foob = getNode(defn, "indexRules/nt:base/properties/foo");
foob.setProperty(LuceneIndexConstants.PROP_NAME, "foo");
foob.setProperty(LuceneIndexConstants.PROP_ANALYZED, true);
NodeBuilder barb = getNode(defn, "indexRules/nt:base/properties/bar");
barb.setProperty(LuceneIndexConstants.PROP_NAME, "bar");
barb.setProperty(LuceneIndexConstants.PROP_ANALYZED, true);
FullTextExpression fooExp = FullTextParser.parse("metadata/bar", "mountain OR valley");
FullTextExpression barExp = FullTextParser.parse("jcr:content/foo", "mountain OR valley");
FullTextExpression exp = new FullTextAnd(Arrays.asList(fooExp, barExp));
IndexPlanner planner = createPlannerForFulltext(defn.getNodeState(), exp);
//No plan for unindex property
assertNull(planner.getPlan());
}
use of org.apache.jackrabbit.oak.query.fulltext.FullTextExpression in project jackrabbit-oak by apache.
the class IndexPlannerTest method fullTextQuery_RelativePropertyPaths.
@Test
public void fullTextQuery_RelativePropertyPaths() throws Exception {
NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo", "bar"), "async");
//Index all props and then perform fulltext
defn = IndexDefinition.updateDefinition(defn.getNodeState().builder());
NodeBuilder foob = getNode(defn, "indexRules/nt:base/properties/foo");
foob.setProperty(LuceneIndexConstants.PROP_NAME, "foo");
foob.setProperty(LuceneIndexConstants.PROP_ANALYZED, true);
NodeBuilder barb = getNode(defn, "indexRules/nt:base/properties/bar");
barb.setProperty(LuceneIndexConstants.PROP_NAME, "bar");
barb.setProperty(LuceneIndexConstants.PROP_ANALYZED, true);
//where contains('jcr:content/bar', 'mountain OR valley') and contains('jcr:content/foo', 'mountain OR valley')
//above query can be evaluated by index which indexes foo and bar with restriction that both belong to same node
//by displacing the query path to evaluate on contains('bar', ...) and filter out those parents which do not
//have jcr:content as parent
FullTextExpression fooExp = FullTextParser.parse("jcr:content/bar", "mountain OR valley");
FullTextExpression barExp = FullTextParser.parse("jcr:content/foo", "mountain OR valley");
FullTextExpression exp = new FullTextAnd(Arrays.asList(fooExp, barExp));
IndexPlanner planner = createPlannerForFulltext(defn.getNodeState(), exp);
//No plan for unindex property
assertNotNull(planner.getPlan());
}
Aggregations