Skip to content

Commit 19cdd5a

Browse files
Spelling corrections are included in smart suggestions
But that may result in duplicated suggestions as demonstrated by some test points in the Suggestion.smartSuggestions unit-test.
1 parent deb7570 commit 19cdd5a

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/suggestion.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,13 +475,18 @@ SuggestionSearch::Results SuggestionSearch::getSpellingSuggestions(uint32_t maxC
475475
return r;
476476
}
477477
SuggestionSearch::Results SuggestionSearch::getSmartSuggestions(uint32_t maxCount) const {
478-
if ( static_cast<uint32_t>(getEstimatedMatches()) > maxCount ) {
479-
return getAutocompletionSuggestions(maxCount);
480-
}
481-
482478
SuggestionSearch::Results r;
483-
for ( const auto& s : getResults(0, maxCount) ) {
484-
r.push_back(s);
479+
const uint32_t titleSuggestionCount = getEstimatedMatches();
480+
if ( titleSuggestionCount == 0 || titleSuggestionCount > maxCount ) {
481+
r = getAutocompletionSuggestions(maxCount);
482+
if ( r.size() < maxCount ) {
483+
const auto corrections = getSpellingSuggestions(maxCount - r.size());
484+
r.insert(r.end(), corrections.begin(), corrections.end());
485+
}
486+
} else {
487+
for ( const auto& s : getResults(0, maxCount) ) {
488+
r.push_back(s);
489+
}
485490
}
486491
return r;
487492
}

test/suggestion.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@ TEST(Suggestion, smartSuggestions) {
982982
EXPECT_SMART_SUGGESTION_RESULTS(archive, "bi", 4, ({
983983
{"", "", "<b>big</b>" },
984984
{"", "", "<b>birth</b>" },
985+
{"", "", "<b>big</b>" }, // XXX: duplicated result due to spelling correction
985986
}));
986987

987988
EXPECT_SMART_SUGGESTION_RESULTS(archive, "date bi", 10, ({
@@ -994,6 +995,7 @@ TEST(Suggestion, smartSuggestions) {
994995
EXPECT_SMART_SUGGESTION_RESULTS(archive, "date bi", 3, ({
995996
{"", "", "date <b>big</b>" },
996997
{"", "", "date <b>birth</b>" },
998+
{"", "", "date <b>big</b>" }, // XXX: duplicated result due to spelling correction
997999
}));
9981000

9991001
EXPECT_SMART_SUGGESTION_RESULTS(archive, "da", 20, ({
@@ -1020,6 +1022,7 @@ TEST(Suggestion, smartSuggestions) {
10201022
{"", "", "<b>data</b>" },
10211023
{"", "", "<b>date</b>" },
10221024
{"", "", "<b>day</b>" },
1025+
{"", "", "<b>day</b>" }, // XXX: duplicated result due to spelling correction
10231026
}));
10241027

10251028
// Autocompletion results are selected based on frequency ("daily" and "data"
@@ -1043,6 +1046,12 @@ TEST(Suggestion, smartSuggestions) {
10431046
{"", "", "birth <b>data</b>" },
10441047
{"", "", "birth <b>date</b>" },
10451048
{"", "", "birth <b>day</b>" },
1049+
{"", "", "birth <b>day</b>" }, // XXX: duplicated result due to spelling correction
1050+
}));
1051+
1052+
EXPECT_SMART_SUGGESTION_RESULTS(archive, "barth", 5, ({
1053+
{"", "", "<b>birth</b>" },
1054+
{"", "", "<b>earth</b>" },
10461055
}));
10471056
}
10481057

0 commit comments

Comments
 (0)