Search in sources :

Example 1 with PropertyIndexResult

use of org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PropertyIndexResult in project jackrabbit-oak by apache.

the class LucenePropertyIndex method mergePropertyIndexResult.

@SuppressWarnings("Guava")
private static Iterator<FulltextResultRow> mergePropertyIndexResult(IndexPlan plan, NodeState rootState, Iterator<FulltextResultRow> itr) {
    PlanResult pr = getPlanResult(plan);
    HybridPropertyIndexLookup lookup = new HybridPropertyIndexLookup(pr.indexPath, NodeStateUtils.getNode(rootState, pr.indexPath), plan.getPathPrefix(), false);
    PropertyIndexResult pir = pr.getPropertyIndexResult();
    FluentIterable<String> paths;
    if (pir != null) {
        Iterable<String> queryResult = lookup.query(plan.getFilter(), pir.propertyName, pir.pr);
        paths = FluentIterable.from(queryResult).transform(path -> pr.isPathTransformed() ? pr.transformPath(path) : path).filter(notNull());
    } else {
        // Either of property or nodetype should not be null
        checkState(pr.evaluateSyncNodeTypeRestriction());
        Filter filter = plan.getFilter();
        paths = FluentIterable.from(Iterables.concat(lookup.query(filter, JCR_PRIMARYTYPE, newName(filter.getPrimaryTypes())), lookup.query(filter, JCR_MIXINTYPES, newName(filter.getMixinTypes()))));
    }
    // No need for path restriction evaluation as thats taken care by PropertyIndex impl itself
    // via content mirror strategy
    FluentIterable<FulltextResultRow> propIndex = paths.transform(path -> new FulltextResultRow(path, 0, null, null, null));
    // Property index itr should come first
    return Iterators.concat(propIndex.iterator(), itr);
}
Also used : PlanResult(org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PlanResult) PropertyIndexResult(org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PropertyIndexResult) Filter(org.apache.jackrabbit.oak.spi.query.Filter) HybridPropertyIndexLookup(org.apache.jackrabbit.oak.plugins.index.lucene.property.HybridPropertyIndexLookup)

Example 2 with PropertyIndexResult

use of org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PropertyIndexResult in project jackrabbit-oak by apache.

the class IndexPlannerTest method syncIndex_NotUsedWithSort.

@Test
public void syncIndex_NotUsedWithSort() throws Exception {
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.indexRule("nt:base").property("foo").propertyIndex().sync();
    defnb.indexRule("nt:base").property("bar").propertyIndex().ordered();
    LuceneIndexDefinition defn = new LuceneIndexDefinition(root, defnb.build(), "/foo");
    LuceneIndexNode node = createIndexNode(defn, 100);
    FilterImpl filter = createFilter("nt:base");
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, ImmutableList.of(new OrderEntry("bar", Type.LONG, OrderEntry.Order.ASCENDING)));
    QueryIndex.IndexPlan plan = planner.getPlan();
    assertNotNull(plan);
    assertEquals(documentsPerValue(100), plan.getEstimatedEntryCount());
    PropertyIndexResult hr = pr(plan).getPropertyIndexResult();
    assertNull(hr);
}
Also used : OrderEntry(org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) PropertyIndexResult(org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PropertyIndexResult) FulltextIndexPlanner(org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) LuceneIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) Test(org.junit.Test)

Example 3 with PropertyIndexResult

use of org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PropertyIndexResult in project jackrabbit-oak by apache.

the class IndexPlannerTest method syncIndex_NotUsedWithFulltext.

@Test
public void syncIndex_NotUsedWithFulltext() throws Exception {
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.indexRule("nt:base").property("foo").propertyIndex().sync();
    defnb.indexRule("nt:base").property("bar").analyzed();
    LuceneIndexDefinition defn = new LuceneIndexDefinition(root, defnb.build(), "/foo");
    LuceneIndexNode node = createIndexNode(defn, 100);
    FilterImpl filter = createFilter("nt:base");
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    filter.setFullTextConstraint(FullTextParser.parse("bar", "mountain"));
    FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, ImmutableList.of(new OrderEntry("bar", Type.LONG, OrderEntry.Order.ASCENDING)));
    QueryIndex.IndexPlan plan = planner.getPlan();
    assertNotNull(plan);
    assertEquals(documentsPerValue(100), plan.getEstimatedEntryCount());
    PropertyIndexResult hr = pr(plan).getPropertyIndexResult();
    assertNull(hr);
}
Also used : OrderEntry(org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) PropertyIndexResult(org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PropertyIndexResult) FulltextIndexPlanner(org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) LuceneIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) Test(org.junit.Test)

Example 4 with PropertyIndexResult

use of org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PropertyIndexResult in project jackrabbit-oak by apache.

the class IndexPlannerTest method syncIndex_uniqueIndex.

// ~------------------------------< sync indexes >
@Test
public void syncIndex_uniqueIndex() throws Exception {
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.indexRule("nt:base").property("foo").propertyIndex().unique();
    LuceneIndexDefinition defn = new LuceneIndexDefinition(root, defnb.build(), "/foo");
    LuceneIndexNode node = createIndexNode(defn, 100);
    FilterImpl filter = createFilter("nt:base");
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    assertNotNull(plan);
    assertEquals(1, plan.getEstimatedEntryCount());
    PropertyIndexResult hr = pr(plan).getPropertyIndexResult();
    assertNotNull(hr);
    assertEquals("foo", hr.propertyName);
    assertEquals("foo", hr.pr.propertyName);
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) PropertyIndexResult(org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PropertyIndexResult) FulltextIndexPlanner(org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) LuceneIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) Test(org.junit.Test)

Example 5 with PropertyIndexResult

use of org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PropertyIndexResult in project jackrabbit-oak by apache.

the class IndexPlannerTest method syncIndex_uniqueAndRelative.

@Test
public void syncIndex_uniqueAndRelative() throws Exception {
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.indexRule("nt:base").property("foo").propertyIndex().unique();
    LuceneIndexDefinition defn = new LuceneIndexDefinition(root, defnb.build(), "/foo");
    LuceneIndexNode node = createIndexNode(defn);
    FilterImpl filter = createFilter("nt:base");
    filter.restrictProperty("jcr:content/foo", Operator.EQUAL, PropertyValues.newString("bar"));
    FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    assertNotNull(plan);
    assertEquals(1, plan.getEstimatedEntryCount());
    PropertyIndexResult hr = pr(plan).getPropertyIndexResult();
    assertNotNull(hr);
    assertEquals("foo", hr.propertyName);
    assertEquals("jcr:content/foo", hr.pr.propertyName);
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) PropertyIndexResult(org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PropertyIndexResult) FulltextIndexPlanner(org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner) QueryIndex(org.apache.jackrabbit.oak.spi.query.QueryIndex) LuceneIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) Test(org.junit.Test)

Aggregations

PropertyIndexResult (org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PropertyIndexResult)7 LuceneIndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder)6 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)6 FulltextIndexPlanner (org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner)6 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)6 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)6 Test (org.junit.Test)6 OrderEntry (org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry)2 HybridPropertyIndexLookup (org.apache.jackrabbit.oak.plugins.index.lucene.property.HybridPropertyIndexLookup)1 PlanResult (org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PlanResult)1 Filter (org.apache.jackrabbit.oak.spi.query.Filter)1