+ move improved suggestion system (check also variations of the prefix) to reader.cpp

This commit is contained in:
kelson42 2012-08-25 15:36:41 +00:00
parent 7cf557b44d
commit 149c840d99

View File

@ -224,37 +224,13 @@ static int accessHandlerCallback(void *cls,
/* Get the suggestions */
content = "[";
reader->searchSuggestions(term, maxSuggestionCount);
reader->searchSuggestionsSmart(term, maxSuggestionCount);
while (reader->getNextSuggestion(suggestion)) {
kiwix::stringReplacement(suggestion, "\"", "\\\"");
content += (content == "[" ? "" : ",");
content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}";
suggestionCount++;
}
/* Try to get further suggestions with ucFirst(pattern) if maxSuggestionCount is not reached */
if (suggestionCount < 10) {
term = kiwix::ucFirst(term);
reader->searchSuggestions(term, maxSuggestionCount);
while (reader->getNextSuggestion(suggestion) && suggestionCount < 10) {
kiwix::stringReplacement(suggestion, "\"", "\\\"");
content += (content == "[" ? "" : ",");
content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}";
suggestionCount++;
}
}
/* Try to get further suggestions with lcFirst(pattern) if maxSuggestionCount is not reached */
if (suggestionCount < 10) {
term = kiwix::lcFirst(term);
reader->searchSuggestions(term, maxSuggestionCount);
while (reader->getNextSuggestion(suggestion) && suggestionCount < 10) {
kiwix::stringReplacement(suggestion, "\"", "\\\"");
content += (content == "[" ? "" : ",");
content += "{\"value\":\"" + suggestion + "\",\"label\":\"" + suggestion + "\"}";
suggestionCount++;
}
}
content += (suggestionCount == 0 ? "" : ",");
content += "{\"value\":\"" + std::string(term) + " \", \"label\":\"containing '" + std::string(term) + "'...\"}]";