Search in sources :

Example 6 with AdvancedQueryIndex

use of org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex in project jackrabbit-oak by apache.

the class LuceneIndexTest method assertQuery.

private void assertQuery(IndexTracker tracker, NodeState indexed, String key, String value) {
    AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker);
    FilterImpl filter = createFilter(NT_BASE);
    filter.restrictPath("/", Filter.PathRestriction.EXACT);
    filter.restrictProperty(key, Operator.EQUAL, PropertyValues.newString(value));
    List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed);
    Cursor cursor = queryIndex.query(plans.get(0), indexed);
    assertTrue(cursor.hasNext());
    assertEquals("/", cursor.next().getPath());
    assertFalse(cursor.hasNext());
}
Also used : AdvancedQueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor)

Example 7 with AdvancedQueryIndex

use of org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex in project jackrabbit-oak by apache.

the class LuceneIndexTest method testPathRestrictions.

@Test
public void testPathRestrictions() throws Exception {
    NodeBuilder idx = newLucenePropertyIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", ImmutableSet.of("foo"), null);
    idx.setProperty(LuceneIndexConstants.EVALUATE_PATH_RESTRICTION, true);
    NodeState before = builder.getNodeState();
    builder.setProperty("foo", "bar");
    builder.child("a").setProperty("foo", "bar");
    builder.child("a1").setProperty("foo", "bar");
    builder.child("a").child("b").setProperty("foo", "bar");
    builder.child("a").child("b").child("c").setProperty("foo", "bar");
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    tracker = new IndexTracker();
    tracker.update(indexed);
    AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker);
    FilterImpl filter = createTestFilter();
    filter.restrictPath("/", Filter.PathRestriction.EXACT);
    assertFilter(filter, queryIndex, indexed, ImmutableList.of("/"));
    filter = createTestFilter();
    filter.restrictPath("/", Filter.PathRestriction.DIRECT_CHILDREN);
    assertFilter(filter, queryIndex, indexed, ImmutableList.of("/a", "/a1"));
    filter = createTestFilter();
    filter.restrictPath("/a", Filter.PathRestriction.DIRECT_CHILDREN);
    assertFilter(filter, queryIndex, indexed, ImmutableList.of("/a/b"));
    filter = createTestFilter();
    filter.restrictPath("/a", Filter.PathRestriction.ALL_CHILDREN);
    assertFilter(filter, queryIndex, indexed, ImmutableList.of("/a/b", "/a/b/c"));
}
Also used : AdvancedQueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 8 with AdvancedQueryIndex

use of org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex in project jackrabbit-oak by apache.

the class LuceneIndexTest method testLucene3.

@Test
public void testLucene3() throws Exception {
    NodeBuilder index = newLucenePropertyIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", ImmutableSet.of("foo"), null);
    NodeBuilder rules = index.child(INDEX_RULES);
    NodeBuilder fooProp = rules.child("nt:base").child(LuceneIndexConstants.PROP_NODE).child("foo");
    fooProp.setProperty(LuceneIndexConstants.PROP_PROPERTY_INDEX, true);
    fooProp.setProperty(LuceneIndexConstants.PROP_INCLUDED_TYPE, PropertyType.TYPENAME_STRING);
    NodeState before = builder.getNodeState();
    builder.setProperty("foo", "bar");
    builder.child("a").setProperty("foo", "bar");
    builder.child("a").child("b").setProperty("foo", "bar", Type.NAME);
    builder.child("a").child("b").child("c").setProperty("foo", "bar", Type.NAME);
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    tracker = new IndexTracker();
    tracker.update(indexed);
    AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker);
    FilterImpl filter = createFilter(NT_BASE);
    // filter.restrictPath("/", Filter.PathRestriction.EXACT);
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed);
    Cursor cursor = queryIndex.query(plans.get(0), indexed);
    assertTrue(cursor.hasNext());
    assertEquals("/a", cursor.next().getPath());
    assertEquals("/", cursor.next().getPath());
    assertFalse(cursor.hasNext());
}
Also used : AdvancedQueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) Test(org.junit.Test)

Example 9 with AdvancedQueryIndex

use of org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex in project jackrabbit-oak by apache.

the class LuceneIndexTest method testLuceneV1NonExistentProperty.

