Search in sources :

Example 1 with ElasticIndexDefinition

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

the class ElasticIndexerProvider method getIndexer.

@Override
@Nullable
public NodeStateIndexer getIndexer(@NotNull String type, @NotNull String indexPath, @NotNull NodeBuilder definition, @NotNull NodeState root, IndexingProgressReporter progressReporter) {
    if (!ElasticIndexDefinition.TYPE_ELASTICSEARCH.equals(definition.getString(TYPE_PROPERTY_NAME))) {
        return null;
    }
    ElasticIndexDefinition idxDefinition = (ElasticIndexDefinition) new ElasticIndexDefinition.Builder(connection.getIndexPrefix()).root(root).indexPath(indexPath).defn(definition.getNodeState()).reindex().build();
    FulltextIndexWriter<ElasticDocument> indexWriter = indexWriterFactory.newInstance(idxDefinition, definition, CommitInfo.EMPTY, true);
    FulltextBinaryTextExtractor textExtractor = new FulltextBinaryTextExtractor(textCache, idxDefinition, true);
    ElasticIndexTracker indexTracker = new ElasticIndexTracker(connection, new ElasticMetricHandler(StatisticsProvider.NOOP));
    ElasticIndexEditorProvider elasticIndexEditorProvider = new ElasticIndexEditorProvider(indexTracker, connection, null);
    return new ElasticIndexer(idxDefinition, textExtractor, definition, progressReporter, indexWriter, elasticIndexEditorProvider, indexHelper);
}
Also used : FulltextBinaryTextExtractor(org.apache.jackrabbit.oak.plugins.index.search.spi.binary.FulltextBinaryTextExtractor) ElasticDocument(org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticDocument) ElasticIndexTracker(org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexTracker) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) ElasticMetricHandler(org.apache.jackrabbit.oak.plugins.index.elastic.ElasticMetricHandler) ElasticIndexEditorProvider(org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexEditorProvider) ElasticIndexDefinition(org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ElasticIndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition 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 3 with ElasticIndexDefinition

use of org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition 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 ElasticIndexDefinition

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

the class ElasticIndexHelperTest method multiRulesWithSamePropertyNames.

@Test
public void multiRulesWithSamePropertyNames() throws IOException {
    IndexDefinitionBuilder builder = new ElasticIndexDefinitionBuilder();
    IndexDefinitionBuilder.IndexRule indexRuleA = builder.indexRule("typeA");
    indexRuleA.property("foo").type("String");
    IndexDefinitionBuilder.IndexRule indexRuleB = builder.indexRule("typeB");
    indexRuleB.property("foo").type("String").analyzed();
    NodeState nodeState = builder.build();
    ElasticIndexDefinition definition = new ElasticIndexDefinition(nodeState, nodeState, "path", "prefix");
    CreateIndexRequest request = ElasticIndexHelper.createIndexRequest("prefix.path", definition);
    ObjectMapper mapper = new ObjectMapper();
    Map<String, Object> jsonMap = mapper.readValue(request.mappings().streamInput(), Map.class);
    Map fooMapping = (Map) ((Map) jsonMap.get("properties")).get("foo");
    assertThat(fooMapping.get("type"), is("text"));
    Map fooKeywordMapping = (Map) ((Map) fooMapping.get("fields")).get("keyword");
    assertThat(fooKeywordMapping.get("type"), is("keyword"));
}
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) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) Map(java.util.Map) ElasticIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ElasticIndexDefinition(org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition) Test(org.junit.Test)

Example 5 with ElasticIndexDefinition

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

the class ElasticIndexHelperTest method multiRulesWithSamePropertyNamesDifferentTypes.

@Test(expected = IllegalStateException.class)
public void multiRulesWithSamePropertyNamesDifferentTypes() throws IOException {
    IndexDefinitionBuilder builder = new ElasticIndexDefinitionBuilder();
    IndexDefinitionBuilder.IndexRule indexRuleA = builder.indexRule("typeA");
    indexRuleA.property("foo").type("String");
    IndexDefinitionBuilder.IndexRule indexRuleB = builder.indexRule("typeB");
    indexRuleB.property("foo").type("Boolean");
    NodeState nodeState = builder.build();
    ElasticIndexDefinition definition = new ElasticIndexDefinition(nodeState, nodeState, "path", "prefix");
    ElasticIndexHelper.createIndexRequest("prefix.path", definition);
}
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) ElasticIndexDefinitionBuilder(org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder) ElasticIndexDefinition(org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition) Test(org.junit.Test)

Aggregations

ElasticIndexDefinition (org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexDefinition)7 ElasticIndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.elastic.util.ElasticIndexDefinitionBuilder)5 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)5 Test (org.junit.Test)5 IndexDefinitionBuilder (org.apache.jackrabbit.oak.plugins.index.search.util.IndexDefinitionBuilder)4 CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Map (java.util.Map)2 ElasticIndexEditorProvider (org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexEditorProvider)2 FulltextBinaryTextExtractor (org.apache.jackrabbit.oak.plugins.index.search.spi.binary.FulltextBinaryTextExtractor)2 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)2 Nullable (org.jetbrains.annotations.Nullable)2 Tree (org.apache.jackrabbit.oak.api.Tree)1 IndexHelper (org.apache.jackrabbit.oak.index.IndexHelper)1 ContextAwareCallback (org.apache.jackrabbit.oak.plugins.index.ContextAwareCallback)1 IndexingContext (org.apache.jackrabbit.oak.plugins.index.IndexingContext)1 ElasticIndexTracker (org.apache.jackrabbit.oak.plugins.index.elastic.ElasticIndexTracker)1 ElasticMetricHandler (org.apache.jackrabbit.oak.plugins.index.elastic.ElasticMetricHandler)1 ElasticDocument (org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticDocument)1 ElasticIndexWriterFactory (org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexWriterFactory)1