use of org.apache.jackrabbit.oak.plugins.index.lucene.spi.IndexFieldProvider in project jackrabbit-oak by apache.
the class LuceneIndexAugmentTest method indexHookCallbackAndStorage.
//OAK-3576
@Test
public void indexHookCallbackAndStorage() throws Exception {
final String propName = "subChild/foo";
//setup repo and index
NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType");
Tree props = createIndex(TestUtil.NT_TEST);
TestUtil.enableForFullText(props, propName);
root.commit();
//setup index augmentor
factory.indexFieldProvider = new IndexFieldProvider() {
@Nonnull
@Override
public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) {
assertEquals("/test/item", path);
assertEquals(TestUtil.NT_TEST, document.getName(JcrConstants.JCR_PRIMARYTYPE));
assertEquals(IndexConstants.INDEX_DEFINITIONS_NODE_TYPE, indexDefinition.getName(JcrConstants.JCR_PRIMARYTYPE));
return Lists.<Field>newArrayList(new StringField("barbar", "1", Field.Store.NO));
}
@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).addChild("subChild");
node.setProperty("foo", "bar");
root.commit();
//Check document that made to the index
IndexSearcher searcher = getSearcher();
TopDocs docs = searcher.search(new TermQuery(new Term("barbar", "1")), 10);
ScoreDoc[] scoreDocs = docs.scoreDocs;
assertEquals("Number of results should be 1", 1, scoreDocs.length);
Document doc = searcher.doc(scoreDocs[0].doc);
String path = doc.get(":path");
assertEquals("/test/item", path);
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.spi.IndexFieldProvider 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.IndexFieldProvider in project jackrabbit-oak by apache.
the class LuceneIndexAugmentTest method indexHookCallbackFrequency.
//OAK-3576
@Test
public void indexHookCallbackFrequency() 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, "foo2", false);
TestUtil.enablePropertyIndex(props, "subChild/foo3", false);
root.commit();
//setup index augmentor
final AtomicInteger counter = new AtomicInteger(0);
factory.indexFieldProvider = new IndexFieldProvider() {
@Nonnull
@Override
public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) {
counter.incrementAndGet();
return IndexFieldProvider.DEFAULT.getAugmentedFields(path, document, indexDefinition);
}
@Nonnull
@Override
public Set<String> getSupportedTypes() {
return Collections.singleton(TestUtil.NT_TEST);
}
};
//add content
counter.set(0);
Tree test = root.getTree("/").addChild("test");
Tree node = createNodeWithType(test, "item", TestUtil.NT_TEST);
node.setProperty("foo1", "bar1");
node.setProperty("foo2", "bar2");
Tree subChild = node.addChild("subChild");
subChild.setProperty("foo3", "bar3");
root.commit();
assertEquals("Number of callbacks should be same as number of changed properties", 1, counter.get());
//change sub-property
counter.set(0);
subChild = root.getTree("/test/item/subChild");
subChild.setProperty("foo3", "bar4");
root.commit();
assertEquals("Sub child property change should make call backs for all indexed properties", 1, counter.get());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.spi.IndexFieldProvider in project jackrabbit-oak by apache.
the class IndexAugmentorFactoryTest method compositeIndexProvider.
@Test
public void compositeIndexProvider() {
final String typeA = "type:A";
final String typeB = "type:B";
final String typeC = "type:C";
final String typeD = "type:D";
context.registerInjectActivateService(indexAugmentorFactory);
new IdentifiableIndexFiledProvider("1", Sets.newHashSet(typeA, typeB));
new IdentifiableIndexFiledProvider("2", Sets.newHashSet(typeC));
new IdentifiableIndexFiledProvider("3", Sets.newHashSet(typeA, typeB));
//register an instance which would be unregistered before validation
IndexFieldProvider unreg = new IdentifiableIndexFiledProvider("4", Sets.newHashSet(typeD));
indexAugmentorFactory.unbindIndexFieldProvider(unreg);
validateComposedFields(typeA, "1", "3");
validateComposedFields(typeC, "2");
validateComposedFields(typeD);
MockOsgi.deactivate(indexAugmentorFactory, context.bundleContext(), Collections.EMPTY_MAP);
validateDeactivatedService();
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.spi.IndexFieldProvider in project jackrabbit-oak by apache.
the class IndexAugmentorFactoryTest method validateComposedFields.
void validateComposedFields(String type, String... expected) {
IndexFieldProvider compositeIndexProvider = indexAugmentorFactory.getIndexFieldProvider(type);
if (expected.length > 0) {
assertTrue("Composed index field provider doesn't declare correct supported type", compositeIndexProvider.getSupportedTypes().contains(type));
}
Iterable<Field> fields = compositeIndexProvider.getAugmentedFields(null, null, null);
Set<String> ids = Sets.newHashSet();
for (Field f : fields) {
ids.add(f.stringValue());
}
assertEquals(expected.length, Iterables.size(ids));
assertThat(ids, CoreMatchers.hasItems(expected));
}
Aggregations