Search in sources :

Example 66 with FilterImpl

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

the class LuceneIndexTest method testLucene.

@Test
public void testLucene() throws Exception {
    NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
    newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo"), null);
    NodeState before = builder.getNodeState();
    builder.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 = createFilter(NT_BASE);
    filter.restrictPath("/", Filter.PathRestriction.EXACT);
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    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());
}
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 67 with FilterImpl

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

the class LuceneIndexTest method nodeNameIndex.

@Test
public void nodeNameIndex() throws Exception {
    NodeBuilder index = newLucenePropertyIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", ImmutableSet.of("foo"), null);
    NodeBuilder rules = index.child(INDEX_RULES);
    NodeBuilder ruleNode = rules.child(NT_FILE);
    ruleNode.setProperty(LuceneIndexConstants.INDEX_NODE_NAME, true);
    NodeState before = builder.getNodeState();
    createNodeWithType(builder, "foo", NT_FILE);
    createNodeWithType(builder, "camelCase", NT_FILE);
    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_FILE);
    filter.restrictProperty(QueryConstants.RESTRICTION_LOCAL_NAME, Operator.EQUAL, PropertyValues.newString("foo"));
    assertFilter(filter, queryIndex, indexed, ImmutableList.of("/foo"));
    filter = createFilter(NT_FILE);
    filter.restrictProperty(QueryConstants.RESTRICTION_LOCAL_NAME, Operator.LIKE, PropertyValues.newString("camelCase"));
    assertFilter(filter, queryIndex, indexed, ImmutableList.of("/camelCase"));
    filter = createFilter(NT_FILE);
    filter.restrictProperty(QueryConstants.RESTRICTION_LOCAL_NAME, Operator.LIKE, PropertyValues.newString("camel%"));
    assertFilter(filter, queryIndex, indexed, ImmutableList.of("/camelCase"));
}
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 68 with FilterImpl

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

the class MultiplexingLucenePropertyIndexTest method createFilter.

private FilterImpl createFilter(String nodeTypeName) {
    NodeTypeInfoProvider nodeTypes = new NodeStateNodeTypeInfoProvider(initialContent);
    NodeTypeInfo type = nodeTypes.getNodeTypeInfo(nodeTypeName);
    SelectorImpl selector = new SelectorImpl(type, nodeTypeName);
    return new FilterImpl(selector, "SELECT * FROM [" + nodeTypeName + "]", new QueryEngineSettings());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) NodeTypeInfo(org.apache.jackrabbit.oak.query.ast.NodeTypeInfo) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider) NodeTypeInfoProvider(org.apache.jackrabbit.oak.query.ast.NodeTypeInfoProvider) NodeStateNodeTypeInfoProvider(org.apache.jackrabbit.oak.query.NodeStateNodeTypeInfoProvider)

Example 69 with FilterImpl

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

the class MultiplexingLucenePropertyIndexTest method numDocsIsSumOfAllReaders.

@Test
public void numDocsIsSumOfAllReaders() throws Exception {
    NodeBuilder defnBuilder = newLucenePropertyIndexDefinition(builder, "test", ImmutableSet.of("foo"), "async");
    IndexDefinition defn = new IndexDefinition(initialContent, defnBuilder.getNodeState(), "/foo");
    //1. Have 2 reader created by writes in 2 diff mounts
    LuceneIndexWriterFactory factory = new DefaultIndexWriterFactory(mip, null, null);
    LuceneIndexWriter writer = factory.newInstance(defn, builder, true);
    writer.updateDocument("/content/en", newDoc("/content/en"));
    writer.updateDocument("/libs/config", newDoc("/libs/config"));
    writer.close(0);
    //2. Construct the readers
    LuceneIndexReaderFactory readerFactory = new DefaultIndexReaderFactory(mip, null);
    List<LuceneIndexReader> readers = readerFactory.createReaders(defn, builder.getNodeState(), "/foo");
    IndexNode node = new IndexNode("foo", defn, readers, null);
    //3 Obtain the plan
    FilterImpl filter = createFilter("nt:base");
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<QueryIndex.OrderEntry>emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    //Count should be sum of both readers
    assertEquals(2, plan.getEstimatedEntryCount());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) LuceneIndexWriter(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter) LuceneIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriterFactory) LuceneIndexReaderFactory(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReaderFactory) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) LuceneIndexReader(org.apache.jackrabbit.oak.plugins.index.lucene.reader.LuceneIndexReader) LuceneIndexHelper.newLucenePropertyIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) DefaultIndexReaderFactory(org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory) DefaultIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Example 70 with FilterImpl

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

the class SolrQueryIndexTest method testNoPlanWithOnlyPathRestrictionsEnabled.

@Test
public void testNoPlanWithOnlyPathRestrictionsEnabled() throws Exception {
    NodeBuilder builder = nodeState.builder();
    builder.child("oak:index").child("solr").setProperty("pathRestrictions", true);
    nodeState = builder.getNodeState();
    SelectorImpl selector = newSelector(nodeState, "a");
    SolrQueryIndex solrQueryIndex = new SolrQueryIndex(null, null, null);
    FilterImpl filter = new FilterImpl(selector, "select * from [nt:base] as a where isdescendantnode(a, '/test')", new QueryEngineSettings());
    filter.restrictPath("/test", Filter.PathRestriction.ALL_CHILDREN);
    List<QueryIndex.OrderEntry> sortOrder = new LinkedList<QueryIndex.OrderEntry>();
    List<QueryIndex.IndexPlan> plans = solrQueryIndex.getPlans(filter, sortOrder, nodeState);
    assertEquals(0, plans.size());
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) SelectorImpl(org.apache.jackrabbit.oak.query.ast.SelectorImpl) QueryEngineSettings(org.apache.jackrabbit.oak.query.QueryEngineSettings) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) LinkedList(java.util.LinkedList) 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