Search in sources :

Example 1 with FulltextIndexPlanner

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

the class IndexPlannerTest method fullTextQuery_DisjointPropertyPaths.

@Test
public void fullTextQuery_DisjointPropertyPaths() throws Exception {
    NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo", "bar"), "async");
    // Index all props and then perform fulltext
    defn = LuceneIndexDefinition.updateDefinition(defn.getNodeState().builder());
    NodeBuilder foob = getNode(defn, "indexRules/nt:base/properties/foo");
    foob.setProperty(FulltextIndexConstants.PROP_NAME, "foo");
    foob.setProperty(FulltextIndexConstants.PROP_ANALYZED, true);
    NodeBuilder barb = getNode(defn, "indexRules/nt:base/properties/bar");
    barb.setProperty(FulltextIndexConstants.PROP_NAME, "bar");
    barb.setProperty(FulltextIndexConstants.PROP_ANALYZED, true);
    FullTextExpression fooExp = FullTextParser.parse("metadata/bar", "mountain OR valley");
    FullTextExpression barExp = FullTextParser.parse("jcr:content/foo", "mountain OR valley");
    FullTextExpression exp = new FullTextAnd(Arrays.asList(fooExp, barExp));
    FulltextIndexPlanner planner = createPlannerForFulltext(defn.getNodeState(), exp);
    // No plan for unindex property
    assertNull(planner.getPlan());
}
Also used : FullTextAnd(org.apache.jackrabbit.oak.spi.query.fulltext.FullTextAnd) FullTextExpression(org.apache.jackrabbit.oak.spi.query.fulltext.FullTextExpression) FulltextIndexPlanner(org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 2 with FulltextIndexPlanner

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

the class IndexPlannerTest method facetGetsPlanned.

// ------ END - Cost via doc count per field plan tests
@Test
public void facetGetsPlanned() throws Exception {
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.indexRule("nt:base").property("foo").propertyIndex();
    defnb.indexRule("nt:base").property("facet").getBuilderTree().setProperty(FACETS, true);
    LuceneIndexDefinition defn = new LuceneIndexDefinition(root, defnb.build(), "/foo");
    LuceneIndexNode node = createIndexNode(defn);
    FilterImpl filter = createFilter("nt:base");
    filter.restrictProperty(REP_FACET, Operator.EQUAL, PropertyValues.newString(REP_FACET + "(facet)"));
    // just so that the index can be picked..
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    assertNotNull("Index supporting facet should participate", plan);
}
Also used : FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) 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 FulltextIndexPlanner

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

the class IndexPlannerTest method indexedButZeroWeightProps.

@Test
public void indexedButZeroWeightProps() throws Exception {
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.indexRule("nt:base").property("foo").propertyIndex();
    defnb.indexRule("nt:base").property("bar").propertyIndex().weight(0);
    LuceneIndexDefinition defn = new LuceneIndexDefinition(root, defnb.build(), "/foo");
    LuceneIndexNode node = createIndexNode(defn);
    FilterImpl filter = createFilter("nt:base");
    filter.restrictProperty("bar", Operator.EQUAL, PropertyValues.newString("a"));
    FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    // Even though foo is indexed it would not be considered for a query involving just foo
    assertNull(planner.getPlan());
    filter = createFilter("nt:base");
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("a"));
    planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    QueryIndex.IndexPlan plan1 = planner.getPlan();
    assertNotNull(plan1);
    filter = createFilter("nt:base");
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("a"));
    filter.restrictProperty("bar", Operator.EQUAL, PropertyValues.newString("a"));
    planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    QueryIndex.IndexPlan plan2 = planner.getPlan();
    assertNotNull(plan2);
    // Since, the index has no entries for "bar", estimated entry count for plan2 would be 0
    assertEquals(0, plan2.getEstimatedEntryCount());
    assertThat(plan2.getEstimatedEntryCount(), lessThan(plan1.getEstimatedEntryCount()));
    assertTrue(pr(plan2).hasProperty("foo"));
    assertTrue(pr(plan2).hasProperty("bar"));
}
Also used : OrderEntry(org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) 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 FulltextIndexPlanner

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

the class IndexPlannerTest method noRestrictionWithSingleSortableField.

