Skip to content

Commit

Permalink
Remove workaround to configure completion postings load mode (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
aprudhomme authored Jan 6, 2025
1 parent 8ead293 commit 9a1613a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ContextSuggestFieldDef extends IndexableFieldDef<Void> {
private static final Gson GSON = new GsonBuilder().serializeNulls().create();
private final Analyzer indexAnalyzer;
private final Analyzer searchAnalyzer;
private final PostingsFormat postingsFormat;

/**
* @param name name of field
Expand All @@ -43,6 +44,8 @@ protected ContextSuggestFieldDef(
super(name, requestField, context, Void.class);
this.indexAnalyzer = this.parseIndexAnalyzer(requestField);
this.searchAnalyzer = this.parseSearchAnalyzer(requestField);
this.postingsFormat =
new Completion912PostingsFormat(context.config().getCompletionCodecLoadMode());
}

@Override
Expand Down Expand Up @@ -117,6 +120,6 @@ public Optional<Analyzer> getSearchAnalyzer() {

@Override
public PostingsFormat getPostingsFormat() {
return new Completion912PostingsFormat();
return postingsFormat;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
import java.util.concurrent.TimeUnit;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.QueryCache;
import org.apache.lucene.search.suggest.document.CompletionPostingsFormatUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import picocli.CommandLine;
Expand Down Expand Up @@ -371,8 +370,6 @@ static class LuceneServerImpl extends LuceneServerGrpc.LuceneServerImplBase {
throws IOException {

DeadlineUtils.setCancellationEnabled(configuration.getDeadlineCancellation());
CompletionPostingsFormatUtil.setCompletionCodecLoadMode(
configuration.getCompletionCodecLoadMode());
ExecutorFactory.init(configuration.getThreadPoolConfiguration());

initQueryCache(configuration);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import com.yelp.nrtsearch.server.ServerTestCase;
import com.yelp.nrtsearch.server.config.NrtsearchConfig;
import com.yelp.nrtsearch.server.grpc.Analyzer;
import com.yelp.nrtsearch.server.grpc.CompletionQuery;
import com.yelp.nrtsearch.server.grpc.Field;
Expand All @@ -30,6 +32,7 @@
import com.yelp.nrtsearch.server.grpc.SearchRequest;
import com.yelp.nrtsearch.server.grpc.SearchResponse;
import io.grpc.testing.GrpcCleanupRule;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -71,8 +74,7 @@ public void validSearchAndIndexAnalyzerWhenFieldAnalyzerIsProvided() {
.setAnalyzer(analyzer)
.build();
ContextSuggestFieldDef contextSuggestFieldDef =
new ContextSuggestFieldDef(
"test_field", field, mock(FieldDefCreator.FieldDefCreatorContext.class));
new ContextSuggestFieldDef("test_field", field, getMockFieldDefCreatorContext());
assertEquals(
ClassicAnalyzer.class, contextSuggestFieldDef.getSearchAnalyzer().get().getClass());
assertEquals(ClassicAnalyzer.class, contextSuggestFieldDef.getIndexAnalyzer().get().getClass());
Expand All @@ -88,8 +90,7 @@ public void validSearchAndIndexAnalyzerWhenSearchAndIndexAnalyzersAreProvided()
.setIndexAnalyzer(indexAnalyzer)
.build();
ContextSuggestFieldDef contextSuggestFieldDef =
new ContextSuggestFieldDef(
"test_field", field, mock(FieldDefCreator.FieldDefCreatorContext.class));
new ContextSuggestFieldDef("test_field", field, getMockFieldDefCreatorContext());
assertSame(
BulgarianAnalyzer.class, contextSuggestFieldDef.getSearchAnalyzer().get().getClass());
assertSame(EnglishAnalyzer.class, contextSuggestFieldDef.getIndexAnalyzer().get().getClass());
Expand All @@ -99,12 +100,20 @@ public void validSearchAndIndexAnalyzerWhenSearchAndIndexAnalyzersAreProvided()
public void validDefaultSearchAndIndexAnalyzerNoAnalyzersAreProvided() {
Field field = Field.newBuilder().build();
ContextSuggestFieldDef contextSuggestFieldDef =
new ContextSuggestFieldDef(
"test_field", field, mock(FieldDefCreator.FieldDefCreatorContext.class));
new ContextSuggestFieldDef("test_field", field, getMockFieldDefCreatorContext());
assertSame(StandardAnalyzer.class, contextSuggestFieldDef.getSearchAnalyzer().get().getClass());
assertSame(StandardAnalyzer.class, contextSuggestFieldDef.getIndexAnalyzer().get().getClass());
}

private FieldDefCreator.FieldDefCreatorContext getMockFieldDefCreatorContext() {
FieldDefCreator.FieldDefCreatorContext mockContext =
mock(FieldDefCreator.FieldDefCreatorContext.class);
NrtsearchConfig config =
new NrtsearchConfig(new ByteArrayInputStream("nodeName: node1".getBytes()));
when(mockContext.config()).thenReturn(config);
return mockContext;
}

@Test
public void validContextSuggestFieldDefTest() throws IOException {
FieldDef contextSuggestFieldDef = getFieldDef(DEFAULT_TEST_INDEX, SINGLE_VALUED_FIELD_NAME);
Expand Down

This file was deleted.

0 comments on commit 9a1613a

Please sign in to comment.