use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class IndexPlannerTest method fulltextIndexCost.
@Test
public void fulltextIndexCost() throws Exception {
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
NodeBuilder defn = newLuceneIndexDefinition(index, "lucene", of(TYPENAME_STRING));
TestUtil.useV2(defn);
long numofDocs = IndexDefinition.DEFAULT_ENTRY_COUNT + 1000;
IndexNode node = createIndexNode(new IndexDefinition(root, defn.getNodeState(), "/foo"), numofDocs);
FilterImpl filter = createFilter("nt:base");
filter.setFullTextConstraint(FullTextParser.parse(".", "mountain"));
IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
QueryIndex.IndexPlan plan = planner.getPlan();
assertNotNull(plan);
assertEquals(numofDocs, plan.getEstimatedEntryCount());
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class IndexPlannerTest method hasPathRestHasMatchingQueryPaths.
@Test
public void hasPathRestHasMatchingQueryPaths() throws Exception {
NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async");
defn.setProperty(createProperty(IndexConstants.QUERY_PATHS, of("/test/a", "/test/b"), Type.STRINGS));
IndexNode node = createIndexNode(new IndexDefinition(root, defn.getNodeState(), "/foo"));
FilterImpl filter = createFilter("nt:base");
filter.restrictPath("/test/a", Filter.PathRestriction.ALL_CHILDREN);
filter.restrictProperty("foo", Operator.EQUAL, PropertyValues.newString("bar"));
IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
assertNotNull(planner.getPlan());
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class IndexPlannerTest method nullPropertyCheck.
@Test
public void nullPropertyCheck() throws Exception {
NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async");
IndexNode node = createIndexNode(new IndexDefinition(root, defn.getNodeState(), "/foo"));
FilterImpl filter = createFilter("nt:base");
filter.restrictProperty("foo", Operator.EQUAL, null);
IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
QueryIndex.IndexPlan plan = planner.getPlan();
assertNull("For null checks no plan should be returned", plan);
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class IndexPlannerTest method purePropertyIndexAndPathRestriction.
@Test
public void purePropertyIndexAndPathRestriction() throws Exception {
NodeBuilder defn = newLucenePropertyIndexDefinition(builder, "test", of("foo"), "async");
defn.setProperty(LuceneIndexConstants.EVALUATE_PATH_RESTRICTION, true);
IndexNode node = createIndexNode(new IndexDefinition(root, defn.getNodeState(), "/foo"));
FilterImpl filter = createFilter("nt:base");
filter.restrictPath("/content", Filter.PathRestriction.ALL_CHILDREN);
IndexPlanner planner = new IndexPlanner(node, "/foo", filter, Collections.<OrderEntry>emptyList());
assertNull(planner.getPlan());
}
use of org.apache.jackrabbit.oak.query.index.FilterImpl in project jackrabbit-oak by apache.
the class LuceneIndexTest method customScoreQuery.
@Test
public void customScoreQuery() throws Exception {
NodeBuilder nb = newLuceneIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", of(TYPENAME_STRING));
TestUtil.useV2(nb);
nb.setProperty(LuceneIndexConstants.PROP_SCORER_PROVIDER, "testScorer");
NodeState before = builder.getNodeState();
builder.child("a").setProperty("jcr:createdBy", "bar bar");
builder.child("b").setProperty("jcr:createdBy", "foo bar");
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
tracker = new IndexTracker();
tracker.update(indexed);
SimpleScorerFactory factory = new SimpleScorerFactory();
ScorerProvider provider = new ScorerProvider() {
String scorerName = "testScorer";
@Override
public String getName() {
return scorerName;
}
@Override
public CustomScoreQuery createCustomScoreQuery(Query query) {
return new ModifiedCustomScoreQuery(query);
}
class ModifiedCustomScoreQuery extends CustomScoreQuery {
private Query query;
public ModifiedCustomScoreQuery(Query query) {
super(query);
this.query = query;
}
@Override
public CustomScoreProvider getCustomScoreProvider(AtomicReaderContext context) {
return new CustomScoreProvider(context) {
public float customScore(int doc, float subQueryScore, float valSrcScore) {
AtomicReader atomicReader = context.reader();
try {
Document document = atomicReader.document(doc);
// boosting docs created by foo
String fieldValue = document.get("full:jcr:createdBy");
if (fieldValue != null && fieldValue.contains("foo")) {
valSrcScore *= 2.0;
}
} catch (IOException e) {
return subQueryScore * valSrcScore;
}
return subQueryScore * valSrcScore;
}
};
}
}
};
factory.providers.put(provider.getName(), provider);
AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker, factory);
FilterImpl filter = createFilter(NT_BASE);
filter.setFullTextConstraint(new FullTextTerm(null, "bar", false, false, null));
assertFilter(filter, queryIndex, indexed, asList("/b", "/a"), true);
}
Aggregations