From 6d6da7c66175d30bb3edc7c7762c281693ee1880 Mon Sep 17 00:00:00 2001 From: James Baiera Date: Wed, 2 May 2018 14:40:57 -0400 Subject: [PATCH] Fix merging logic of Suggester Options (#29514) Suggester Options have a collate match field that is returned when the prune option is set to true. These values should be merged together in the query reduce phase, otherwise good suggestions that result in rare hits in shards with results that do not arrive first may be incorrectly marked as not matching the collate query. --- .../elasticsearch/search/suggest/Suggest.java | 7 ++++++ .../search/suggest/SuggestTests.java | 24 ++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/search/suggest/Suggest.java b/server/src/main/java/org/elasticsearch/search/suggest/Suggest.java index a54f1193df0..e4099193359 100644 --- a/server/src/main/java/org/elasticsearch/search/suggest/Suggest.java +++ b/server/src/main/java/org/elasticsearch/search/suggest/Suggest.java @@ -742,6 +742,13 @@ public class Suggest implements Iterable" + suggestedWord + " " + secondWord); + PhraseSuggestion.Entry.Option option1 = new Option(suggestionText, highlighted, 0.7f, false); + PhraseSuggestion.Entry.Option option2 = new Option(suggestionText, highlighted, 0.8f, true); + PhraseSuggestion.Entry.Option option3 = new Option(suggestionText, highlighted, 0.6f); + assertEquals(suggestionText, option1.getText()); + assertEquals(highlighted, option1.getHighlighted()); + assertFalse(option1.collateMatch()); + assertTrue(option1.getScore() > 0.6f); + option1.mergeInto(option2); + assertEquals(suggestionText, option1.getText()); + assertEquals(highlighted, option1.getHighlighted()); + assertTrue(option1.collateMatch()); + assertTrue(option1.getScore() > 0.7f); + option1.mergeInto(option3); + assertEquals(suggestionText, option1.getText()); + assertEquals(highlighted, option1.getHighlighted()); + assertTrue(option1.getScore() > 0.7f); + assertTrue(option1.collateMatch()); + } }