diff --git a/src/common/kiwix/reader.cpp b/src/common/kiwix/reader.cpp index a15a9cd96..b077ac579 100644 --- a/src/common/kiwix/reader.cpp +++ b/src/common/kiwix/reader.cpp @@ -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 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); diff --git a/src/common/kiwix/reader.h b/src/common/kiwix/reader.h index 67e04af83..186ff1185 100644 --- a/src/common/kiwix/reader.h +++ b/src/common/kiwix/reader.h @@ -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); diff --git a/src/common/kiwix/searcher.cpp b/src/common/kiwix/searcher.cpp index 445fee665..b153e2de4 100644 --- a/src/common/kiwix/searcher.cpp +++ b/src/common/kiwix/searcher.cpp @@ -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; iresultCountPerPage;