Search in sources :

Example 61 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class IndexPlannerTest method fulltextIndexCost.

@Test
public void fulltextIndexCost() throws Exception {
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder defn = newLuceneIndexDefinition(index, "lucene", of(TYPENAME_STRING));
    TestUtil.useV2(defn);
    long numofDocs = IndexDefinition.DEFAULT_ENTRY_COUNT + 1000;
    IndexNode node = createIndexNode(new IndexDefinition(root, defn.getNodeState(), "/foo"), numofDocs);
    FilterImpl filter = createFilter("nt:base");
    filter.setFullTextConstraint(FullTextParser.parse(".", "mountain"));
    IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    assertNotNull(plan);
    assertEquals(numofDocs, plan.getEstimatedEntryCount());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 62 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class IndexPlannerTest method hasPathRestHasMatchingQueryPaths.

@Test
public void hasPathRestHasMatchingQueryPaths() throws Exception {
    NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async");
    defn.setProperty(createProperty(IndexConstants.QUERY_PATHS, of("/test/a", "/test/b"), Type.STRINGS));
    IndexNode node = createIndexNode(new IndexDefinition(root, defn.getNodeState(), "/foo"));
    FilterImpl filter = createFilter("nt:base");
    filter.restrictPath("/test/a", Filter.PathRestriction.ALL_CHILDREN);
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    assertNotNull(planner.getPlan());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 63 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class IndexPlannerTest method nullPropertyCheck.

@Test
public void nullPropertyCheck() throws Exception {
    NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async");
    IndexNode node = createIndexNode(new IndexDefinition(root, defn.getNodeState(), "/foo"));
    FilterImpl filter = createFilter("nt:base");
    filter.restrictProperty("foo", Operator.EQUAL, null);
    IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    assertNull("For null checks no plan should be returned", plan);
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 64 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class IndexPlannerTest method purePropertyIndexAndPathRestriction.

@Test
public void purePropertyIndexAndPathRestriction() throws Exception {
    NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async");
    defn.setProperty(LuceneIndexConstants.EVALUATE_PATH_RESTRICTION, true);
    IndexNode node = createIndexNode(new IndexDefinition(root, defn.getNodeState(), "/foo"));
    FilterImpl filter = createFilter("nt:base");
    filter.restrictPath("/content", Filter.PathRestriction.ALL_CHILDREN);
    IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    assertNull(planner.getPlan());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 65 with FilterImpl

use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.

the class LuceneIndexTest method customScoreQuery.

@Test
public void customScoreQuery() throws Exception {
    NodeBuilder nb = newLuceneIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", of(TYPENAME_STRING));
    TestUtil.useV2(nb);
    nb.setProperty(LuceneIndexConstants.PROP_SCORER_PROVIDER, "testScorer");
    NodeState before = builder.getNodeState();
    builder.child("a").setProperty("jcr:createdBy", "bar bar");
    builder.child("b").setProperty("jcr:createdBy", "foo bar");
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    tracker = new IndexTracker();
    tracker.update(indexed);
    SimpleScorerFactory factory = new SimpleScorerFactory();
    ScorerProvider provider = new ScorerProvider() {

        String scorerName = "testScorer";

        @Override
        public String getName() {
            return scorerName;
        }

        @Override
        public CustomScoreQuery createCustomScoreQuery(Query query) {
            return new ModifiedCustomScoreQuery(query);
        }

        class ModifiedCustomScoreQuery extends CustomScoreQuery {

            private Query query;

            public ModifiedCustomScoreQuery(Query query) {
                super(query);
                this.query = query;
            }

            @Override
            public CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
                return new CustomScoreProvider(context) {

                    public float customScore(int doc, float subQueryScore, float valSrcScore) {
                        AtomicReader atomicReader = context.reader();
                        try {
                            Document document = atomicReader.document(doc);
                            // boosting docs created by foo
                            String fieldValue = document.get("full:jcr:createdBy");
                            if (fieldValue != null && fieldValue.contains("foo")) {
                                valSrcScore *= 2.0;
                            }
                        } catch (IOException e) {
                            return subQueryScore * valSrcScore;
                        }
                        return subQueryScore * valSrcScore;
                    }
                };
            }
        }
    };
    factory.providers.put(provider.getName(), provider);
    AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker, factory);
    FilterImpl filter = createFilter(NT_BASE);
    filter.setFullTextConstraint(new FullTextTerm(null, "bar", false, false, null));
    assertFilter(filter, queryIndex, indexed, asList("/b", "/a"), true);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) Query(org.apache.lucene.search.Query) CustomScoreQuery(org.apache.lucene.queries.CustomScoreQuery) AtomicReader(org.apache.lucene.index.AtomicReader) IOException(java.io.IOException) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Document(org.apache.lucene.document.Document) AdvancedQueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex) ScorerProvider(org.apache.jackrabbit.oak.plugins.index.lucene.score.ScorerProvider) FullTextTerm(org.apache.jackrabbit.oak.query.fulltext.FullTextTerm) CustomScoreProvider(org.apache.lucene.queries.CustomScoreProvider) AtomicReaderContext(org.apache.lucene.index.AtomicReaderContext) Test(org.junit.Test)

Aggregations

FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)98 Test (org.junit.Test)81 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)74 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)39 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)28 SelectorImpl (org.apache.jackrabbit.oak.query.ast.SelectorImpl)27 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)26 QueryEngineSettings (org.apache.jackrabbit.oak.query.QueryEngineSettings)26 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)25 AdvancedQueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex)15 LinkedList (java.util.LinkedList)14 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)14 NodeStateNodeTypeInfoProvider (org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)10 NodeTypeInfo (org.apache.jackrabbit.oak.query.ast.NodeTypeInfo)10 NodeTypeInfoProvider (org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider)10 Cursor (org.apache.jackrabbit.oak.spi.query.Cursor)9 IndexPlan (org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan)8 IndexUpdateProvider (org.apache.jackrabbit.oak.plugins.index.IndexUpdateProvider)4 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)4 DefaultSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.DefaultSolrConfiguration)3