Search in sources :

Example 1 with FullTextExpression

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);
}
Also used : FullTextExpression(org.apache.jackrabbit.oak.query.fulltext.FullTextExpression)

Example 2 with FullTextExpression

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();
}
Also used : FullTextOr(org.apache.jackrabbit.oak.query.fulltext.FullTextOr) FullTextContains(org.apache.jackrabbit.oak.query.fulltext.FullTextContains) AtomicReference(java.util.concurrent.atomic.AtomicReference) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) Function(com.google.common.base.Function) FullTextVisitor(org.apache.jackrabbit.oak.query.fulltext.FullTextVisitor) FullTextTerm(org.apache.jackrabbit.oak.query.fulltext.FullTextTerm) FullTextAnd(org.apache.jackrabbit.oak.query.fulltext.FullTextAnd) Iterator(java.util.Iterator) FullTextExpression(org.apache.jackrabbit.oak.query.fulltext.FullTextExpression) List(java.util.List)

Example 3 with FullTextExpression

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);
    }
}
Also used : FullTextContains(org.apache.jackrabbit.oak.query.fulltext.FullTextContains) FullTextExpression(org.apache.jackrabbit.oak.query.fulltext.FullTextExpression) PropertyValue(org.apache.jackrabbit.oak.api.PropertyValue) ParseException(java.text.ParseException)

Example 4 with FullTextExpression

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());
}
Also used : FullTextAnd(org.apache.jackrabbit.oak.query.fulltext.FullTextAnd) FullTextExpression(org.apache.jackrabbit.oak.query.fulltext.FullTextExpression) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 5 with FullTextExpression

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());
}
Also used : FullTextAnd(org.apache.jackrabbit.oak.query.fulltext.FullTextAnd) FullTextExpression(org.apache.jackrabbit.oak.query.fulltext.FullTextExpression) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

FullTextExpression (org.apache.jackrabbit.oak.query.fulltext.FullTextExpression)20 Filter (org.apache.jackrabbit.oak.spi.query.Filter)7 FullTextAnd (org.apache.jackrabbit.oak.query.fulltext.FullTextAnd)6 FullTextContains (org.apache.jackrabbit.oak.query.fulltext.FullTextContains)6 FullTextTerm (org.apache.jackrabbit.oak.query.fulltext.FullTextTerm)5 BooleanQuery (org.apache.lucene.search.BooleanQuery)5 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)5 PrefixQuery (org.apache.lucene.search.PrefixQuery)5 Query (org.apache.lucene.search.Query)5 TermQuery (org.apache.lucene.search.TermQuery)5 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)5 WildcardQuery (org.apache.lucene.search.WildcardQuery)5 FullTextOr (org.apache.jackrabbit.oak.query.fulltext.FullTextOr)4 FullTextVisitor (org.apache.jackrabbit.oak.query.fulltext.FullTextVisitor)4 PropertyRestriction (org.apache.jackrabbit.oak.spi.query.Filter.PropertyRestriction)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 Analyzer (org.apache.lucene.analysis.Analyzer)3