Search in sources :

Example 1 with IndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.

the class LuceneIndexInfoProviderTest method info.

@Test
public void info() throws Exception {
    IndexDefinitionBuilder defnBuilder = new IndexDefinitionBuilder();
    NodeBuilder builder = store.getRoot().builder();
    builder.child("oak:index").setChildNode("fooIndex", defnBuilder.build());
    store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    when(asyncService.getInfo("async")).thenReturn(new AsyncIndexInfo("async", 0, 0, false, null));
    IndexInfo info = provider.getInfo("/oak:index/fooIndex");
    assertNotNull(info);
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder) IndexInfo(org.apache.jackrabbit.oak.plugins.index.IndexInfo) AsyncIndexInfo(org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfo) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) AsyncIndexInfo(org.apache.jackrabbit.oak.plugins.index.AsyncIndexInfo) Test(org.junit.Test)

Example 2 with IndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.

the class HybridIndexTest method createIndex.

private static Tree createIndex(Tree index, String name, Set<String> propNames) {
    IndexDefinitionBuilder idx = new IndexDefinitionBuilder();
    IndexRule rule = idx.indexRule("nt:base");
    for (String propName : propNames) {
        rule.property(propName).propertyIndex();
    }
    Tree idxTree = index.getChild("oak:index").addChild(name);
    idx.build(idxTree);
    return idxTree;
}
Also used : IndexRule(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder.IndexRule) IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 3 with IndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.

the class HybridIndexTest method createFulltextIndex.

private static Tree createFulltextIndex(Tree index, String name) {
    IndexDefinitionBuilder idx = new IndexDefinitionBuilder();
    idx.evaluatePathRestrictions();
    idx.indexRule("nt:base").property(LuceneIndexConstants.REGEX_ALL_PROPS, true).analyzed().nodeScopeIndex().useInExcerpt();
    Tree idxTree = index.getChild("oak:index").addChild(name);
    idx.build(idxTree);
    return idxTree;
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree)

Example 4 with IndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.

the class HybridIndexTest method newNodeTypesFoundLater2.

@Test
public void newNodeTypesFoundLater2() throws Exception {
    String idxName = "hybridtest";
    IndexDefinitionBuilder idx = new IndexDefinitionBuilder();
    idx.indexRule("oak:TestNode").property(JcrConstants.JCR_PRIMARYTYPE).propertyIndex();
    idx.indexRule("nt:base").property("foo").propertyIndex().property("bar").propertyIndex();
    idx.async("async", "sync");
    idx.build(root.getTree("/").getChild("oak:index").addChild(idxName));
    //By default nodetype index indexes every nodetype. Declare a specific list
    //such that it does not indexes test nodetype
    Tree nodeType = root.getTree("/oak:index/nodetype");
    if (!nodeType.hasProperty(IndexConstants.DECLARING_NODE_TYPES)) {
        nodeType.setProperty(IndexConstants.DECLARING_NODE_TYPES, ImmutableList.of("nt:file"), Type.NAMES);
        nodeType.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true);
    }
    root.commit();
    setTraversalEnabled(false);
    createPath("/a").setProperty("foo", "bar");
    root.commit();
    assertQuery("select [jcr:path] from [nt:base] where [foo] = 'bar'", of("/a"));
    optionalEditorProvider.delegate = new TypeEditorProvider(false);
    NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType");
    root.refresh();
    Tree b = createPath("/b");
    b.setProperty(JcrConstants.JCR_PRIMARYTYPE, "oak:TestNode", Type.NAME);
    b.setProperty("bar", "foo");
    Tree c = createPath("/c");
    c.setProperty(JcrConstants.JCR_PRIMARYTYPE, "oak:TestNode", Type.NAME);
    root.commit();
    String query = "select [jcr:path] from [oak:TestNode] ";
    assertThat(explain(query), containsString("/oak:index/hybridtest"));
    assertQuery(query, of("/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 5 with IndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder in project jackrabbit-oak by apache.

the class LocalIndexWriterFactoryTest method createIndexDefinition.

private void createIndexDefinition(String idxName, IndexingMode indexingMode) {
    IndexDefinitionBuilder idx = new IndexDefinitionBuilder();
    TestUtil.enableIndexingMode(idx.getBuilderTree(), indexingMode);
    idx.indexRule("nt:base").property("foo").propertyIndex();
    builder.child("oak:index").setChildNode(idxName, idx.build());
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.lucene.util.IndexDefinitionBuilder)

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