Search in sources :

Example 16 with LuceneIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class IndexPlannerTest method relativeProperty_MultipleMatch.

@Test
public void relativeProperty_MultipleMatch() throws Exception {
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.indexRule("nt:base").property("foo").propertyIndex();
    defnb.indexRule("nt:base").property("bar").propertyIndex();
    defnb.indexRule("nt:base").property("baz").propertyIndex();
    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"));
    filter.restrictProperty("jcr:content/bar", Operator.EQUAL, PropertyValues.newString("/bar"));
    filter.restrictProperty("metadata/baz", Operator.EQUAL, PropertyValues.newString("/bar"));
    FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    assertNotNull(plan);
    FulltextIndexPlanner.PlanResult pr = pr(plan);
    assertTrue(pr.hasProperty("jcr:content/foo"));
    assertTrue(pr.hasProperty("jcr:content/bar"));
    assertFalse(pr.hasProperty("metadata/baz"));
}
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 17 with LuceneIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class IndexPlannerTest method unableToReadCountForJcrTitle.

@Test
public void unableToReadCountForJcrTitle() throws Exception {
    try {
        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(SYNTHETICALLY_FALLIABLE_FIELD).propertyIndex();
        idxBuilder.indexRule("nt:base").property("bar").propertyIndex();
        NodeState defn = idxBuilder.build();
        long numOfDocs = 100;
        LuceneIndexDefinition idxDefn = new LuceneIndexDefinition(root, defn, indexPath);
        Document doc = new Document();
        doc.add(new StringField("foo1", "bar1", Field.Store.NO));
        doc.add(new StringField(SYNTHETICALLY_FALLIABLE_FIELD, "failingField", Field.Store.NO));
        Directory sampleDirectory = createSampleDirectory(numOfDocs, doc);
        LuceneIndexNode node = createIndexNode(idxDefn, sampleDirectory);
        FilterImpl filter = createFilter("nt:base");
        filter.restrictProperty("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(SYNTHETICALLY_FALLIABLE_FIELD, Operator.EQUAL, PropertyValues.newString("bar"));
        planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
        plan = planner.getPlan();
        // falliable field's count couldn't be read - so, fallback to numDocs
        assertEquals(numOfDocs + 1, plan.getEstimatedEntryCount());
        filter = createFilter("nt:base");
        filter.restrictProperty("foo1", Operator.EQUAL, PropertyValues.newString("bar"));
        filter.restrictProperty(SYNTHETICALLY_FALLIABLE_FIELD, Operator.EQUAL, PropertyValues.newString("bar"));
        planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
        plan = planner.getPlan();
        // min() still comes into play even when one field's count couldn't be read
        assertEquals(1, plan.getEstimatedEntryCount());
        filter = createFilter("nt:base");
        filter.restrictProperty("bar", Operator.EQUAL, PropertyValues.newString("bar"));
        filter.restrictProperty(SYNTHETICALLY_FALLIABLE_FIELD, Operator.EQUAL, PropertyValues.newString("bar"));
        planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
        plan = planner.getPlan();
        // min() still comes into play even when one field's count couldn't be read
        assertEquals(0, plan.getEstimatedEntryCount());
    } finally {
        LuceneIndexStatistics.failReadingSyntheticallyFalliableField = false;
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) Document(org.apache.lucene.document.Document) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) StringField(org.apache.lucene.document.StringField) 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) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory) Test(org.junit.Test)

Example 18 with LuceneIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class IndexPlannerTest method syncNodeTypeIndex.

@Test
public void syncNodeTypeIndex() throws Exception {
    TestUtil.registerNodeType(builder, testNodeTypeDefn);
    root = builder.getNodeState();
    LuceneIndexDefinitionBuilder defnb = new LuceneIndexDefinitionBuilder();
    defnb.nodeTypeIndex();
    defnb.indexRule("oak:TestSuperType").sync();
    LuceneIndexDefinition defn = new LuceneIndexDefinition(root, defnb.build(), "/foo");
    LuceneIndexNode node = createIndexNode(defn);
    FilterImpl filter = createFilter("oak:TestSuperType");
    FulltextIndexPlanner planner = new FulltextIndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    assertNotNull(plan);
    FulltextIndexPlanner.PlanResult r = pr(plan);
    assertTrue(r.evaluateNodeTypeRestriction());
    assertTrue(r.evaluateSyncNodeTypeRestriction());
}
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 19 with LuceneIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class IndexPlannerTest method unableToIterateFields.

