use of org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex in project jackrabbit-oak by apache.
the class LuceneIndexTest method assertQuery.
private void assertQuery(IndexTracker tracker, NodeState indexed, String key, String value) {
AdvancedQueryIndex queryIndex = new LucenePropertyIndex(tracker);
FilterImpl filter = createFilter(NT_BASE);
filter.restrictPath("/", Filter.PathRestriction.EXACT);
filter.restrictProperty(key, Operator.EQUAL, PropertyValues.newString(value));
List<IndexPlan> plans = queryIndex.getPlans(filter, null, indexed);
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.AdvancedQueryIndex in project jackrabbit-oak by apache.
the class LuceneIndexTest method testPathRestrictions.
@Test
public void testPathRestrictions() throws Exception {
NodeBuilder idx = newLucenePropertyIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", ImmutableSet.of("foo"), null);
idx.setProperty(LuceneIndexConstants.EVALUATE_PATH_RESTRICTION, true);
NodeState before = builder.getNodeState();
builder.setProperty("foo", "bar");
builder.child("a").setProperty("foo", "bar");
builder.child("a1").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 = createTestFilter();
filter.restrictPath("/", Filter.PathRestriction.EXACT);
assertFilter(filter, queryIndex, indexed, ImmutableList.of("/"));
filter = createTestFilter();
filter.restrictPath("/", Filter.PathRestriction.DIRECT_CHILDREN);
assertFilter(filter, queryIndex, indexed, ImmutableList.of("/a", "/a1"));
filter = createTestFilter();
filter.restrictPath("/a", Filter.PathRestriction.DIRECT_CHILDREN);
assertFilter(filter, queryIndex, indexed, ImmutableList.of("/a/b"));
filter = createTestFilter();
filter.restrictPath("/a", Filter.PathRestriction.ALL_CHILDREN);
assertFilter(filter, queryIndex, indexed, ImmutableList.of("/a/b", "/a/b/c"));
}
use of org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex in project jackrabbit-oak by apache.
the class LuceneIndexTest method testLucene3.
@Test
public void testLucene3() throws Exception {
NodeBuilder index = newLucenePropertyIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", ImmutableSet.of("foo"), null);
NodeBuilder rules = index.child(INDEX_RULES);
NodeBuilder fooProp = rules.child("nt:base").child(LuceneIndexConstants.PROP_NODE).child("foo");
fooProp.setProperty(LuceneIndexConstants.PROP_PROPERTY_INDEX, true);
fooProp.setProperty(LuceneIndexConstants.PROP_INCLUDED_TYPE, PropertyType.TYPENAME_STRING);
NodeState before = builder.getNodeState();
builder.setProperty("foo", "bar");
builder.child("a").setProperty("foo", "bar");
builder.child("a").child("b").setProperty("foo", "bar", Type.NAME);
builder.child("a").child("b").child("c").setProperty("foo", "bar", Type.NAME);
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", cursor.next().getPath());
assertEquals("/", cursor.next().getPath());
assertFalse(cursor.hasNext());
}
use of org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex in project jackrabbit-oak by apache.
the class LuceneIndexTest method testLuceneV1NonExistentProperty.
@Test
public void testLuceneV1NonExistentProperty() throws Exception {
NodeBuilder index = builder.child(INDEX_DEFINITIONS_NAME);
NodeBuilder defn = newLuceneIndexDefinition(index, "lucene", ImmutableSet.of("String"));
defn.setProperty(LuceneIndexConstants.COMPAT_MODE, IndexFormatVersion.V1.getVersion());
NodeState before = builder.getNodeState();
builder.setProperty("foo", "value-with-dash");
NodeState after = builder.getNodeState();
NodeState indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
tracker = new IndexTracker();
tracker.update(indexed);
AdvancedQueryIndex queryIndex = new LuceneIndex(tracker, null);
FilterImpl filter = createFilter(NT_BASE);
filter.restrictPath("/", Filter.PathRestriction.EXACT);
filter.setFullTextConstraint(FullTextParser.parse("foo", "value-with*"));
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());
//Now perform a query against a field which does not exist
FilterImpl filter2 = createFilter(NT_BASE);
filter2.restrictPath("/", Filter.PathRestriction.EXACT);
filter2.setFullTextConstraint(FullTextParser.parse("baz", "value-with*"));
List<IndexPlan> plans2 = queryIndex.getPlans(filter2, null, builder.getNodeState());
Cursor cursor2 = queryIndex.query(plans2.get(0), indexed);
assertFalse(cursor2.hasNext());
}
use of org.apache.jackrabbit.oak.spi.query.QueryIndex.AdvancedQueryIndex in project jackrabbit-oak by apache.
the class LuceneIndexTest method analyzerWithStopWords.
@Test
public void analyzerWithStopWords() throws Exception {
NodeBuilder nb = newLuceneIndexDefinition(builder.child(INDEX_DEFINITIONS_NAME), "lucene", of(TYPENAME_STRING));
TestUtil.useV2(nb);
NodeState before = builder.getNodeState();
builder.setProperty("foo", "fox jumping");
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.setFullTextConstraint(new FullTextTerm(null, "fox jumping", false, false, null));
assertFilter(filter, queryIndex, indexed, ImmutableList.of("/"));
//No stop word configured so default analyzer would also check for 'was'
filter.setFullTextConstraint(new FullTextTerm(null, "fox was jumping", false, false, null));
assertFilter(filter, queryIndex, indexed, Collections.<String>emptyList());
//Change the default analyzer to use the default stopword set
//and trigger a reindex such that new analyzer is used
NodeBuilder anlnb = nb.child(ANALYZERS).child(ANL_DEFAULT);
anlnb.child(ANL_TOKENIZER).setProperty(ANL_NAME, "whitespace");
anlnb.child(ANL_FILTERS).child("stop");
nb.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true);
before = after;
after = builder.getNodeState();
indexed = HOOK.processCommit(before, after, CommitInfo.EMPTY);
tracker.update(indexed);
queryIndex = new LucenePropertyIndex(tracker);
filter.setFullTextConstraint(new FullTextTerm(null, "fox jumping", false, false, null));
assertFilter(filter, queryIndex, indexed, ImmutableList.of("/"));
//Now this should get passed as the analyzer would ignore 'was'
filter.setFullTextConstraint(new FullTextTerm(null, "fox was jumping", false, false, null));
assertFilter(filter, queryIndex, indexed, ImmutableList.of("/"));
}
Aggregations