mirror of https://github.com/kiwix/libkiwix.git
Merge branch 'master' of ssh://git.code.sf.net/p/kiwix/kiwix
This commit is contained in:
commit
58c5ffbca5
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -39,21 +39,39 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search strings in the database */
|
/* Search strings in the database */
|
||||||
void Searcher::search(std::string &search, const unsigned int resultStart,
|
void Searcher::search(std::string &search, unsigned int resultStart,
|
||||||
const unsigned int resultEnd, const bool verbose) {
|
unsigned int resultEnd, const bool verbose) {
|
||||||
this->reset();
|
this->reset();
|
||||||
|
|
||||||
if (verbose == true) {
|
if (verbose == true) {
|
||||||
cout << "Performing query `" << search << "'" << endl;
|
cout << "Performing query `" << search << "'" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->searchPattern = search;
|
/* If resultEnd & resultStart inverted */
|
||||||
this->resultCountPerPage = resultEnd - resultStart;
|
if (resultStart > resultEnd) {
|
||||||
this->resultStart = resultStart;
|
resultEnd += resultStart;
|
||||||
this->resultEnd = resultEnd;
|
resultStart = resultEnd - resultStart;
|
||||||
string unaccentedSearch = removeAccents(search);
|
resultEnd -= resultStart;
|
||||||
searchInIndex(unaccentedSearch, resultStart, resultEnd, verbose);
|
}
|
||||||
this->resultOffset = this->results.begin();
|
|
||||||
|
/* Try to find results */
|
||||||
|
if (resultStart != resultEnd) {
|
||||||
|
|
||||||
|
/* Avoid big researches */
|
||||||
|
this->resultCountPerPage = resultEnd - resultStart;
|
||||||
|
if (this->resultCountPerPage > 70) {
|
||||||
|
resultEnd = resultStart + 70;
|
||||||
|
this->resultCountPerPage = 70;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Perform the search */
|
||||||
|
this->searchPattern = search;
|
||||||
|
this->resultStart = resultStart;
|
||||||
|
this->resultEnd = resultEnd;
|
||||||
|
string unaccentedSearch = removeAccents(search);
|
||||||
|
searchInIndex(unaccentedSearch, resultStart, resultEnd, verbose);
|
||||||
|
this->resultOffset = this->results.begin();
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,8 +59,8 @@ namespace kiwix {
|
||||||
public:
|
public:
|
||||||
Searcher();
|
Searcher();
|
||||||
|
|
||||||
void search(std::string &search, const unsigned int resultStart,
|
void search(std::string &search, unsigned int resultStart,
|
||||||
const unsigned int resultEnd, const bool verbose=false);
|
unsigned int resultEnd, const bool verbose=false);
|
||||||
bool getNextResult(string &url, string &title, unsigned int &score);
|
bool getNextResult(string &url, string &title, unsigned int &score);
|
||||||
unsigned int getEstimatedResultCount();
|
unsigned int getEstimatedResultCount();
|
||||||
bool setProtocolPrefix(const std::string prefix);
|
bool setProtocolPrefix(const std::string prefix);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -50,6 +50,15 @@ std::string kiwix::beautifyInteger(const unsigned int number) {
|
||||||
return numberString;
|
return numberString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string kiwix::beautifyFileSize(const unsigned int number) {
|
||||||
|
if (number > 1024*1024) {
|
||||||
|
return kiwix::beautifyInteger(number/(1024*1024)) + " GB";
|
||||||
|
} else {
|
||||||
|
return kiwix::beautifyInteger(number/1024 !=
|
||||||
|
0 ? number/1024 : 1) + " MB";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string kiwix::removeAccents(const std::string &text) {
|
std::string kiwix::removeAccents(const std::string &text) {
|
||||||
loadICUExternalTables();
|
loadICUExternalTables();
|
||||||
ucnv_setDefaultName("UTF-8");
|
ucnv_setDefaultName("UTF-8");
|
||||||
|
@ -199,6 +208,18 @@ std::string kiwix::ucFirst (const std::string &word) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string kiwix::ucAll (const std::string &word) {
|
||||||
|
if (word.empty())
|
||||||
|
return "";
|
||||||
|
|
||||||
|
std::string result;
|
||||||
|
|
||||||
|
UnicodeString unicodeWord(word.c_str());
|
||||||
|
unicodeWord.toUpper().toUTF8String(result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::string kiwix::lcFirst (const std::string &word) {
|
std::string kiwix::lcFirst (const std::string &word) {
|
||||||
if (word.empty())
|
if (word.empty())
|
||||||
return "";
|
return "";
|
||||||
|
@ -213,6 +234,17 @@ std::string kiwix::lcFirst (const std::string &word) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string kiwix::lcAll (const std::string &word) {
|
||||||
|
if (word.empty())
|
||||||
|
return "";
|
||||||
|
|
||||||
|
std::string result;
|
||||||
|
|
||||||
|
UnicodeString unicodeWord(word.c_str());
|
||||||
|
unicodeWord.toLower().toUTF8String(result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
std::string kiwix::toTitle (const std::string &word) {
|
std::string kiwix::toTitle (const std::string &word) {
|
||||||
if (word.empty())
|
if (word.empty())
|
||||||
|
|
|
@ -43,6 +43,7 @@ namespace kiwix {
|
||||||
|
|
||||||
std::string removeAccents(const std::string &text);
|
std::string removeAccents(const std::string &text);
|
||||||
std::string beautifyInteger(const unsigned int number);
|
std::string beautifyInteger(const unsigned int number);
|
||||||
|
std::string beautifyFileSize(const unsigned int number);
|
||||||
std::string urlEncode(const std::string &c);
|
std::string urlEncode(const std::string &c);
|
||||||
void printStringInHexadecimal(const char *s);
|
void printStringInHexadecimal(const char *s);
|
||||||
void printStringInHexadecimal(UnicodeString s);
|
void printStringInHexadecimal(UnicodeString s);
|
||||||
|
@ -58,6 +59,8 @@ namespace kiwix {
|
||||||
std::vector<std::string> split(const std::string&, const char*);
|
std::vector<std::string> split(const std::string&, const char*);
|
||||||
std::vector<std::string> split(const char*, const std::string&);
|
std::vector<std::string> split(const char*, const std::string&);
|
||||||
|
|
||||||
|
std::string ucAll(const std::string &word);
|
||||||
|
std::string lcAll(const std::string &word);
|
||||||
std::string ucFirst(const std::string &word);
|
std::string ucFirst(const std::string &word);
|
||||||
std::string lcFirst(const std::string &word);
|
std::string lcFirst(const std::string &word);
|
||||||
std::string toTitle(const std::string &word);
|
std::string toTitle(const std::string &word);
|
||||||
|
|
|
@ -27,9 +27,20 @@
|
||||||
#kiwixsearchbox {
|
#kiwixsearchbox {
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
float: right;
|
float: right;
|
||||||
|
width: 300px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#kiwixsearch {
|
#kiwixsearch {
|
||||||
margin: 0px;
|
margin: 0px;
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Try to fix buggy stuff in jquery-ui autocomplete */
|
||||||
|
#ui-id-1 {
|
||||||
|
background: white;
|
||||||
|
border: solid 1px grey;
|
||||||
|
}
|
||||||
|
|
||||||
|
li.ui-state-focus {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
Loading…
Reference in New Issue