Search in sources :

Example 6 with IndexDefinitionBuilder

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());
}
Also used : AsyncIndexInfoService(org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService) IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree) IndexInfo(org.apache.jackrabbit.oak.plugins.index.IndexInfo) AsyncIndexInfoServiceImpl(org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoServiceImpl) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Example 7 with IndexDefinitionBuilder

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"));
}
Also used : TypeEditorProvider(org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider) IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Example 8 with IndexDefinitionBuilder

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());
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Example 9 with IndexDefinitionBuilder

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"));
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Example 10 with IndexDefinitionBuilder

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());
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test) AbstractQueryTest(org.apache.jackrabbit.oak.query.AbstractQueryTest)

Aggregations

IndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder)16 Tree (org.apache.jackrabbit.oak.api.Tree)9 Test (org.junit.Test)9 AbstractQueryTest (org.apache.jackrabbit.oak.query.AbstractQueryTest)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)7 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)3 Node (javax.jcr.Node)2 IndexInfo (org.apache.jackrabbit.oak.plugins.index.IndexInfo)2 TypeEditorProvider (org.apache.jackrabbit.oak.plugins.nodetype.TypeEditorProvider)2 Session (javax.jcr.Session)1 AsyncIndexInfo (org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfo)1 AsyncIndexInfoService (org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoService)1 AsyncIndexInfoServiceImpl (org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfoServiceImpl)1 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.lucene.IndexDefinition)1 IndexRule (org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder.IndexRule)1 DefaultIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.lucene.writer.DefaultIndexWriterFactory)1 LuceneIndexWriter (org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter)1 NodeStateUtils.getNode (org.apache.jackrabbit.oak.spi.state.NodeStateUtils.getNode)1 Document (org.apache.lucene.document.Document)1