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);
}
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()));
}
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"));
}
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"));
}
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);
}
Aggregations