Remove some special casing
This special casing is useless. If the word is the same as what user typed, the scoring algorithm already ensures that it comes out at the top. Actually, as is written in a comment here, code executed later is actively relying on this suggestion having the top score ! There is no need to test it for equalness and inserting it at the top then. Change-Id: I263a6de59b77ec72a2dcbb933361b8e16fca0681
This commit is contained in:
parent
22657dcba0
commit
7e49a2b6b8
1 changed files with 10 additions and 27 deletions
|
@ -394,34 +394,17 @@ public class Suggest {
|
|||
final int score = wordInfo.mScore;
|
||||
int pos = 0;
|
||||
|
||||
// Check if it's the same word, only caps are different
|
||||
if (StringUtils.equalsIgnoreCase(consideredWord, word)) {
|
||||
// TODO: remove this surrounding if clause and move this logic to
|
||||
// getSuggestedWordBuilder.
|
||||
if (suggestions.size() > 0) {
|
||||
final SuggestedWordInfo currentHighestWord = suggestions.get(0);
|
||||
// If the current highest word is also equal to typed word, we need to compare
|
||||
// frequency to determine the insertion position. This does not ensure strictly
|
||||
// correct ordering, but ensures the top score is on top which is enough for
|
||||
// removing duplicates correctly.
|
||||
if (StringUtils.equalsIgnoreCase(currentHighestWord.mWord, word)
|
||||
&& score <= currentHighestWord.mScore) {
|
||||
pos = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Check the last one's score and bail
|
||||
if (suggestions.size() >= prefMaxSuggestions
|
||||
&& suggestions.get(prefMaxSuggestions - 1).mScore >= score) return true;
|
||||
final int length = wordInfo.mCodePointCount;
|
||||
while (pos < suggestions.size()) {
|
||||
final int curScore = suggestions.get(pos).mScore;
|
||||
if (curScore < score
|
||||
|| (curScore == score && length < suggestions.get(pos).mCodePointCount)) {
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
// Check the last one's score and bail
|
||||
if (suggestions.size() >= prefMaxSuggestions
|
||||
&& suggestions.get(prefMaxSuggestions - 1).mScore >= score) return true;
|
||||
final int length = wordInfo.mCodePointCount;
|
||||
while (pos < suggestions.size()) {
|
||||
final int curScore = suggestions.get(pos).mScore;
|
||||
if (curScore < score
|
||||
|| (curScore == score && length < suggestions.get(pos).mCodePointCount)) {
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
if (pos >= prefMaxSuggestions) {
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue