use of org.apache.jackrabbit.oak.plugins.index.lucene.spi.IndexFieldProvider in project jackrabbit-oak by apache.
the class LuceneIndexAugmentTest method nullBehavior.
//OAK-3576
@Test
public void nullBehavior() 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();
Tree rootTree = root.getTree("/").addChild("test");
//Note: augmentor behavior is tested elsewhere... we are just checking if default works
int testIndex = 1;
//both query and index augmentors are null (no exception expected)
checkSimpleBehavior(rootTree, testIndex++);
//Set a very sad query augmentor
factory.fulltextQueryTermsProvider = new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
return null;
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return FulltextQueryTermsProvider.DEFAULT.getSupportedTypes();
}
};
checkSimpleBehavior(rootTree, testIndex++);
//Set query augmentor... with null query
factory.fulltextQueryTermsProvider = new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
return null;
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
checkSimpleBehavior(rootTree, testIndex++);
//Set query augmentor... with some query
factory.fulltextQueryTermsProvider = new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
return new TermQuery(new Term("bar", "baz"));
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
checkSimpleBehavior(rootTree, testIndex++);
factory.fulltextQueryTermsProvider = null;
//Set a very sad index augmentor
factory.indexFieldProvider = IndexFieldProvider.DEFAULT;
checkSimpleBehavior(rootTree, testIndex++);
//Set index augmentor... with null fields
factory.indexFieldProvider = new IndexFieldProvider() {
@Nonnull
@Override
public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) {
return IndexFieldProvider.DEFAULT.getAugmentedFields(path, document, indexDefinition);
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
checkSimpleBehavior(rootTree, testIndex++);
//Set index augmentor... with some fields
factory.fulltextQueryTermsProvider = null;
factory.indexFieldProvider = new IndexFieldProvider() {
@Nonnull
@Override
public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) {
List<Field> fields = Lists.newArrayList();
fields.add(new StringField("bar", "baz", Field.Store.NO));
return fields;
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
checkSimpleBehavior(rootTree, testIndex++);
//setup composite query term provider with one returning null query
factory.registerQueryTermsProvider(new FulltextQueryTermsProvider() {
@Override
public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) {
return null;
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
});
factory.useSuperBehavior = true;
checkSimpleBehavior(rootTree, testIndex++);
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.spi.IndexFieldProvider in project jackrabbit-oak by apache.
the class LuceneIndexAugmentTest method propertyIndexUsingAugmentors.
//OAK-3576
@Test
public void propertyIndexUsingAugmentors() throws Exception {
//setup repo and index
NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType");
Tree props = createIndex(TestUtil.NT_TEST);
TestUtil.enablePropertyIndex(props, "foo1", false);
TestUtil.enablePropertyIndex(props, "subChild/foo2", false);
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 [foo1]='bar1'";
executeQuery(query, SQL2);
assertEquals("Query augmentor should not get called for property constraints", 0, queryingCounter.get());
query = "EXPLAIN " + query;
List<String> paths = executeQuery(query, SQL2, false);
assertTrue("property index should have made the index selected (" + paths.get(0) + ")", paths.get(0).contains("/* lucene:test-index("));
query = "SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE [subChild/foo2]='bar2'";
executeQuery(query, SQL2);
assertEquals("Query augmentor should not get called for property constraints", 0, queryingCounter.get());
query = "EXPLAIN " + query;
paths = executeQuery(query, SQL2);
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.IndexFieldProvider in project jackrabbit-oak by apache.
the class IndexAugmentorFactory method refreshIndexFieldProviders.
private void refreshIndexFieldProviders() {
ListMultimap<String, IndexFieldProvider> providerMultimap = LinkedListMultimap.create();
for (IndexFieldProvider provider : indexFieldProviders) {
Set<String> supportedNodeTypes = provider.getSupportedTypes();
for (String nodeType : supportedNodeTypes) {
providerMultimap.put(nodeType, provider);
}
}
Map<String, CompositeIndexFieldProvider> providerMap = Maps.newHashMap();
for (String nodeType : providerMultimap.keySet()) {
List<IndexFieldProvider> providers = providerMultimap.get(nodeType);
CompositeIndexFieldProvider compositeIndexFieldProvider = new CompositeIndexFieldProvider(nodeType, providers);
providerMap.put(nodeType, compositeIndexFieldProvider);
}
indexFieldProviderMap = ImmutableMap.copyOf(providerMap);
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.spi.IndexFieldProvider 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.IndexFieldProvider in project jackrabbit-oak by apache.
the class LuceneIndexAugmentTest method indexAugmentorMismatchedNodeType.
@Test
public void indexAugmentorMismatchedNodeType() 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");
root.commit();
//setup augmentors
final AtomicInteger indexingCounter1 = new AtomicInteger(0);
final AtomicInteger indexingCounter2 = new AtomicInteger(0);
factory.registerIndexFieldProvider(new IndexFieldProvider() {
@Nonnull
@Override
public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) {
indexingCounter1.incrementAndGet();
return IndexFieldProvider.DEFAULT.getAugmentedFields(path, document, indexDefinition);
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(JcrConstants.NT_BASE);
}
});
factory.registerIndexFieldProvider(new IndexFieldProvider() {
@Nonnull
@Override
public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) {
indexingCounter2.incrementAndGet();
return IndexFieldProvider.DEFAULT.getAugmentedFields(path, document, indexDefinition);
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
});
factory.useSuperBehavior = true;
//add content
createNodeWithType(root.getTree("/"), "node1", TestUtil.NT_TEST).setProperty("foo1", "bar1");
root.commit();
assertEquals("Mismatching node type should not let index augmentor called", 0, indexingCounter1.get());
assertEquals("Matching node type should get augmentor called", 1, indexingCounter2.get());
}
Aggregations