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