use of org.apache.jackrabbit.oak.query.fulltext.FullTextContains 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.FullTextContains 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.FullTextContains in project jackrabbit-oak by apache.
the class IndexPlannerTest method fullTextQuery_IndexAllProps.
@Test
public void fullTextQuery_IndexAllProps() throws Exception {
NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("allProps"), "async");
//Index all props and then perform fulltext
defn = IndexDefinition.updateDefinition(defn.getNodeState().builder());
NodeBuilder foob = getNode(defn, "indexRules/nt:base/properties/allProps");
foob.setProperty(LuceneIndexConstants.PROP_NAME, LuceneIndexConstants.REGEX_ALL_PROPS);
foob.setProperty(LuceneIndexConstants.PROP_ANALYZED, true);
foob.setProperty(LuceneIndexConstants.PROP_IS_REGEX, true);
FullTextExpression exp = FullTextParser.parse("bar", "mountain OR valley");
exp = new FullTextContains("bar", "mountain OR valley", exp);
IndexPlanner planner = createPlannerForFulltext(defn.getNodeState(), exp);
//No plan for unindex property
assertNotNull(planner.getPlan());
}
use of org.apache.jackrabbit.oak.query.fulltext.FullTextContains in project jackrabbit-oak by apache.
the class LucenePropertyIndex method getFullTextQuery.
static Query getFullTextQuery(final IndexPlan plan, FullTextExpression ft, final Analyzer analyzer, final FulltextQueryTermsProvider augmentor) {
final PlanResult pr = getPlanResult(plan);
// a reference to the query, so it can be set in the visitor
// (a "non-local return")
final AtomicReference<Query> result = new AtomicReference<Query>();
ft.accept(new FullTextVisitor() {
@Override
public boolean visit(FullTextContains contains) {
visitTerm(contains.getPropertyName(), contains.getRawText(), null, contains.isNot());
return true;
}
@Override
public boolean visit(FullTextOr or) {
BooleanQuery q = new BooleanQuery();
for (FullTextExpression e : or.list) {
Query x = getFullTextQuery(plan, e, analyzer, augmentor);
q.add(x, SHOULD);
}
result.set(q);
return true;
}
@Override
public boolean visit(FullTextAnd and) {
BooleanQuery q = new BooleanQuery();
for (FullTextExpression e : and.list) {
Query x = getFullTextQuery(plan, e, analyzer, augmentor);
/* Only unwrap the clause if MUST_NOT(x) */
boolean hasMustNot = false;
if (x instanceof BooleanQuery) {
BooleanQuery bq = (BooleanQuery) x;
if ((bq.getClauses().length == 1) && (bq.getClauses()[0].getOccur() == BooleanClause.Occur.MUST_NOT)) {
hasMustNot = true;
q.add(bq.getClauses()[0]);
}
}
if (!hasMustNot) {
q.add(x, MUST);
}
}
result.set(q);
return true;
}
@Override
public boolean visit(FullTextTerm term) {
return visitTerm(term.getPropertyName(), term.getText(), term.getBoost(), term.isNot());
}
private boolean visitTerm(String propertyName, String text, String boost, boolean not) {
String p = getLuceneFieldName(propertyName, pr);
Query q = tokenToQuery(text, p, pr, analyzer, augmentor);
if (q == null) {
return false;
}
if (boost != null) {
q.setBoost(Float.parseFloat(boost));
}
if (not) {
BooleanQuery bq = new BooleanQuery();
bq.add(q, MUST_NOT);
result.set(bq);
} else {
result.set(q);
}
return true;
}
});
return result.get();
}
use of org.apache.jackrabbit.oak.query.fulltext.FullTextContains in project jackrabbit-oak by apache.
the class AggregateIndex method hasCompositeExpression.
private static boolean hasCompositeExpression(FullTextExpression ft) {
if (ft == null) {
return false;
}
final AtomicReference<Boolean> composite = new AtomicReference<Boolean>();
composite.set(false);
ft.accept(new FullTextVisitor() {
@Override
public boolean visit(FullTextContains contains) {
return contains.getBase().accept(this);
}
@Override
public boolean visit(FullTextTerm term) {
return true;
}
@Override
public boolean visit(FullTextAnd and) {
composite.set(true);
return true;
}
@Override
public boolean visit(FullTextOr or) {
composite.set(true);
return true;
}
});
return composite.get() && !hasNegativeContains(ft);
}
Aggregations