Search in sources :

Example 1 with FullTextSearchImpl

use of org.apache.jackrabbit.oak.query.ast.FullTextSearchImpl in project jackrabbit-oak by apache.

the class SimpleExcerptProvider method extractFulltext.

private static Set<String> extractFulltext(ConstraintImpl c) {
    Set<String> tokens = new HashSet<String>();
    // as it will break without us noticing if we extend the AST
    if (c instanceof FullTextSearchImpl) {
        FullTextSearchImpl f = (FullTextSearchImpl) c;
        if (f.getFullTextSearchExpression() instanceof LiteralImpl) {
            LiteralImpl l = (LiteralImpl) f.getFullTextSearchExpression();
            tokens.add(l.getLiteralValue().getValue(Type.STRING));
        }
    }
    if (c instanceof AndImpl) {
        for (ConstraintImpl constraint : ((AndImpl) c).getConstraints()) {
            tokens.addAll(extractFulltext(constraint));
        }
    }
    if (c instanceof OrImpl) {
        for (ConstraintImpl constraint : ((OrImpl) c).getConstraints()) {
            tokens.addAll(extractFulltext(constraint));
        }
    }
    return tokens;
}
Also used : LiteralImpl(org.apache.jackrabbit.oak.query.ast.LiteralImpl) ConstraintImpl(org.apache.jackrabbit.oak.query.ast.ConstraintImpl) FullTextSearchImpl(org.apache.jackrabbit.oak.query.ast.FullTextSearchImpl) AndImpl(org.apache.jackrabbit.oak.query.ast.AndImpl) OrImpl(org.apache.jackrabbit.oak.query.ast.OrImpl) HashSet(java.util.HashSet)

Example 2 with FullTextSearchImpl

use of org.apache.jackrabbit.oak.query.ast.FullTextSearchImpl in project jackrabbit-oak by apache.

the class QueryImpl method init.

