+ last dev. on the search feature before beta1

This commit is contained in:
kelson42 2011-03-26 15:29:56 +00:00
parent 47bd414a18
commit 91212bdb13
3 changed files with 29 additions and 1 deletions

View File

@ -79,7 +79,31 @@ namespace kiwix {
return s.str(); 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() { string Reader::getRandomPageUrl() {
zim::size_type idx = this->firstArticleOffset + zim::size_type idx = this->firstArticleOffset +
(zim::size_type)((double)rand() / ((double)RAND_MAX + 1) * this->articleCount); (zim::size_type)((double)rand() / ((double)RAND_MAX + 1) * this->articleCount);

View File

@ -45,6 +45,7 @@ namespace kiwix {
string getFirstPageUrl(); string getFirstPageUrl();
string getMainPageUrl(); string getMainPageUrl();
bool getMetatag(const string &url, string &content); 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 getContentByUrl(const string &url, string &content, unsigned int &contentLength, string &contentType);
bool searchSuggestions(const string &prefix, unsigned int suggestionsCount); bool searchSuggestions(const string &prefix, unsigned int suggestionsCount);
bool getNextSuggestion(string &title); bool getNextSuggestion(string &title);

View File

@ -173,6 +173,9 @@ namespace kiwix {
unsigned int pageCount = this->estimatedResultCount / this->resultCountPerPage + 1; unsigned int pageCount = this->estimatedResultCount / this->resultCountPerPage + 1;
if (pageCount > 10) if (pageCount > 10)
pageCount = 10; pageCount = 10;
else if (pageCount == 1)
pageCount = 0;
for (unsigned int i=0; i<pageCount; i++) { for (unsigned int i=0; i<pageCount; i++) {
CDT page; CDT page;
page["start"] = i * this->resultCountPerPage; page["start"] = i * this->resultCountPerPage;