diff --git a/src/common/kiwix/reader.cpp b/src/common/kiwix/reader.cpp index 1b25c2712..a7759ba97 100644 --- a/src/common/kiwix/reader.cpp +++ b/src/common/kiwix/reader.cpp @@ -503,24 +503,26 @@ namespace kiwix { return retVal; } + std::vector Reader::getTitleVariants(const std::string &title) { + std::vector variants; + variants.push_back(title); + variants.push_back(kiwix::ucFirst(title)); + variants.push_back(kiwix::lcFirst(title)); + variants.push_back(kiwix::toTitle(title)); + return variants; + } + /* Try also a few variations of the prefix to have better results */ bool Reader::searchSuggestionsSmart(const string &prefix, unsigned int suggestionsCount) { - std::string myPrefix = prefix; - - /* Normal suggestion request */ - bool retVal = this->searchSuggestions(prefix, suggestionsCount, true); - - /* Try with first letter uppercase */ - myPrefix = kiwix::ucFirst(myPrefix); - this->searchSuggestions(myPrefix, suggestionsCount, false); - - /* Try with first letter lowercase */ - myPrefix = kiwix::lcFirst(myPrefix); - this->searchSuggestions(myPrefix, suggestionsCount, false); - - /* Try with title words */ - myPrefix = kiwix::toTitle(myPrefix); - this->searchSuggestions(myPrefix, suggestionsCount, false); + std::vector variants = this->getTitleVariants(prefix); + bool retVal; + + this->suggestions.clear(); + for (std::vector::iterator variantsItr = variants.begin(); + variantsItr != variants.end(); + variantsItr++) { + retVal = this->searchSuggestions(*variantsItr, suggestionsCount, false) || retVal; + } return retVal; } diff --git a/src/common/kiwix/reader.h b/src/common/kiwix/reader.h index f35cfc0b0..9d2982ebc 100644 --- a/src/common/kiwix/reader.h +++ b/src/common/kiwix/reader.h @@ -68,6 +68,7 @@ namespace kiwix { bool getContentByDecodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType); bool searchSuggestions(const string &prefix, unsigned int suggestionsCount, const bool reset = true); bool searchSuggestionsSmart(const string &prefix, unsigned int suggestionsCount); + std::vector getTitleVariants(const std::string &title); bool getNextSuggestion(string &title); bool canCheckIntegrity(); bool isCorrupted();