Search in sources :

Example 1 with ElasticIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class ElasticIndexerTest method nodeIndexed_WithIncludedPaths.

@Test
public void nodeIndexed_WithIncludedPaths() throws Exception {
    ElasticIndexDefinitionBuilder idxb = new ElasticIndexDefinitionBuilder();
    idxb.indexRule("nt:base").property("foo").propertyIndex();
    idxb.includedPaths("/content");
    NodeState defn = idxb.build();
    IndexDefinition idxDefn = new ElasticIndexDefinition(root, defn, "/oak:index/testIndex", "testPrefix");
    NodeBuilder builder = root.builder();
    FulltextIndexWriter indexWriter = new ElasticIndexWriterFactory(mock(ElasticConnection.class), mock(ElasticIndexTracker.class)).newInstance(idxDefn, defn.builder(), CommitInfo.EMPTY, false);
    ElasticIndexer indexer = new ElasticIndexer(idxDefn, mock(FulltextBinaryTextExtractor.class), builder, mock(IndexingProgressReporter.class), indexWriter, mock(ElasticIndexEditorProvider.class), mock(IndexHelper.class));
    NodeState testNode = EMPTY_NODE.builder().setProperty("foo", "bar").getNodeState();
    assertTrue(indexer.index(new NodeStateEntry.NodeStateEntryBuilder(testNode, "/content/x").build()));
    assertFalse(indexer.index(new NodeStateEntry.NodeStateEntryBuilder(testNode, "/x").build()));
    assertFalse(indexer.index(new NodeStateEntry.NodeStateEntryBuilder(testNode, "/").build()));
}
Also used : ElasticIndexWriterFactory(org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexWriterFactory) IndexHelper(org.apache.jackrabbit.oak.index.IndexHelper) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) FulltextBinaryTextExtractor(org.apache.jackrabbit.oak.plugins.index.search.spi.binary.FulltextBinaryTextExtractor) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) ElasticIndexDefinition(org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition) FulltextIndexWriter(org.apache.jackrabbit.oak.plugins.index.search.spi.editor.FulltextIndexWriter) IndexingProgressReporter(org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter) ElasticIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexEditorProvider) ElasticIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder) ElasticIndexDefinition(org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition) Test(org.junit.Test)

Example 2 with ElasticIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class ElasticReindexTest method reindex.

@Test
public void reindex() throws Exception {
    IndexDefinitionBuilder indexDefinitionBuilder = new ElasticIndexDefinitionBuilder();
    indexDefinitionBuilder.noAsync();
    IndexDefinitionBuilder.IndexRule indexRule = indexDefinitionBuilder.indexRule("nt:base");
    indexRule.property("a").propertyIndex().analyzed();
    String indexName = UUID.randomUUID().toString();
    indexDefinitionBuilder.build(adminSession.getRootNode().getNode(INDEX_DEFINITIONS_NAME).addNode(indexName, INDEX_DEFINITIONS_NODE_TYPE));
    adminSession.save();
    Node content = adminSession.getRootNode().addNode("content");
    for (int i = 0; i < 100; i++) {
        Node c = content.addNode("c_" + i);
        c.setProperty("a", "foo");
        c.setProperty("b", "bar");
    }
    adminSession.save();
    assertQuery("select [jcr:path] from [nt:base] where contains(a, 'foo')", 100);
    // adding an extra content node (handled by reindex and potentially incremental indexing)
    Node c = content.addNode("c_100");
    c.setProperty("a", "foo");
    c.setProperty("b", "bar");
    Node indexNode = adminSession.getRootNode().getNode(INDEX_DEFINITIONS_NAME).getNode(indexName);
    Node b = indexNode.getNode("indexRules").getNode("nt:base").getNode("properties").addNode("b");
    b.setProperty(FulltextIndexConstants.PROP_PROPERTY_INDEX, true);
    b.setProperty(FulltextIndexConstants.PROP_ANALYZED, true);
    // Now we reindex and see everything works fine
    indexNode.setProperty(REINDEX_PROPERTY_NAME, true);
    adminSession.save();
    assertQuery("select [jcr:path] from [nt:base] where contains(b, 'bar')", 101);
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder) ElasticIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder) Node(javax.jcr.Node) ElasticIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder) Test(org.junit.Test)