@Override
public void init() {
    final QueryImpl query = this;
    if (constraint != null) {
        // need to do this *before* the visitation below, as the
        // simplify() method does not always keep the query reference
        // passed in setQuery(). TODO: avoid that mutability concern
        constraint = constraint.simplify();
    }
    new AstVisitorBase() {

        @Override
        public boolean visit(BindVariableValueImpl node) {
            node.setQuery(query);
            bindVariableMap.put(node.getBindVariableName(), null);
            return true;
        }

        @Override
        public boolean visit(ChildNodeImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(ChildNodeJoinConditionImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(ColumnImpl node) {
            node.setQuery(query);
            return true;
        }

        @Override
        public boolean visit(DescendantNodeImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(DescendantNodeJoinConditionImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(EquiJoinConditionImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(FullTextSearchImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return super.visit(node);
        }

        @Override
        public boolean visit(NativeFunctionImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return super.visit(node);
        }

        @Override
        public boolean visit(SimilarImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return super.visit(node);
        }

        @Override
        public boolean visit(SpellcheckImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return super.visit(node);
        }

        @Override
        public boolean visit(SuggestImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return super.visit(node);
        }

        @Override
        public boolean visit(FullTextSearchScoreImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(LiteralImpl node) {
            node.setQuery(query);
            return true;
        }

        @Override
        public boolean visit(NodeLocalNameImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(NodeNameImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(PropertyExistenceImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(PropertyInexistenceImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(PropertyValueImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(SameNodeImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(SameNodeJoinConditionImpl node) {
            node.setQuery(query);
            node.bindSelector(source);
            return true;
        }

        @Override
        public boolean visit(SelectorImpl node) {
            String name = node.getSelectorName();
            if (selectorIndexes.put(name, selectors.size()) != null) {
                throw new IllegalArgumentException("Two selectors with the same name: " + name);
            }
            selectors.add(node);
            node.setQuery(query);
            return true;
        }

        @Override
        public boolean visit(LengthImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(UpperCaseImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(LowerCaseImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(ComparisonImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(InImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(AndImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(OrImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }

        @Override
        public boolean visit(NotImpl node) {
            node.setQuery(query);
            return super.visit(node);
        }
    }.visit(this);
    source.setQueryConstraint(constraint);
    for (ColumnImpl column : columns) {
        column.bindSelector(source);
    }
    distinctColumns = new boolean[columns.length];
    for (int i = 0; i < columns.length; i++) {
        ColumnImpl c = columns[i];
        boolean distinct = true;
        if (JCR_SCORE.equals(c.getPropertyName())) {
            distinct = false;
        }
        distinctColumns[i] = distinct;
    }
    init = true;
}
Also used : SpellcheckImpl(org.apache.jackrabbit.oak.query.ast.SpellcheckImpl) NodeLocalNameImpl(org.apache.jackrabbit.oak.query.ast.NodeLocalNameImpl) AstVisitorBase(org.apache.jackrabbit.oak.query.ast.AstVisitorBase) FullTextSearchScoreImpl(org.apache.jackrabbit.oak.query.ast.FullTextSearchScoreImpl) PropertyInexistenceImpl(org.apache.jackrabbit.oak.query.ast.PropertyInexistenceImpl) UpperCaseImpl(org.apache.jackrabbit.oak.query.ast.UpperCaseImpl) InImpl(org.apache.jackrabbit.oak.query.ast.InImpl) DescendantNodeJoinConditionImpl(org.apache.jackrabbit.oak.query.ast.DescendantNodeJoinConditionImpl) NodeNameImpl(org.apache.jackrabbit.oak.query.ast.NodeNameImpl) BindVariableValueImpl(org.apache.jackrabbit.oak.query.ast.BindVariableValueImpl) SuggestImpl(org.apache.jackrabbit.oak.query.ast.SuggestImpl) ComparisonImpl(org.apache.jackrabbit.oak.query.ast.ComparisonImpl) PropertyExistenceImpl(org.apache.jackrabbit.oak.query.ast.PropertyExistenceImpl) SameNodeJoinConditionImpl(org.apache.jackrabbit.oak.query.ast.SameNodeJoinConditionImpl) ChildNodeImpl(org.apache.jackrabbit.oak.query.ast.ChildNodeImpl) SimilarImpl(org.apache.jackrabbit.oak.query.ast.SimilarImpl) PropertyValueImpl(org.apache.jackrabbit.oak.query.ast.PropertyValueImpl) SameNodeImpl(org.apache.jackrabbit.oak.query.ast.SameNodeImpl) NotImpl(org.apache.jackrabbit.oak.query.ast.NotImpl) DescendantNodeImpl(org.apache.jackrabbit.oak.query.ast.DescendantNodeImpl) NativeFunctionImpl(org.apache.jackrabbit.oak.query.ast.NativeFunctionImpl) ChildNodeJoinConditionImpl(org.apache.jackrabbit.oak.query.ast.ChildNodeJoinConditionImpl) LiteralImpl(org.apache.jackrabbit.oak.query.ast.LiteralImpl) FullTextSearchImpl(org.apache.jackrabbit.oak.query.ast.FullTextSearchImpl) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) LowerCaseImpl(org.apache.jackrabbit.oak.query.ast.LowerCaseImpl) LengthImpl(org.apache.jackrabbit.oak.query.ast.LengthImpl) AndImpl(org.apache.jackrabbit.oak.query.ast.AndImpl) ColumnImpl(org.apache.jackrabbit.oak.query.ast.ColumnImpl) OrImpl(org.apache.jackrabbit.oak.query.ast.OrImpl) EquiJoinConditionImpl(org.apache.jackrabbit.oak.query.ast.EquiJoinConditionImpl)

Example 3 with FullTextSearchImpl

use of org.apache.jackrabbit.oak.query.ast.FullTextSearchImpl in project jackrabbit-oak by apache.

the class QueryCostOverheadTest method getCostOverhead.

@Test
public void getCostOverhead() {
    QueryImpl query;
    UnionQueryImpl union;
    ConstraintImpl c, c1, c2, c3, c4, c5;
    c1 = new ComparisonImpl(null, null, null);
    c2 = new FullTextSearchImpl(null, null, null);
    union = new UnionQueryImpl(false, new QueryImpl(null, null, c1, null, null, null), new QueryImpl(null, null, c2, null, null, null), null);
    assertFalse("we always expect false from a `UnionQueryImpl`", union.containsUnfilteredFullTextCondition());
    c1 = new ComparisonImpl(null, null, null);
    c2 = new FullTextSearchImpl(null, null, null);
    c = new OrImpl(c1, c2);
    query = new QueryImpl(null, null, c, null, null, null);
    assertTrue(query.containsUnfilteredFullTextCondition());
    c1 = new ComparisonImpl(null, null, null);
    c2 = new FullTextSearchImpl(null, null, null);
    c3 = new FullTextSearchImpl(null, null, null);
    c = new OrImpl(of(c1, c2, c3));
    query = new QueryImpl(null, null, c, null, null, null);
    assertTrue(query.containsUnfilteredFullTextCondition());
    c2 = new FullTextSearchImpl(null, null, null);
    c3 = new FullTextSearchImpl(null, null, null);
    c4 = new ComparisonImpl(null, null, null);
    c1 = new OrImpl(of(c2, c3, c4));
    c5 = mock(DescendantNodeImpl.class);
    c = new AndImpl(c1, c5);
    query = new QueryImpl(null, null, c, null, null, null);
    assertTrue(query.containsUnfilteredFullTextCondition());
    c = new FullTextSearchImpl(null, null, null);
    query = new QueryImpl(null, null, c, null, null, null);
    assertFalse(query.containsUnfilteredFullTextCondition());
    c1 = new FullTextSearchImpl(null, null, null);
    c2 = new FullTextSearchImpl(null, null, null);
    c3 = new FullTextSearchImpl(null, null, null);
    c = new OrImpl(of(c1, c2, c3));
    query = new QueryImpl(null, null, c, null, null, null);
    assertFalse(query.containsUnfilteredFullTextCondition());
    c1 = new ComparisonImpl(null, null, null);
    c2 = new FullTextSearchImpl(null, null, null);
    c3 = new FullTextSearchImpl(null, null, null);
    c = new AndImpl(of(c1, c2, c3));
    query = new QueryImpl(null, null, c, null, null, null);
    assertFalse(query.containsUnfilteredFullTextCondition());
    c1 = new ComparisonImpl(null, null, null);
    c2 = new ComparisonImpl(null, null, null);
    c = new AndImpl(of(c1, c2, c3));
    query = new QueryImpl(null, null, c, null, null, null);
    assertFalse(query.containsUnfilteredFullTextCondition());
}
Also used : ComparisonImpl(org.apache.jackrabbit.oak.query.ast.ComparisonImpl) ConstraintImpl(org.apache.jackrabbit.oak.query.ast.ConstraintImpl) FullTextSearchImpl(org.apache.jackrabbit.oak.query.ast.FullTextSearchImpl) DescendantNodeImpl(org.apache.jackrabbit.oak.query.ast.DescendantNodeImpl) AndImpl(org.apache.jackrabbit.oak.query.ast.AndImpl) OrImpl(org.apache.jackrabbit.oak.query.ast.OrImpl) Test(org.junit.Test)

Aggregations

AndImpl (org.apache.jackrabbit.oak.query.ast.AndImpl)3 FullTextSearchImpl (org.apache.jackrabbit.oak.query.ast.FullTextSearchImpl)3 OrImpl (org.apache.jackrabbit.oak.query.ast.OrImpl)3 ComparisonImpl (org.apache.jackrabbit.oak.query.ast.ComparisonImpl)2 ConstraintImpl (org.apache.jackrabbit.oak.query.ast.ConstraintImpl)2 DescendantNodeImpl (org.apache.jackrabbit.oak.query.ast.DescendantNodeImpl)2 LiteralImpl (org.apache.jackrabbit.oak.query.ast.LiteralImpl)2 HashSet (java.util.HashSet)1 AstVisitorBase (org.apache.jackrabbit.oak.query.ast.AstVisitorBase)1 BindVariableValueImpl (org.apache.jackrabbit.oak.query.ast.BindVariableValueImpl)1 ChildNodeImpl (org.apache.jackrabbit.oak.query.ast.ChildNodeImpl)1 ChildNodeJoinConditionImpl (org.apache.jackrabbit.oak.query.ast.ChildNodeJoinConditionImpl)1 ColumnImpl (org.apache.jackrabbit.oak.query.ast.ColumnImpl)1 DescendantNodeJoinConditionImpl (org.apache.jackrabbit.oak.query.ast.DescendantNodeJoinConditionImpl)1 EquiJoinConditionImpl (org.apache.jackrabbit.oak.query.ast.EquiJoinConditionImpl)1 FullTextSearchScoreImpl (org.apache.jackrabbit.oak.query.ast.FullTextSearchScoreImpl)1 InImpl (org.apache.jackrabbit.oak.query.ast.InImpl)1 LengthImpl (org.apache.jackrabbit.oak.query.ast.LengthImpl)1 LowerCaseImpl (org.apache.jackrabbit.oak.query.ast.LowerCaseImpl)1 NativeFunctionImpl (org.apache.jackrabbit.oak.query.ast.NativeFunctionImpl)1