Skip to content

Commit

Permalink
Fix merging logic of Suggester Options (#29514)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbaiera authored May 2, 2018
1 parent 383856a commit 6d6da7c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,13 @@ public static Option fromXContent(XContentParser parser) {

protected void mergeInto(Option otherOption) {
score = Math.max(score, otherOption.score);
if (otherOption.collateMatch != null) {
if (collateMatch == null) {
collateMatch = otherOption.collateMatch;
} else {
collateMatch |= otherOption.collateMatch;
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,27 @@ public void testParsingExceptionOnUnknownSuggestion() throws IOException {
}
}


public void testMergingSuggestionOptions() {
String suggestedWord = randomAlphaOfLength(10);
String secondWord = randomAlphaOfLength(10);
Text suggestionText = new Text(suggestedWord + " " + secondWord);
Text highlighted = new Text("<em>" + suggestedWord + "</em> " + 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());
}
}

0 comments on commit 6d6da7c

Please sign in to comment.