Skip to content
Permalink
Browse files
Merge pull request #534 from apache/OAK-9743-b
OAK-9743 oak-run indexing doesn't support facets
  • Loading branch information
thomasmueller committed Apr 1, 2022
2 parents f23fe7f + e6edaa4 commit 2ca74a89b0051494cdc83eb12d514757ee66fe1f
Showing 2 changed files with 43 additions and 4 deletions.
@@ -26,20 +26,23 @@
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneDocumentMaker;
import org.apache.jackrabbit.oak.plugins.index.lucene.util.FacetHelper;
import org.apache.jackrabbit.oak.plugins.index.lucene.util.FacetsConfigProvider;
import org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter;
import org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter;
import org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition;
import org.apache.jackrabbit.oak.plugins.index.search.spi.binary.FulltextBinaryTextExtractor;
import org.apache.jackrabbit.oak.spi.filter.PathFilter;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.lucene.document.Document;
import org.apache.lucene.facet.FacetsConfig;

public class LuceneIndexer implements NodeStateIndexer {
public class LuceneIndexer implements NodeStateIndexer, FacetsConfigProvider {
private final IndexDefinition definition;
private final FulltextBinaryTextExtractor binaryTextExtractor;
private final NodeBuilder definitionBuilder;
private final LuceneIndexWriter indexWriter;
private final IndexingProgressReporter progressReporter;
private FacetsConfig facetsConfig;

public LuceneIndexer(IndexDefinition definition, LuceneIndexWriter indexWriter,
NodeBuilder builder, FulltextBinaryTextExtractor binaryTextExtractor,
@@ -111,11 +114,22 @@ private void writeToIndex(Document doc, String path) throws IOException {
private LuceneDocumentMaker newDocumentMaker(IndexDefinition.IndexingRule indexingRule, String path) {
return new LuceneDocumentMaker(
binaryTextExtractor,
() -> FacetHelper.getFacetsConfig(definitionBuilder), //TODO FacetsConfig handling
null, //TODO augmentorFactory
// we re-use the facet config
this,
// augmentorFactory is not supported (it is deprecated)
null,
definition,
indexingRule,
path
);
}

@Override
public FacetsConfig getFacetsConfig() {
if (facetsConfig == null) {
facetsConfig = FacetHelper.getFacetsConfig(definitionBuilder);
}
return facetsConfig;
}

}
@@ -19,13 +19,15 @@

package org.apache.jackrabbit.oak.index.indexer.document;

import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneDocumentMaker;
import org.apache.jackrabbit.oak.plugins.index.lucene.util.LuceneIndexDefinitionBuilder;
import org.apache.jackrabbit.oak.plugins.index.lucene.writer.LuceneIndexWriter;
import org.apache.jackrabbit.oak.plugins.index.progress.IndexingProgressReporter;
import org.apache.jackrabbit.oak.plugins.index.search.IndexDefinition;
import org.apache.jackrabbit.oak.plugins.index.search.spi.binary.FulltextBinaryTextExtractor;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeState;
import org.apache.lucene.facet.FacetsConfig;
import org.junit.Test;

import static org.apache.jackrabbit.oak.InitialContentHelper.INITIAL_CONTENT;
@@ -37,7 +39,7 @@ public class LuceneIndexerTest {
private NodeState root = INITIAL_CONTENT;

@Test
public void nodeIndexed_WithIncludedPaths() throws Exception{
public void nodeIndexed_WithIncludedPaths() throws Exception {
LuceneIndexDefinitionBuilder idxb = new LuceneIndexDefinitionBuilder();
idxb.indexRule("nt:base").property("foo").propertyIndex();
idxb.includedPaths("/content");
@@ -54,6 +56,29 @@ public void nodeIndexed_WithIncludedPaths() throws Exception{
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()));

indexer.close();
}

@Test
public void facetConfig() throws Exception {
LuceneIndexDefinitionBuilder idxb = new LuceneIndexDefinitionBuilder();
idxb.indexRule("nt:base").property("foo").propertyIndex().facets();
idxb.includedPaths("/content");

NodeState defn = idxb.build();
IndexDefinition idxDefn = new IndexDefinition(root, defn, "/oak:index/testIndex");

NodeBuilder builder = root.builder();
LuceneIndexer indexer = new LuceneIndexer(idxDefn, mock(LuceneIndexWriter.class), builder,
mock(FulltextBinaryTextExtractor.class), mock(IndexingProgressReporter.class));

FacetsConfig config1 = indexer.getFacetsConfig();
FacetsConfig config2 = indexer.getFacetsConfig();
assertTrue(config1 == config2);

indexer.close();
}


}

0 comments on commit 2ca74a8

Please sign in to comment.