@Test
public void testLuceneV1NonExistentProperty() throws Exception {
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    NodeBuilder defn = newLuceneIndexDefinition(index, "lucene", ImmutableSet.of("String"));
    defn.setProperty(LuceneIndexConstants.COMPAT_MODE, IndexFormatVersion.V1.getVersion());
    NodeState before = builder.getNodeState();
    builder.setProperty("foo", "value-with-dash");
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    tracker = new IndexTracker();
    tracker.update(indexed);
    AdvancedQueryIndex queryIndex = new LuceneIndex(tracker, null);
    FilterImpl filter = createFilter(NT_BASE);
    filter.restrictPath("/", Filter.PathRestriction.EXACT);
    filter.setFullTextConstraint(FullTextParser.parse("foo", "value-with*"));
    List<IndexPlan> plans = queryIndex.getPlans(filter, null, builder.getNodeState());
    Cursor cursor = queryIndex.query(plans.get(0), indexed);
    assertTrue(cursor.hasNext());
    assertEquals("/", cursor.next().getPath());
    assertFalse(cursor.hasNext());
    //Now perform a query against a field which does not exist
    FilterImpl filter2 = createFilter(NT_BASE);
    filter2.restrictPath("/", Filter.PathRestriction.EXACT);
    filter2.setFullTextConstraint(FullTextParser.parse("baz", "value-with*"));
    List<IndexPlan> plans2 = queryIndex.getPlans(filter2, null, builder.getNodeState());
    Cursor cursor2 = queryIndex.query(plans2.get(0), indexed);
    assertFalse(cursor2.hasNext());
}
Also used : AdvancedQueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) IndexPlan(org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Cursor(org.apache.jackrabbit.oak.spi.query.Cursor) Test(org.junit.Test)

Example 10 with AdvancedQueryIndex

use of org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex in project jackrabbit-oak by apache.

the class LuceneIndexTest method analyzerWithStopWords.

@Test
public void analyzerWithStopWords() throws Exception {
    NodeBuilder nb = newLuceneIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", of(TYPENAME_STRING));
    TestUtil.useV2(nb);
    NodeState before = builder.getNodeState();
    builder.setProperty("foo", "fox jumping");
    NodeState after = builder.getNodeState();
    NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    tracker = new IndexTracker();
    tracker.update(indexed);
    AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker);
    FilterImpl filter = createFilter("nt:base");
    filter.setFullTextConstraint(new FullTextTerm(null, "fox jumping", false, false, null));
    assertFilter(filter, queryIndex, indexed, ImmutableList.of("/"));
    //No stop word configured so default analyzer would also check for 'was'
    filter.setFullTextConstraint(new FullTextTerm(null, "fox was jumping", false, false, null));
    assertFilter(filter, queryIndex, indexed, Collections.<String>emptyList());
    //Change the default analyzer to use the default stopword set
    //and trigger a reindex such that new analyzer is used
    NodeBuilder anlnb = nb.child(ANALYZERS).child(ANL_DEFAULT);
    anlnb.child(ANL_TOKENIZER).setProperty(ANL_NAME, "whitespace");
    anlnb.child(ANL_FILTERS).child("stop");
    nb.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true);
    before = after;
    after = builder.getNodeState();
    indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
    tracker.update(indexed);
    queryIndex = new LucenePropertyIndex(tracker);
    filter.setFullTextConstraint(new FullTextTerm(null, "fox jumping", false, false, null));
    assertFilter(filter, queryIndex, indexed, ImmutableList.of("/"));
    //Now this should get passed as the analyzer would ignore 'was'
    filter.setFullTextConstraint(new FullTextTerm(null, "fox was jumping", false, false, null));
    assertFilter(filter, queryIndex, indexed, ImmutableList.of("/"));
}
Also used : AdvancedQueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) FullTextTerm(org.apache.jackrabbit.oak.query.fulltext.FullTextTerm) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Aggregations

AdvancedQueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex)18 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)14 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)13 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)13 Test (org.junit.Test)13 IndexPlan (org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan)11 Cursor (org.apache.jackrabbit.oak.spi.query.Cursor)7 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)4 FullTextTerm (org.apache.jackrabbit.oak.query.fulltext.FullTextTerm)2 Function (com.google.common.base.Function)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ScorerProvider (org.apache.jackrabbit.oak.plugins.index.lucene.score.ScorerProvider)1 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)1 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)1 TraversingIndex (org.apache.jackrabbit.oak.query.index.TraversingIndex)1 SelectorExecutionPlan (org.apache.jackrabbit.oak.query.plan.SelectorExecutionPlan)1 IndexRow (org.apache.jackrabbit.oak.spi.query.IndexRow)1 OrderEntry (org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry)1