@Test
public void unableToIterateFields() throws Exception {
    try {
        LuceneIndexStatistics.failReadingFields = true;
        String indexPath = "/test";
        LuceneIndexDefinitionBuilder idxBuilder = new LuceneIndexDefinitionBuilder(child(builder, indexPath));
        idxBuilder.indexRule("nt:base").property("foo").propertyIndex();
        idxBuilder.indexRule("nt:base").property("bar").propertyIndex();
        NodeState defn = idxBuilder.build();
        long numOfDocs = 100;
        LuceneIndexDefinition idxDefn = new LuceneIndexDefinition(root, defn, indexPath);
        LuceneIndexNode node = createIndexNode(idxDefn, numOfDocs);
        FilterImpl filter = createFilter("nt:base");
        filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
        FulltextIndexPlanner planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
        QueryIndex.IndexPlan plan = planner.getPlan();
        assertEquals(numOfDocs, plan.getEstimatedEntryCount());
        filter = createFilter("nt:base");
        filter.restrictProperty("bar", Operator.EQUAL, PropertyValues.newString("bar"));
        planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
        plan = planner.getPlan();
        assertEquals(numOfDocs, plan.getEstimatedEntryCount());
        filter = createFilter("nt:base");
        filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
        filter.restrictProperty("bar", Operator.EQUAL, PropertyValues.newString("bar"));
        planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
        plan = planner.getPlan();
        assertEquals(numOfDocs, plan.getEstimatedEntryCount());
    } finally {
        LuceneIndexStatistics.failReadingFields = false;
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) 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 20 with LuceneIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class IndexPlannerTest method weightedPropDefs.

@Test
public void weightedPropDefs() throws Exception {
    String indexPath = "/test";
    LuceneIndexDefinitionBuilder idxBuilder = new LuceneIndexDefinitionBuilder(child(builder, indexPath));
    idxBuilder.indexRule("nt:base").property("foo").propertyIndex().weight(500).enclosingRule().property("foo1").propertyIndex().weight(20).enclosingRule().property("foo2").propertyIndex().weight(0).enclosingRule().property("foo3").propertyIndex();
    NodeState defn = idxBuilder.build();
    List<Document> docs = Lists.newArrayList();
    Document doc;
    for (int i = 0; i < 60; i++) {
        doc = new Document();
        doc.add(new StringField("foo1", "bar1" + i, Field.Store.NO));
        docs.add(doc);
    }
    doc = new Document();
    doc.add(new StringField("foo2", "bar2", Field.Store.NO));
    docs.add(doc);
    Directory sampleDirectory = createSampleDirectory(1000, docs);
    LuceneIndexDefinition idxDefn = new LuceneIndexDefinition(root, defn, indexPath);
    LuceneIndexNode node = createIndexNode(idxDefn, sampleDirectory);
    // Query on "foo"
    FilterImpl filter = createFilter("nt:base");
    filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
    FulltextIndexPlanner planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
    QueryIndex.IndexPlan plan = planner.getPlan();
    // scale down 1000 by 500 = 2
    assertEquals(2, plan.getEstimatedEntryCount());
    // Query on "foo1"
    filter = createFilter("nt:base");
    filter.restrictProperty("foo1", Operator.EQUAL, PropertyValues.newString("bar"));
    planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
    plan = planner.getPlan();
    // scale down 60 by 20 = 2
    assertEquals(3, plan.getEstimatedEntryCount());
    // Query on "foo" and "foo1"
    filter = createFilter("nt:base");
    filter.restrictProperty("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();
    // min(2, 3)
    assertEquals(2, plan.getEstimatedEntryCount());
    // Query on "foo1" and "foo2"
    filter = createFilter("nt:base");
    filter.restrictProperty("foo1", Operator.EQUAL, PropertyValues.newString("bar"));
    filter.restrictProperty("foo2", Operator.EQUAL, PropertyValues.newString("bar"));
    planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
    plan = planner.getPlan();
    // don't scale down 1 by 0 (foo1 would estimate 3)
    assertEquals(1, plan.getEstimatedEntryCount());
    // Query on "foo1" and "foo3"
    filter = createFilter("nt:base");
    filter.restrictProperty("foo1", Operator.EQUAL, PropertyValues.newString("bar"));
    filter.restrictProperty("foo3", Operator.EQUAL, PropertyValues.newString("bar"));
    planner = new FulltextIndexPlanner(node, indexPath, filter, Collections.emptyList());
    plan = planner.getPlan();
    // min(0, 3)
    assertEquals(0, plan.getEstimatedEntryCount());
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) FilterImpl(org.apache.jackrabbit.oak.query.index.FilterImpl) Document(org.apache.lucene.document.Document) LuceneIndexHelper.newLuceneIndexDefinition(org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition) StringField(org.apache.lucene.document.StringField) 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) Directory(org.apache.lucene.store.Directory) RAMDirectory(org.apache.lucene.store.RAMDirectory) Test(org.junit.Test)

Aggregations

LuceneIndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder)110 Test (org.junit.Test)94 LuceneIndexHelper.newLuceneIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLuceneIndexDefinition)44 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)37 Tree (org.apache.jackrabbit.oak.api.Tree)35 IndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder)33 FulltextIndexPlanner (org.apache.jackrabbit.oak.plugins.index.search.spi.query.FulltextIndexPlanner)31 QueryIndex (org.apache.jackrabbit.oak.spi.query.QueryIndex)29 AbstractQueryTest (org.apache.jackrabbit.oak.query.AbstractQueryTest)27 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)20 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)20 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition)18 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)18 LuceneIndexHelper.newLucenePropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexHelper.newLucenePropertyIndexDefinition)13 OrderEntry (org.apache.jackrabbit.oak.spi.query.QueryIndex.OrderEntry)6 Document (org.apache.lucene.document.Document)6 StringField (org.apache.lucene.document.StringField)6 Directory (org.apache.lucene.store.Directory)6 RAMDirectory (org.apache.lucene.store.RAMDirectory)6 IndexingRule (org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition.IndexingRule)5