Skip to content

Commit

Permalink
HSEARCH-3892 Move away from FacetConfig/SortedSetDocValuesFacetCounts…
Browse files Browse the repository at this point in the history
… for text doc values used in aggregations

1. SortedSetDocValuesFacetCounts does not support nested documents
2. SortedSetDocValuesFacetCounts depends heavily on how FacetConfig
   organizes doc values, with some dependencies on internal code.
3. FacetConfig is able to do much more than what we need, and is very
   complicated. So we don't want to copy that.

Thus I copied SortedSetDocValuesFacetCounts to our project as
TextMultiValueFacetCounts, and removed the FacetConfig parts.

I'll adapt the code to support nested documents it in the next few commits.
  • Loading branch information
yrodiere committed Apr 15, 2020
1 parent 0318871 commit e253a60
Show file tree
Hide file tree
Showing 17 changed files with 268 additions and 143 deletions.
Expand Up @@ -9,25 +9,20 @@
import org.hibernate.search.backend.lucene.multitenancy.impl.MultiTenancyStrategy;
import org.hibernate.search.engine.backend.work.execution.spi.DocumentContributor;

import org.apache.lucene.facet.FacetsConfig;

public class LuceneIndexEntryFactory {

private final MultiTenancyStrategy multiTenancyStrategy;
private final String indexName;
private final FacetsConfig facetsConfig;

public LuceneIndexEntryFactory(MultiTenancyStrategy multiTenancyStrategy, String indexName,
FacetsConfig facetsConfig) {
public LuceneIndexEntryFactory(MultiTenancyStrategy multiTenancyStrategy, String indexName) {
this.indexName = indexName;
this.multiTenancyStrategy = multiTenancyStrategy;
this.facetsConfig = facetsConfig;
}

public LuceneIndexEntry create(String tenantId, String id, String routingKey,
DocumentContributor documentContributor) {
LuceneRootDocumentBuilder builder = new LuceneRootDocumentBuilder(
multiTenancyStrategy, indexName, facetsConfig
multiTenancyStrategy, indexName
);
documentContributor.contribute( builder );
return builder.build( tenantId, id, routingKey );
Expand Down
Expand Up @@ -6,35 +6,25 @@
*/
package org.hibernate.search.backend.lucene.document.impl;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;

import org.apache.lucene.document.Document;
import org.apache.lucene.facet.FacetsConfig;

import org.hibernate.search.backend.lucene.logging.impl.Log;
import org.hibernate.search.backend.lucene.lowlevel.common.impl.MetadataFields;
import org.hibernate.search.backend.lucene.document.model.impl.LuceneIndexSchemaObjectNode;
import org.hibernate.search.backend.lucene.multitenancy.impl.MultiTenancyStrategy;
import org.hibernate.search.util.common.logging.impl.LoggerFactory;


public class LuceneRootDocumentBuilder extends AbstractLuceneNonFlattenedDocumentBuilder {

private static final Log log = LoggerFactory.make( Log.class, MethodHandles.lookup() );

private final MultiTenancyStrategy multiTenancyStrategy;
private final String indexName;
private final FacetsConfig facetsConfig;

LuceneRootDocumentBuilder(MultiTenancyStrategy multiTenancyStrategy, String indexName,
FacetsConfig facetsConfig) {
LuceneRootDocumentBuilder(MultiTenancyStrategy multiTenancyStrategy, String indexName) {
super( LuceneIndexSchemaObjectNode.root() );
this.multiTenancyStrategy = multiTenancyStrategy;
this.indexName = indexName;
this.facetsConfig = facetsConfig;
}

public LuceneIndexEntry build(String tenantId, String id, String routingKey) {
Expand All @@ -55,19 +45,6 @@ private List<Document> assembleDocuments(MultiTenancyStrategy multiTenancyStrate

documents.add( document );

if ( facetsConfig != null ) {
for ( int i = 0; i < documents.size(); i++ ) {
Document document = documents.get( i );
try {
Document facetedDocument = facetsConfig.build( document );
documents.set( i, facetedDocument );
}
catch (IOException | RuntimeException e) {
throw log.errorDuringFacetingIndexing( e );
}
}
}

return documents;
}
}
Expand Up @@ -10,7 +10,6 @@
import java.util.Map;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.facet.FacetsConfig;

import org.hibernate.search.backend.lucene.analysis.model.impl.LuceneAnalysisDefinitionRegistry;
import org.hibernate.search.backend.lucene.document.model.impl.LuceneIndexModel;
Expand Down Expand Up @@ -73,7 +72,6 @@ public LuceneIndexModel build(String indexName) {
Map<String, LuceneIndexSchemaObjectNode> objectNodesBuilder = new HashMap<>();
Map<String, LuceneIndexSchemaFieldNode<?>> fieldNodesBuilder = new HashMap<>();
ScopedAnalyzer.Builder scopedAnalyzerBuilder = new ScopedAnalyzer.Builder();
FacetsConfig facetsConfig = new FacetsConfig();

LuceneIndexSchemaNodeCollector collector = new LuceneIndexSchemaNodeCollector() {
@Override
Expand All @@ -90,11 +88,6 @@ public void collectFieldNode(String absoluteFieldPath, LuceneIndexSchemaFieldNod
public void collectObjectNode(String absolutePath, LuceneIndexSchemaObjectNode node) {
objectNodesBuilder.put( absolutePath, node );
}

@Override
public void collectFacetConfig(String absoluteFieldPath, boolean multiValued) {
facetsConfig.setMultiValued( absoluteFieldPath, multiValued );
}
};

LuceneIndexSchemaObjectNode rootNode = LuceneIndexSchemaObjectNode.root();
Expand All @@ -106,8 +99,7 @@ public void collectFacetConfig(String absoluteFieldPath, boolean multiValued) {
idDslConverter == null ? new StringToDocumentIdentifierValueConverter() : idDslConverter,
objectNodesBuilder,
fieldNodesBuilder,
scopedAnalyzerBuilder.build(),
facetsConfig.getDimConfigs().isEmpty() ? null : facetsConfig
scopedAnalyzerBuilder.build()
);
}

Expand Down
Expand Up @@ -14,8 +14,6 @@
import org.hibernate.search.engine.reporting.spi.EventContexts;
import org.hibernate.search.util.common.impl.CollectionHelper;

import org.apache.lucene.facet.FacetsConfig;


public class LuceneIndexModel implements AutoCloseable {

Expand All @@ -31,22 +29,18 @@ public class LuceneIndexModel implements AutoCloseable {

private final ScopedAnalyzer scopedAnalyzer;

private final FacetsConfig facetsConfig;

public LuceneIndexModel(String indexName,
String mappedTypeName,
ToDocumentIdentifierValueConverter<?> idDslConverter,
Map<String, LuceneIndexSchemaObjectNode> objectNodesBuilder,
Map<String, LuceneIndexSchemaFieldNode<?>> fieldNodesBuilder,
ScopedAnalyzer scopedAnalyzer,
FacetsConfig facetsConfig) {
ScopedAnalyzer scopedAnalyzer) {
this.indexName = indexName;
this.mappedTypeName = mappedTypeName;
this.idDslConverter = idDslConverter;
this.fieldNodes = CollectionHelper.toImmutableMap( fieldNodesBuilder );
this.objectNodes = CollectionHelper.toImmutableMap( objectNodesBuilder );
this.scopedAnalyzer = scopedAnalyzer;
this.facetsConfig = facetsConfig;
}

@Override
Expand Down Expand Up @@ -82,10 +76,6 @@ public ScopedAnalyzer getScopedAnalyzer() {
return scopedAnalyzer;
}

public FacetsConfig getFacetsConfig() {
return facetsConfig;
}

@Override
public String toString() {
return new StringBuilder( getClass().getSimpleName() )
Expand Down
Expand Up @@ -15,7 +15,5 @@ public interface LuceneIndexSchemaNodeCollector {

void collectFieldNode(String absoluteFieldPath, LuceneIndexSchemaFieldNode<?> schemaFieldNode);

void collectFacetConfig(String absoluteFieldPath, boolean multiValued);

void collectAnalyzer(String absoluteFieldPath, Analyzer analyzer);
}
Expand Up @@ -55,8 +55,6 @@
import org.hibernate.search.util.common.impl.SuppressingCloser;
import org.hibernate.search.util.common.reporting.EventContext;

import org.apache.lucene.facet.FacetsConfig;

public class IndexManagerBackendContext implements WorkExecutionBackendContext, SearchBackendContext {

private static final ConfigurationProperty<IOStrategyName> IO_STRATEGY =
Expand Down Expand Up @@ -175,8 +173,8 @@ EventContext getEventContext() {
return eventContext;
}

LuceneIndexEntryFactory createLuceneIndexEntryFactory(String indexName, FacetsConfig facetsConfig) {
return new LuceneIndexEntryFactory( multiTenancyStrategy, indexName, facetsConfig );
LuceneIndexEntryFactory createLuceneIndexEntryFactory(String indexName) {
return new LuceneIndexEntryFactory( multiTenancyStrategy, indexName );
}

IOStrategy createIOStrategy(ConfigurationPropertySource propertySource) {
Expand Down
Expand Up @@ -44,9 +44,7 @@ public LuceneIndexManagerImpl build() {
LuceneIndexModel model = null;
try {
model = schemaRootNodeBuilder.build( indexName );
LuceneIndexEntryFactory indexEntryFactory = backendContext.createLuceneIndexEntryFactory(
indexName, model.getFacetsConfig()
);
LuceneIndexEntryFactory indexEntryFactory = backendContext.createLuceneIndexEntryFactory( indexName );
return new LuceneIndexManagerImpl(
backendContext, indexName, model, indexEntryFactory
);
Expand Down
Expand Up @@ -128,10 +128,6 @@ public interface Log extends BasicLogger {
value = "Value '%1$ss' is not in a valid format to express a Lucene version: %2$s" )
SearchException illegalLuceneVersionFormat(String property, String luceneErrorMessage, @Cause Exception e);

@Message(id = ID_OFFSET_1 + 265,
value = "Unable to build Lucene Document due to facet indexing error")
SearchException errorDuringFacetingIndexing(@Cause Exception e );

@LogMessage(level = Level.DEBUG)
@Message(id = ID_OFFSET_1 + 274, value = "Executing Lucene query '%s'" )
void executingLuceneQuery(Query luceneQuery);
Expand Down

0 comments on commit e253a60

Please sign in to comment.