Example 3 with ElasticIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class ElasticIndexHelperTest method oakAnalyzerWithOriginalTerm.

@Test
public void oakAnalyzerWithOriginalTerm() throws IOException {
    IndexDefinitionBuilder builder = new ElasticIndexDefinitionBuilder();
    IndexDefinitionBuilder.IndexRule indexRule = builder.indexRule("type");
    indexRule.property("foo").type("String").analyzed();
    Tree analyzer = builder.getBuilderTree().addChild("analyzers");
    analyzer.setProperty("indexOriginalTerm", "true");
    NodeState nodeState = builder.build();
    ElasticIndexDefinition definition = new ElasticIndexDefinition(nodeState, nodeState, "path", "prefix");
    CreateIndexRequest request = ElasticIndexHelper.createIndexRequest("prefix.path", definition);
    assertThat(request.settings().get("analysis.filter.oak_word_delimiter_graph_filter.preserve_original"), is("true"));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder) ElasticIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder) Tree(org.apache.jackrabbit.oak.api.Tree) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) ElasticIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder) ElasticIndexDefinition(org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition) Test(org.junit.Test)

Example 4 with ElasticIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class ElasticAbstractQueryTest method createIndex.

protected IndexDefinitionBuilder createIndex(boolean isPropertyIndex, String nodeType, String... propNames) {
    IndexDefinitionBuilder builder = new ElasticIndexDefinitionBuilder();
    if (!useAsyncIndexing()) {
        builder = builder.noAsync();
    }
    IndexDefinitionBuilder.IndexRule indexRule = builder.indexRule(nodeType);
    if (isPropertyIndex) {
        for (String propName : propNames) {
            indexRule.property(propName).propertyIndex();
        }
    }
    return builder;
}
Also used : IndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder) ElasticIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder) ElasticIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder)

Example 5 with ElasticIndexDefinitionBuilder

use of org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder in project jackrabbit-oak by apache.

the class ElasticDocumentMakerLargeStringPropertiesLogTest method addPropertyAccordingToType.

private ElasticDocumentMaker addPropertyAccordingToType(NodeBuilder test, Type type, String... str) throws IOException {
    NodeState root = INITIAL_CONTENT;
    ElasticIndexDefinitionBuilder builder = new ElasticIndexDefinitionBuilder();
    builder.indexRule("nt:base").property("foo").propertyIndex().analyzed().valueExcludedPrefixes("/jobs");
    IndexDefinition defn = ElasticIndexDefinition.newBuilder(root, builder.build(), "/foo").build();
    ElasticDocumentMaker docMaker = new ElasticDocumentMaker(null, defn, defn.getApplicableIndexingRule("nt:base"), "/x");
    if (Type.STRINGS == type) {
        test.setProperty("foo", asList(str), Type.STRINGS);
    } else if (Type.STRING == type && str.length == 1) {
        test.setProperty("foo", str[0]);
    } else {
        throw new InvalidParameterException();
    }
    return docMaker;
}
Also used : InvalidParameterException(java.security.InvalidParameterException) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) IndexDefinition(org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition) ElasticIndexDefinition(org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition) ElasticIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder)

Aggregations

ElasticIndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder)8 ElasticIndexDefinition (org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition)6 IndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder)6 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)6 Test (org.junit.Test)6 CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Map (java.util.Map)2 IndexDefinition (org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition)2 InvalidParameterException (java.security.InvalidParameterException)1 Node (javax.jcr.Node)1 Tree (org.apache.jackrabbit.oak.api.Tree)1 IndexHelper (org.apache.jackrabbit.oak.index.IndexHelper)1 ElasticIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexEditorProvider)1 ElasticIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexWriterFactory)1 IndexingProgressReporter (org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter)1 FulltextBinaryTextExtractor (org.apache.jackrabbit.oak.plugins.index.search.spi.binary.FulltextBinaryTextExtractor)1 FulltextIndexWriter (org.apache.jackrabbit.oak.plugins.index.search.spi.editor.FulltextIndexWriter)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1