Search in sources :

Example 1 with IndexDefinitionBuilder

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

the class ElasticFullTextAsyncTest method defaultAnalyzer.

@Test
public void defaultAnalyzer() throws Exception {
    IndexDefinitionBuilder builder = createIndex("analyzed_field");
    builder.async("async");
    builder.indexRule("nt:base").property("analyzed_field").analyzed().nodeScopeIndex();
    setIndex(UUID.randomUUID().toString(), builder);
    root.commit();
    // add content
    Tree test = root.getTree("/").addChild("test");
    test.addChild("a").setProperty("analyzed_field", "sun.jpg");
    root.commit();
    assertEventually(() -> {
        assertQuery("//*[jcr:contains(@analyzed_field, 'SUN.JPG')] ", XPATH, Collections.singletonList("/test/a"));
        assertQuery("//*[jcr:contains(@analyzed_field, 'Sun')] ", XPATH, Collections.singletonList("/test/a"));
        assertQuery("//*[jcr:contains(@analyzed_field, 'jpg')] ", XPATH, Collections.singletonList("/test/a"));
        assertQuery("//*[jcr:contains(., 'SUN.jpg')] ", XPATH, Collections.singletonList("/test/a"));
        assertQuery("//*[jcr:contains(., 'sun')] ", XPATH, Collections.singletonList("/test/a"));
        assertQuery("//*[jcr:contains(., 'jpg')] ", XPATH, Collections.singletonList("/test/a"));
    });
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree) Test(org.junit.Test)

Example 2 with IndexDefinitionBuilder

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

the class ElasticContentTest method indexWithAnalyzedNodeScopeIndexProperty.

@Test
@Ignore("this test fails because of a bug with nodeScopeIndex (every node gets indexed in an empty doc)")
public void indexWithAnalyzedNodeScopeIndexProperty() throws Exception {
    IndexDefinitionBuilder builder = createIndex("a").noAsync();
    builder.indexRule("nt:base").property("a").analyzed().nodeScopeIndex();
    Tree index = setIndex(UUID.randomUUID().toString(), builder);
    root.commit();
    assertThat(0L, equalTo(countDocuments(index)));
    Tree content = root.getTree("/").addChild("content");
    content.addChild("indexed").setProperty("a", "foo");
    content.addChild("not-indexed").setProperty("b", "foo");
    root.commit();
    assertEventually(() -> assertThat(countDocuments(index), equalTo(1L)));
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with IndexDefinitionBuilder

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

the class ElasticContentTest method analyzedFieldWithLongValue.

@Test
public void analyzedFieldWithLongValue() throws Exception {
    IndexDefinitionBuilder builder = createIndex("a").noAsync();
    builder.indexRule("nt:base").property("a").analyzed();
    Tree index = setIndex(UUID.randomUUID().toString(), builder);
    root.commit();
    assertTrue(exists(index));
    assertThat(0L, equalTo(countDocuments(index)));
    Tree content = root.getTree("/").addChild("content");
    // max length is 32766
    content.addChild("indexed1").setProperty("a", randomString(33409));
    root.commit();
    assertEventually(() -> assertThat(countDocuments(index), equalTo(1L)));
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree) Test(org.junit.Test)

Example 4 with IndexDefinitionBuilder

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

the class ElasticDynamicBoostQueryTest method configureIndex.

private void configureIndex(boolean bothBoostFields) throws CommitFailedException {
    NodeTypeRegistry.register(root, new ByteArrayInputStream(ASSET_NODE_TYPE.getBytes()), "test nodeType");
    IndexDefinitionBuilder builder = createIndex(true, "dam:Asset", "title", "dynamicBoost");
    IndexDefinitionBuilder.PropertyRule title = builder.indexRule("dam:Asset").property("title").analyzed().nodeScopeIndex();
    title.getBuilderTree().setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME);
    IndexDefinitionBuilder.IndexRule assetIndexRule = builder.indexRule("dam:Asset");
    IndexDefinitionBuilder.PropertyRule dynamicBoostPropertyRule = assetIndexRule.property("dynamicBoost");
    Tree dbTree = dynamicBoostPropertyRule.getBuilderTree();
    dbTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME);
    dbTree.setProperty("name", "jcr:content/metadata/.*");
    dbTree.setProperty("isRegexp", true);
    dbTree.setProperty("dynamicBoost", true);
    if (bothBoostFields) {
        IndexDefinitionBuilder.PropertyRule newDynamicBoostPropertyRule = assetIndexRule.property("dynamicBoostNew");
        Tree anotherDbTree = newDynamicBoostPropertyRule.getBuilderTree();
        anotherDbTree.setProperty(JcrConstants.JCR_PRIMARYTYPE, NT_UNSTRUCTURED, Type.NAME);
        anotherDbTree.setProperty("name", "jcr:content/metadataNew/.*");
        anotherDbTree.setProperty("isRegexp", true);
        anotherDbTree.setProperty("dynamicBoost", true);
    }
    setIndex("damAsset_" + UUID.randomUUID(), builder);
    root.commit();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree)

Example 5 with IndexDefinitionBuilder

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

the class ElasticFullTextAsyncTest method fulltextWithModifiedNodeScopeIndex.

@Test
public void fulltextWithModifiedNodeScopeIndex() throws Exception {
    IndexDefinitionBuilder builder = createIndex("analyzed_field");
    builder.async("async");
    builder.indexRule("nt:base").property("analyzed_field").analyzed();
    Tree index = setIndex(UUID.randomUUID().toString(), builder);
    root.commit();
    // add content
    Tree test = root.getTree("/").addChild("test");
    test.addChild("a").setProperty("analyzed_field", "sun.jpg");
    root.commit();
    assertEventually(() -> assertQuery("//*[jcr:contains(@analyzed_field, 'SUN.JPG')] ", XPATH, Collections.singletonList("/test/a")));
    // add nodeScopeIndex at a later stage
    index.getChild("indexRules").getChild("nt:base").getChild("properties").getChild("analyzed_field").setProperty(FulltextIndexConstants.PROP_NODE_SCOPE_INDEX, true);
    root.commit();
    assertEventually(() -> assertQuery("//*[jcr:contains(., 'jpg')] ", XPATH, Collections.singletonList("/test/a")));
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree) Test(org.junit.Test)

Aggregations

IndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder)91 Test (org.junit.Test)83 Tree (org.apache.jackrabbit.oak.api.Tree)60 LuceneIndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder)32 AbstractQueryTest (org.apache.jackrabbit.oak.query.AbstractQueryTest)32 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)18 IndexHelper.newFTIndexDefinition (org.apache.jackrabbit.oak.plugins.index.search.util.IndexHelper.newFTIndexDefinition)13 IndexHelper.newFTPropertyIndexDefinition (org.apache.jackrabbit.oak.plugins.index.search.util.IndexHelper.newFTPropertyIndexDefinition)13 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)10 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)8 File (java.io.File)7 FileInputStream (java.io.FileInputStream)7 URI (java.net.URI)7 Random (java.util.Random)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 LinkedList (java.util.LinkedList)6 ElasticIndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder)6 IndexingRule (org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition.IndexingRule)6 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)6 Blob (org.apache.jackrabbit.oak.api.Blob)5