use of org.apache.jackrabbit.oak.plugins.index.lucene.spi.FulltextQueryTermsProvider in project jackrabbit-oak by apache.
the class LuceneIndexAugmentTest method fulltextIndexUsingAugmentors.
//OAK-3576
@Test
public void fulltextIndexUsingAugmentors() throws Exception {
//setup repo and index
NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType");
Tree props = createIndex(TestUtil.NT_TEST);
TestUtil.enableForFullText(props, "foo1");
TestUtil.enableForFullText(props, "subChild/foo2");
root.commit();
//setup augmentors
final AtomicInteger indexingCounter = new AtomicInteger(0);
factory.indexFieldProvider = new IndexFieldProvider() {
@Nonnull
@Override
public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) {
indexingCounter.incrementAndGet();
return IndexFieldProvider.DEFAULT.getAugmentedFields(path, document, indexDefinition);
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
final AtomicInteger queryingCounter = new AtomicInteger(0);
factory.fulltextQueryTermsProvider = new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
queryingCounter.set(1);
return null;
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
//add content
Tree node1 = createNodeWithType(root.getTree("/"), "node1", TestUtil.NT_TEST);
node1.setProperty("foo1", "bar1");
node1.addChild("subChild").setProperty("foo2", "bar2");
root.commit();
//indexing assertions
assertEquals("Indexing augment should get called once", 1, indexingCounter.get());
String query = "SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE CONTAINS(*, 'bar1')";
executeQuery(query, SQL2);
assertEquals("Query augmentor should get called for full text constraints", 1, queryingCounter.get());
queryingCounter.set(0);
query = "EXPLAIN " + query;
List<String> paths = executeQuery(query, SQL2, false);
assertEquals("Query augmentor should get called for full text constraints", 1, queryingCounter.get());
assertTrue("property index should have made the index selected (" + paths.get(0) + ")", paths.get(0).contains("/* lucene:test-index("));
queryingCounter.set(0);
query = "SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE CONTAINS(*, 'bar2')";
executeQuery(query, SQL2);
assertEquals("Query augmentor should get called for full text constraints", 1, queryingCounter.get());
queryingCounter.set(0);
query = "EXPLAIN " + query;
paths = executeQuery(query, SQL2, false);
assertEquals("Query augmentor should get called for full text constraints", 1, queryingCounter.get());
assertTrue("property index should have made the index selected (" + paths.get(0) + ")", paths.get(0).contains("/* lucene:test-index("));
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.spi.FulltextQueryTermsProvider in project jackrabbit-oak by apache.
the class LuceneIndexAugmentTest method queryAugmentorMismatchedNodeType.
@Test
public void queryAugmentorMismatchedNodeType() throws Exception {
//setup repo and index
NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType");
Tree props = createIndex(TestUtil.NT_TEST);
TestUtil.enableForFullText(props, "foo1", false);
root.commit();
//setup augmentors
final AtomicInteger indexingCounter1 = new AtomicInteger(0);
final AtomicInteger indexingCounter2 = new AtomicInteger(0);
factory.registerQueryTermsProvider(new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
indexingCounter1.set(1);
return null;
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(JcrConstants.NT_BASE);
}
});
factory.registerQueryTermsProvider(new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
indexingCounter2.set(1);
return null;
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
});
factory.useSuperBehavior = true;
executeQuery("SELECT [jcr:path] FROM [" + TestUtil.NT_TEST + "] WHERE CONTAINS(*, 'test')", SQL2, false);
assertEquals("Mismatching node type should not let index augmentor called", 0, indexingCounter1.get());
assertEquals("Matching node type should get augmentor called", 1, indexingCounter2.get());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.spi.FulltextQueryTermsProvider in project jackrabbit-oak by apache.
the class LuceneIndexAugmentTest method queryHook.
//OAK-3576
@Test
public void queryHook() throws Exception {
//setup repo and index
NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType");
Tree props = createIndex(TestUtil.NT_TEST);
TestUtil.enableForFullText(props, "foo");
root.commit();
//setup query augmentor
final String testSearchText = "search this text";
final String realSearchText = "bar";
factory.fulltextQueryTermsProvider = new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
assertEquals("Full text term passed to provider isn't same as the one passed in query", testSearchText, text);
return new TermQuery(new Term(":fulltext", realSearchText));
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
//add content
Tree test = root.getTree("/").addChild("test");
Tree node = createNodeWithType(test, "item", TestUtil.NT_TEST);
node.setProperty("foo", realSearchText);
root.commit();
//query (testSearchText doesn't have 'bar'... our augment would search for :fulltext:bar
String query = "select [jcr:path] from [oak:TestNode] where CONTAINS(*, '" + testSearchText + "')";
List<String> paths = executeQuery(query, SQL2);
assertEquals("Augmented query wasn't used to search", 1, paths.size());
assertEquals("/test/item", paths.get(0));
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.spi.FulltextQueryTermsProvider in project jackrabbit-oak by apache.
the class LuceneIndexAugmentTest method skipDefaultOnlyUsingAugmentors.
//OAK-3576
@Test
public void skipDefaultOnlyUsingAugmentors() throws Exception {
//setup repo and index
NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType");
Tree props = createIndex(TestUtil.NT_TEST);
Tree prop = props.addChild("foo1");
prop.setProperty(LuceneIndexConstants.PROP_INDEX, true);
prop = props.addChild("foo2");
prop.setProperty(LuceneIndexConstants.PROP_NAME, "subChild/foo2");
prop.setProperty(LuceneIndexConstants.PROP_INDEX, true);
root.commit();
//setup augmentors
final AtomicInteger indexingCounter = new AtomicInteger(0);
factory.indexFieldProvider = new IndexFieldProvider() {
@Nonnull
@Override
public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) {
indexingCounter.incrementAndGet();
return IndexFieldProvider.DEFAULT.getAugmentedFields(path, document, indexDefinition);
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
final AtomicInteger queryingCounter = new AtomicInteger(0);
factory.fulltextQueryTermsProvider = new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
queryingCounter.set(1);
return null;
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
//add content
Tree node1 = createNodeWithType(root.getTree("/"), "node1", TestUtil.NT_TEST);
node1.setProperty("foo1", "bar1");
node1.addChild("subChild").setProperty("foo2", "bar2");
root.commit();
//indexing assertions
assertEquals("Indexing augment should get called once", 1, indexingCounter.get());
assertEquals("No docs should get indexed (augmentor hasn't added any field)", 0, getSearcher().getIndexReader().numDocs());
String query = "EXPLAIN SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE [foo1]='bar1'";
List<String> paths = executeQuery(query, SQL2);
assertTrue("indexed prop name shouldn't decide query plan (" + paths.get(0) + ")", paths.get(0).contains("/* no-index "));
query = "EXPLAIN SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE [subChild/foo2]='bar2'";
paths = executeQuery(query, SQL2);
assertTrue("indexed prop name shouldn't decide query plan (" + paths.get(0) + ")", paths.get(0).contains("/* no-index "));
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.spi.FulltextQueryTermsProvider in project jackrabbit-oak by apache.
the class IndexAugmentorFactory method refreshFulltextQueryTermsProviders.
private void refreshFulltextQueryTermsProviders() {
ListMultimap<String, FulltextQueryTermsProvider> providerMultimap = LinkedListMultimap.create();
for (FulltextQueryTermsProvider provider : fulltextQueryTermsProviders) {
Set<String> supportedNodeTypes = provider.getSupportedTypes();
for (String nodeType : supportedNodeTypes) {
providerMultimap.put(nodeType, provider);
}
}
Map<String, CompositeFulltextQueryTermsProvider> providerMap = Maps.newHashMap();
for (String nodeType : providerMultimap.keySet()) {
List<FulltextQueryTermsProvider> providers = providerMultimap.get(nodeType);
CompositeFulltextQueryTermsProvider compositeFulltextQueryTermsProvider = new CompositeFulltextQueryTermsProvider(nodeType, providers);
providerMap.put(nodeType, compositeFulltextQueryTermsProvider);
}
fulltextQueryTermsProviderMap = ImmutableMap.copyOf(providerMap);
}
Aggregations