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"));
}
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;
}
}
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());
}
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;
}
}
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());
}
Aggregations