Search in sources :

Example 6 with PlanResult

use of org.apache.jackrabbit.oak.plugins.index.lucene.IndexPlanner.PlanResult in project jackrabbit-oak by apache.

the class LucenePropertyIndex method addNonFullTextConstraints.

private static void addNonFullTextConstraints(List<Query> qs, IndexPlan plan, IndexReader reader) {
    Filter filter = plan.getFilter();
    PlanResult planResult = getPlanResult(plan);
    IndexDefinition defn = planResult.indexDefinition;
    if (!filter.matchesAllTypes()) {
        addNodeTypeConstraints(planResult.indexingRule, qs, filter);
    }
    String path = getPathRestriction(plan);
    switch(filter.getPathRestriction()) {
        case ALL_CHILDREN:
            if (defn.evaluatePathRestrictions()) {
                if ("/".equals(path)) {
                    break;
                }
                qs.add(new TermQuery(newAncestorTerm(path)));
            }
            break;
        case DIRECT_CHILDREN:
            if (defn.evaluatePathRestrictions()) {
                BooleanQuery bq = new BooleanQuery();
                bq.add(new BooleanClause(new TermQuery(newAncestorTerm(path)), BooleanClause.Occur.MUST));
                bq.add(new BooleanClause(newDepthQuery(path), BooleanClause.Occur.MUST));
                qs.add(bq);
            }
            break;
        case EXACT:
            qs.add(new TermQuery(newPathTerm(path)));
            break;
        case PARENT:
            if (denotesRoot(path)) {
                // there's no parent of the root node
                // we add a path that can not possibly occur because there
                // is no way to say "match no documents" in Lucene
                qs.add(new TermQuery(new Term(FieldNames.PATH, "///")));
            } else {
                qs.add(new TermQuery(newPathTerm(getParentPath(path))));
            }
            break;
        case NO_RESTRICTION:
            break;
    }
    for (PropertyRestriction pr : filter.getPropertyRestrictions()) {
        String name = pr.propertyName;
        if (QueryImpl.REP_EXCERPT.equals(name) || QueryImpl.OAK_SCORE_EXPLANATION.equals(name) || QueryImpl.REP_FACET.equals(name)) {
            continue;
        }
        if (QueryConstants.RESTRICTION_LOCAL_NAME.equals(name)) {
            if (planResult.evaluateNodeNameRestriction()) {
                Query q = createNodeNameQuery(pr);
                if (q != null) {
                    qs.add(q);
                }
            }
            continue;
        }
        if (pr.first != null && pr.first.equals(pr.last) && pr.firstIncluding && pr.lastIncluding) {
            String first = pr.first.getValue(STRING);
            first = first.replace("\\", "");
            if (JCR_PATH.equals(name)) {
                qs.add(new TermQuery(newPathTerm(first)));
                continue;
            } else if ("*".equals(name)) {
                //TODO Revisit reference constraint. For performant impl
                //references need to be indexed in a different manner
                addReferenceConstraint(first, qs, reader);
                continue;
            }
        }
        PropertyDefinition pd = planResult.getPropDefn(pr);
        if (pd == null) {
            continue;
        }
        Query q = createQuery(pr, pd);
        if (q != null) {
            qs.add(q);
        }
    }
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) PropertyRestriction(org.apache.jackrabbit.oak.spi.query.Filter.PropertyRestriction) PlanResult(org.apache.jackrabbit.oak.plugins.index.lucene.IndexPlanner.PlanResult) Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) NumericRangeQuery(org.apache.lucene.search.NumericRangeQuery) CustomScoreQuery(org.apache.lucene.queries.CustomScoreQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) Filter(org.apache.jackrabbit.oak.spi.query.Filter) Term(org.apache.lucene.index.Term) TermFactory.newAncestorTerm(org.apache.jackrabbit.oak.plugins.index.lucene.TermFactory.newAncestorTerm) TermFactory.newPathTerm(org.apache.jackrabbit.oak.plugins.index.lucene.TermFactory.newPathTerm) FullTextTerm(org.apache.jackrabbit.oak.query.fulltext.FullTextTerm)

Aggregations

PlanResult (org.apache.jackrabbit.oak.plugins.index.lucene.IndexPlanner.PlanResult)6 CustomScoreQuery (org.apache.lucene.queries.CustomScoreQuery)4 BooleanQuery (org.apache.lucene.search.BooleanQuery)4 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)4 NumericRangeQuery (org.apache.lucene.search.NumericRangeQuery)4 PrefixQuery (org.apache.lucene.search.PrefixQuery)4 Query (org.apache.lucene.search.Query)4 TermQuery (org.apache.lucene.search.TermQuery)4 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)4 WildcardQuery (org.apache.lucene.search.WildcardQuery)4 Filter (org.apache.jackrabbit.oak.spi.query.Filter)3 PropertyRestriction (org.apache.jackrabbit.oak.spi.query.Filter.PropertyRestriction)3 SuggestHelper (org.apache.jackrabbit.oak.plugins.index.lucene.util.SuggestHelper)2 FullTextExpression (org.apache.jackrabbit.oak.query.fulltext.FullTextExpression)2 FullTextTerm (org.apache.jackrabbit.oak.query.fulltext.FullTextTerm)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 ParseException (org.apache.lucene.queryparser.classic.ParseException)2 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)2 StandardQueryParser (org.apache.lucene.queryparser.flexible.standard.StandardQueryParser)2 Sort (org.apache.lucene.search.Sort)2