use of org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan in project jackrabbit-oak by apache.
the class LuceneIndexTest method testLucene2.
@Test
public void testLucene2() throws Exception {
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo"), null);
NodeState before = builder.getNodeState();
builder.setProperty("foo", "bar");
builder.child("a").setProperty("foo", "bar");
builder.child("a").child("b").setProperty("foo", "bar");
builder.child("a").child("b").child("c").setProperty("foo", "bar");
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
tracker = new IndexTracker();
tracker.update(indexed);
AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker);
FilterImpl filter = createFilter(NT_BASE);
// filter.restrictPath("/", Filter.PathRestriction.EXACT);
filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed);
Cursor cursor = queryIndex.query(plans.get(0), indexed);
assertTrue(cursor.hasNext());
assertEquals("/a/b/c", cursor.next().getPath());
assertEquals("/a/b", cursor.next().getPath());
assertEquals("/a", cursor.next().getPath());
assertEquals("/", cursor.next().getPath());
assertFalse(cursor.hasNext());
}
use of org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan in project jackrabbit-oak by apache.
the class LuceneIndexTest method testLucene.
@Test
public void testLucene() throws Exception {
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo"), null);
NodeState before = builder.getNodeState();
builder.setProperty("foo", "bar");
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
tracker = new IndexTracker();
tracker.update(indexed);
AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker);
FilterImpl filter = createFilter(NT_BASE);
filter.restrictPath("/", Filter.PathRestriction.EXACT);
filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
List<IndexPlan> plans = queryIndex.getPlans(filter, null, builder.getNodeState());
Cursor cursor = queryIndex.query(plans.get(0), indexed);
assertTrue(cursor.hasNext());
assertEquals("/", cursor.next().getPath());
assertFalse(cursor.hasNext());
}
use of org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan in project jackrabbit-oak by apache.
the class LuceneIndexTest method testLuceneLazyCursor.
@Test
public void testLuceneLazyCursor() throws Exception {
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
newLucenePropertyIndexDefinition(index, "lucene", ImmutableSet.of("foo"), null);
NodeState before = builder.getNodeState();
builder.setProperty("foo", "bar");
for (int i = 0; i < LuceneIndex.LUCENE_QUERY_BATCH_SIZE; i++) {
builder.child("parent").child("child" + i).setProperty("foo", "bar");
}
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
tracker = new IndexTracker();
tracker.update(indexed);
AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker);
FilterImpl filter = createFilter(NT_BASE);
filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed);
Cursor cursor = queryIndex.query(plans.get(0), indexed);
List<String> paths = copyOf(transform(cursor, new Function<IndexRow, String>() {
public String apply(IndexRow input) {
return input.getPath();
}
}));
assertTrue(!paths.isEmpty());
assertEquals(LuceneIndex.LUCENE_QUERY_BATCH_SIZE + 1, paths.size());
}
use of org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan in project jackrabbit-oak by apache.
the class SelectorImpl method getIndexCostInfo.
@Override
public String getIndexCostInfo(NodeState rootState) {
StringBuilder buff = new StringBuilder();
buff.append(quoteJson(selectorName)).append(": ");
QueryIndex index = getIndex();
if (index != null) {
if (index instanceof AdvancedQueryIndex) {
IndexPlan p = plan.getIndexPlan();
buff.append("{ perEntry: ").append(p.getCostPerEntry());
buff.append(", perExecution: ").append(p.getCostPerExecution());
buff.append(", count: ").append(p.getEstimatedEntryCount());
buff.append(" }");
} else {
buff.append(index.getCost(createFilter(true), rootState));
}
}
return buff.toString();
}
use of org.apache.jackrabbit.oak.spi.query.QueryIndex.IndexPlan in project jackrabbit-oak by apache.
the class AggregateIndexPlan method getCostPerEntry.
@Override
public double getCostPerEntry() {
// calculate the weigted average
double costPerEntry = 0;
long totalEntries = getEstimatedEntryCount();
if (totalEntries == 0) {
return 0;
}
for (IndexPlan p : basePlans.values()) {
if (p != null) {
costPerEntry += p.getCostPerEntry() * p.getEstimatedEntryCount() / totalEntries;
}
}
return costPerEntry;
}
Aggregations