// ------ END - Suggestion/spellcheck plan tests
// ------ Cost via doc count per field plan tests
@Test
public void noRestrictionWithSingleSortableField() throws Exception {
    NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async");
    defn.setProperty(createProperty(ORDERED_PROP_NAMES, of("foo"), STRINGS));
    LuceneIndexDefinition definition = new LuceneIndexDefinition(root, defn.getNodeState(), "/test");
    LuceneIndexNode node = createIndexNode(definition);
    FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/test", createFilter("nt:base"), ImmutableList.of(new OrderEntry("foo", Type.LONG, OrderEntry.Order.ASCENDING), new OrderEntry("bar", Type.LONG, OrderEntry.Order.ASCENDING)));
    assertNotNull(planner.getPlan());
    assertEquals(1, planner.getPlan().getEstimatedEntryCount());
    assertEquals(definition.getCostPerEntry() / 2, planner.getPlan().getCostPerEntry(), 0.0001);
}
Also used : OrderEntry(org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry) FulltextIndexPlanner(org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) Test(org.junit.Test)

Example 5 with FulltextIndexPlanner

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

the class IndexPlannerTest method costForPathTransformation.

@Test
public void costForPathTransformation() throws Exception {
    LuceneIndexStatistics.failReadingSyntheticallyFalliableField = true;
    String indexPath = "/test";
    LuceneIndexDefinitionBuilder idxBuilder = new LuceneIndexDefinitionBuilder(child(builder, indexPath));
    idxBuilder.indexRule("nt:base").property("foo").propertyIndex();
    idxBuilder.indexRule("nt:base").property("foo1").propertyIndex();
    idxBuilder.indexRule("nt:base").property("foo2").propertyIndex();
    Tree fooPD = idxBuilder.getBuilderTree().getChild("indexRules").getChild("nt:base").getChild("properties").getChild("foo2");
    fooPD.setProperty(PROP_FUNCTION, "lower([foo])");
    NodeState defn = idxBuilder.build();
    long numOfDocs = 100;
    LuceneIndexDefinition idxDefn = new LuceneIndexDefinition(root, defn, indexPath);
    LuceneIndexNode node = createIndexNode(idxDefn, 100);
    FilterImpl filter = createFilter("nt:base");
    filter.restrictProperty("a/foo", Operator.EQUAL, PropertyValues.newString("bar"));
    FulltextIndexPlanner planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    assertEquals(documentsPerValue(numOfDocs), plan.getEstimatedEntryCount());
    filter = createFilter("nt:base");
    filter.restrictProperty("a/foo", Operator.EQUAL, PropertyValues.newString("bar"));
    filter.restrictProperty("foo1", Operator.EQUAL, PropertyValues.newString("bar"));
    planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
    plan = planner.getPlan();
    // there is no doc with foo1
    assertEquals(0, plan.getEstimatedEntryCount());
    filter = createFilter("nt:base");
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    filter.restrictProperty("a/foo1", Operator.EQUAL, PropertyValues.newString("bar"));
    planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
    plan = planner.getPlan();
    // Because path transormation comes into play only when direct prop defs don't match
    assertEquals(documentsPerValue(numOfDocs), plan.getEstimatedEntryCount());
    filter = createFilter("nt:base");
    filter.restrictProperty("a/foo", Operator.EQUAL, PropertyValues.newString("bar"));
    filter.restrictProperty(FunctionIndexProcessor.convertToPolishNotation("lower([foo])"), Operator.EQUAL, PropertyValues.newString("foo1"));
    planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
    plan = planner.getPlan();
    // there is no doc with lower([foo])
    assertEquals(0, plan.getEstimatedEntryCount());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) Tree(org.apache.jackrabbit.oak.api.Tree) 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

FulltextIndexPlanner (org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner)73 Test (org.junit.Test)71 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)63 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)61 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)43 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)40 LuceneIndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder)31 OrderEntry (org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry)12 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)8 Document (org.apache.lucene.document.Document)8 StringField (org.apache.lucene.document.StringField)8 Directory (org.apache.lucene.store.Directory)7 RAMDirectory (org.apache.lucene.store.RAMDirectory)7 PropertyIndexResult (org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner.PropertyIndexResult)6 FullTextExpression (org.apache.jackrabbit.oak.spi.query.fulltext.FullTextExpression)4 Tree (org.apache.jackrabbit.oak.api.Tree)2 FullTextAnd (org.apache.jackrabbit.oak.spi.query.fulltext.FullTextAnd)2 DefaultDirectoryFactory (org.apache.jackrabbit.oak.plugins.index.lucene.directory.DefaultDirectoryFactory)1 DirectoryFactory (org.apache.jackrabbit.oak.plugins.index.lucene.directory.DirectoryFactory)1 DefaultIndexReaderFactory (org.apache.jackrabbit.oak.plugins.index.lucene.reader.DefaultIndexReaderFactory)1