mirror of https://github.com/kiwix/libkiwix.git
+ last dev. on the search feature before beta1
This commit is contained in:
parent
47bd414a18
commit
91212bdb13
|
@ -79,7 +79,31 @@ namespace kiwix {
|
|||
return s.str();
|
||||
}
|
||||
|
||||
/* Return a random article URL */
|
||||
/* Return a page url from a title */
|
||||
bool Reader::getPageUrlFromTitle(const string &title, string &url) {
|
||||
/* Extract the content from the zim file */
|
||||
std::pair<bool, zim::File::const_iterator> resultPair = zimFileHandler->findxByTitle('A', title);
|
||||
|
||||
/* Test if the article was found */
|
||||
if (resultPair.first == true) {
|
||||
|
||||
/* Get the article */
|
||||
zim::Article article = zimFileHandler->getArticle(resultPair.second.getIndex());
|
||||
|
||||
/* If redirect */
|
||||
unsigned int loopCounter = 0;
|
||||
while (article.isRedirect() && loopCounter++<42) {
|
||||
article = article.getRedirectArticle();
|
||||
}
|
||||
|
||||
url = article.getLongUrl();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Return an URL from a title*/
|
||||
string Reader::getRandomPageUrl() {
|
||||
zim::size_type idx = this->firstArticleOffset +
|
||||
(zim::size_type)((double)rand() / ((double)RAND_MAX + 1) * this->articleCount);
|
||||
|
|
|
@ -45,6 +45,7 @@ namespace kiwix {
|
|||
string getFirstPageUrl();
|
||||
string getMainPageUrl();
|
||||
bool getMetatag(const string &url, string &content);
|
||||
bool getPageUrlFromTitle(const string &title, string &url);
|
||||
bool getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType);
|
||||
bool searchSuggestions(const string &prefix, unsigned int suggestionsCount);
|
||||
bool getNextSuggestion(string &title);
|
||||
|
|
|
@ -173,6 +173,9 @@ namespace kiwix {
|
|||
unsigned int pageCount = this->estimatedResultCount / this->resultCountPerPage + 1;
|
||||
if (pageCount > 10)
|
||||
pageCount = 10;
|
||||
else if (pageCount == 1)
|
||||
pageCount = 0;
|
||||
|
||||
for (unsigned int i=0; i<pageCount; i++) {
|
||||
CDT page;
|
||||
page["start"] = i * this->resultCountPerPage;
|
||||
|
|
Loading…
Reference in New Issue