+ simplifaction of the code = cleaning

This commit is contained in:
kelson42 2014-08-27 17:13:29 -06:00
parent a353513c9c
commit 1cc94e1b95
2 changed files with 19 additions and 16 deletions

View File

@ -503,24 +503,26 @@ namespace kiwix {
return retVal; return retVal;
} }
std::vector<std::string> Reader::getTitleVariants(const std::string &title) {
std::vector<std::string> 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 */ /* Try also a few variations of the prefix to have better results */
bool Reader::searchSuggestionsSmart(const string &prefix, unsigned int suggestionsCount) { bool Reader::searchSuggestionsSmart(const string &prefix, unsigned int suggestionsCount) {
std::string myPrefix = prefix; std::vector<std::string> variants = this->getTitleVariants(prefix);
bool retVal;
/* Normal suggestion request */ this->suggestions.clear();
bool retVal = this->searchSuggestions(prefix, suggestionsCount, true); for (std::vector<std::string>::iterator variantsItr = variants.begin();
variantsItr != variants.end();
/* Try with first letter uppercase */ variantsItr++) {
myPrefix = kiwix::ucFirst(myPrefix); retVal = this->searchSuggestions(*variantsItr, suggestionsCount, false) || retVal;
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);
return retVal; return retVal;
} }

View File

@ -68,6 +68,7 @@ namespace kiwix {
bool getContentByDecodedUrl(const string &url, string &content, unsigned int &contentLength, string &contentType); 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 searchSuggestions(const string &prefix, unsigned int suggestionsCount, const bool reset = true);
bool searchSuggestionsSmart(const string &prefix, unsigned int suggestionsCount); bool searchSuggestionsSmart(const string &prefix, unsigned int suggestionsCount);
std::vector<std::string> getTitleVariants(const std::string &title);
bool getNextSuggestion(string &title); bool getNextSuggestion(string &title);
bool canCheckIntegrity(); bool canCheckIntegrity();
bool isCorrupted(); bool isCorrupted();