use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class LucenePropertyIndexTest method storedIndexDefinitionDiff.
@Test
public void storedIndexDefinitionDiff() throws Exception {
IndexDefinitionBuilder idxb = new IndexDefinitionBuilder().noAsync();
idxb.indexRule("nt:base").property("foo").propertyIndex();
Tree idx = root.getTree("/").getChild("oak:index").addChild("test1");
idxb.build(idx);
root.commit();
AsyncIndexInfoService asyncService = new AsyncIndexInfoServiceImpl(nodeStore);
LuceneIndexInfoProvider indexInfoProvider = new LuceneIndexInfoProvider(nodeStore, asyncService, temporaryFolder.newFolder());
IndexInfo info = indexInfoProvider.getInfo("/oak:index/test1");
assertNotNull(info);
assertFalse(info.hasIndexDefinitionChangedWithoutReindexing());
assertNull(info.getIndexDefinitionDiff());
Tree idxTree = root.getTree("/oak:index/test1");
idxTree.setProperty("foo", "bar");
root.commit();
info = indexInfoProvider.getInfo("/oak:index/test1");
assertTrue(info.hasIndexDefinitionChangedWithoutReindexing());
assertNotNull(info.getIndexDefinitionDiff());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class LucenePropertyIndexTest method subNodeTypes.
@Test
public void subNodeTypes() throws Exception {
optionalEditorProvider.delegate = new TypeEditorProvider();
String testNodeTypes = "[oak:TestMixA]\n" + " mixin\n" + "\n" + "[oak:TestSuperType] \n" + " - * (UNDEFINED) multiple\n" + "\n" + "[oak:TestTypeA] > oak:TestSuperType\n" + " - * (UNDEFINED) multiple\n" + "\n" + " [oak:TestTypeB] > oak:TestSuperType, oak:TestMixA\n" + " - * (UNDEFINED) multiple\n" + "\n" + " [oak:TestTypeC] > oak:TestMixA\n" + " - * (UNDEFINED) multiple";
NodeTypeRegistry.register(root, IOUtils.toInputStream(testNodeTypes, "utf-8"), "test nodeType");
//Flush the changes to nodetypes
root.commit();
IndexDefinitionBuilder idxb = new IndexDefinitionBuilder().noAsync();
idxb.indexRule("oak:TestSuperType").property(JcrConstants.JCR_PRIMARYTYPE).propertyIndex();
idxb.indexRule("oak:TestMixA").property(JcrConstants.JCR_MIXINTYPES).propertyIndex();
idxb.indexRule("oak:TestMixA").property(JcrConstants.JCR_PRIMARYTYPE).propertyIndex();
Tree idx = root.getTree("/").getChild("oak:index").addChild("test1");
idxb.build(idx);
root.getTree("/oak:index/nodetype").remove();
Tree rootTree = root.getTree("/");
createNodeWithType(rootTree, "a", "oak:TestTypeA");
createNodeWithType(rootTree, "b", "oak:TestTypeB");
createNodeWithMixinType(rootTree, "c", "oak:TestMixA").setProperty(JcrConstants.JCR_PRIMARYTYPE, "oak:Unstructured", Type.NAME);
root.commit();
assertPlanAndQuery("select * from [oak:TestSuperType]", "lucene:test1(/oak:index/test1)", asList("/a", "/b"));
assertPlanAndQuery("select * from [oak:TestMixA]", "lucene:test1(/oak:index/test1)", asList("/b", "/c"));
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class LucenePropertyIndexTest method updateOldIndexDefinition.
@Test
public void updateOldIndexDefinition() throws Exception {
IndexDefinitionBuilder idxb = new IndexDefinitionBuilder().noAsync();
idxb.indexRule("nt:base").property("foo").propertyIndex();
Tree idx = root.getTree("/").getChild("oak:index").addChild("test1");
idxb.build(idx);
Tree rootTree = root.getTree("/");
rootTree.addChild("a").setProperty("foo", "bar");
rootTree.addChild("b").setProperty("bar", "bar");
root.commit();
//Cannot use Tree api as it cannot read hidden tree
String clonedDefnPath = "/oak:index/test1/" + INDEX_DEFINITION_NODE;
assertTrue(NodeStateUtils.getNode(nodeStore.getRoot(), clonedDefnPath).exists());
NodeBuilder builder = nodeStore.getRoot().builder();
child(builder, clonedDefnPath).remove();
nodeStore.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
root.rebase();
rootTree = root.getTree("/");
rootTree.addChild("c").setProperty("foo", "bar");
root.commit();
//Definition state should be recreated
assertTrue(NodeStateUtils.getNode(nodeStore.getRoot(), clonedDefnPath).exists());
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class LucenePropertyIndexTest method indexDefinitionModifiedPostReindex.
@Test
public void indexDefinitionModifiedPostReindex() throws Exception {
IndexDefinitionBuilder idxb = new IndexDefinitionBuilder().noAsync();
idxb.indexRule("nt:base").property("foo").propertyIndex();
Tree idx = root.getTree("/").getChild("oak:index").addChild("test1");
idxb.build(idx);
Tree rootTree = root.getTree("/");
rootTree.addChild("a").setProperty("foo", "bar");
rootTree.addChild("b").setProperty("bar", "bar");
root.commit();
String query = "select * from [nt:base] where [foo] = 'bar'";
assertPlanAndQuery(query, "lucene:test1(/oak:index/test1)", asList("/a"));
Tree barProp = root.getTree("/oak:index/test1/indexRules/nt:base/properties").addChild("bar");
barProp.setProperty("name", "bar");
barProp.setProperty("propertyIndex", true);
root.commit();
query = "select * from [nt:base] where [bar] = 'bar'";
assertThat(explain(query), not(containsString("lucene:test1(/oak:index/test1)")));
root.getTree("/oak:index/test1").setProperty(REINDEX_PROPERTY_NAME, true);
root.commit();
assertPlanAndQuery(query, "lucene:test1(/oak:index/test1)", asList("/b"));
}
use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.
the class LucenePropertyIndexTest method disableIndexDefnStorage.
@Test
public void disableIndexDefnStorage() throws Exception {
IndexDefinition.setDisableStoredIndexDefinition(true);
IndexDefinitionBuilder idxb = new IndexDefinitionBuilder().noAsync();
idxb.indexRule("nt:base").property("foo").propertyIndex();
Tree idx = root.getTree("/").getChild("oak:index").addChild("test1");
idxb.build(idx);
Tree rootTree = root.getTree("/");
rootTree.addChild("a").setProperty("foo", "bar");
rootTree.addChild("b").setProperty("bar", "bar");
root.commit();
String clonedDefnPath = "/oak:index/test1/" + INDEX_DEFINITION_NODE;
assertFalse(NodeStateUtils.getNode(nodeStore.getRoot(), clonedDefnPath).exists());
}
Aggregations