#26496: handle `shard_size` correctly in the completion suggester and tests.

The completion suggester has a `shard_size` option that sets the size of the suggestions to retrieve per shard but it is ignored
 by the builder. This commit restores the handling of this option and fixes a test that can randomly fail without it.
This commit is contained in:
Jim Ferenczi 2017-09-07 18:22:28 +02:00
parent cff904bf97
commit e684c5e0a5
3 changed files with 6 additions and 3 deletions

View File

@ -58,8 +58,8 @@ public class CompletionSuggester extends Suggester<CompletionSuggestionContext>
CompletionSuggestion.Entry completionSuggestEntry = new CompletionSuggestion.Entry(
new Text(spare.toString()), 0, spare.length());
completionSuggestion.addTerm(completionSuggestEntry);
TopSuggestDocsCollector collector =
new TopDocumentsCollector(suggestionContext.getSize(), suggestionContext.isSkipDuplicates());
int shardSize = suggestionContext.getShardSize() != null ? suggestionContext.getShardSize() : suggestionContext.getSize();
TopSuggestDocsCollector collector = new TopDocumentsCollector(shardSize, suggestionContext.isSkipDuplicates());
suggest(searcher, suggestionContext.toQuery(), collector);
int numResult = 0;
for (TopSuggestDocs.SuggestScoreDoc suggestScoreDoc : collector.get().scoreLookupDocs()) {

View File

@ -289,6 +289,9 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSug
suggestionContext.setSkipDuplicates(skipDuplicates);
suggestionContext.setFuzzyOptions(fuzzyOptions);
suggestionContext.setRegexOptions(regexOptions);
if (shardSize != null) {
suggestionContext.setShardSize(shardSize);
}
MappedFieldType mappedFieldType = mapperService.fullName(suggestionContext.getField());
if (mappedFieldType == null || mappedFieldType instanceof CompletionFieldMapper.CompletionFieldType == false) {
throw new IllegalArgumentException("Field [" + suggestionContext.getField() + "] is not a completion suggest field");

View File

@ -1157,7 +1157,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
));
}
indexRandom(true, indexRequestBuilders);
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg");
CompletionSuggestionBuilder prefix = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg").shardSize(15);
assertSuggestions("foo", prefix, "suggester10", "suggester9", "suggester8", "suggester7", "suggester6");
}