From 41217c22d8f4d71590b1c212bd7ebb78ed802982 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Tue, 22 Mar 2011 21:04:41 +0000 Subject: [PATCH] + search page navigation --- src/common/kiwix/cluceneIndexer.cpp | 15 ++++++++++----- src/common/kiwix/cluceneSearcher.cpp | 6 ++++-- src/common/kiwix/cluceneSearcher.h | 3 ++- src/common/kiwix/searcher.cpp | 25 ++++++++++++++++++++++--- src/common/kiwix/searcher.h | 9 +++++++-- src/common/kiwix/xapianSearcher.cpp | 5 +++-- src/common/kiwix/xapianSearcher.h | 3 ++- static/results.tmpl | 8 ++++---- 8 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/common/kiwix/cluceneIndexer.cpp b/src/common/kiwix/cluceneIndexer.cpp index f5490ae43..bc3d9ab9c 100644 --- a/src/common/kiwix/cluceneIndexer.cpp +++ b/src/common/kiwix/cluceneIndexer.cpp @@ -45,24 +45,29 @@ namespace kiwix { Document doc; /* Not indexed but stored */ - STRCPY_AtoT(buffer, title.c_str(), MAX_BUFFER_SIZE); + //STRCPY_AtoT(buffer, title.c_str(), MAX_BUFFER_SIZE); + ::mbstowcs(buffer,title.c_str(),MAX_BUFFER_SIZE); doc.add(*_CLNEW Field(_T("title"), buffer, Field::STORE_YES | Field::INDEX_UNTOKENIZED)); - STRCPY_AtoT(buffer, url.c_str(), MAX_BUFFER_SIZE); + //STRCPY_AtoT(buffer, url.c_str(), MAX_BUFFER_SIZE); + ::mbstowcs(buffer,url.c_str(),MAX_BUFFER_SIZE); doc.add(*_CLNEW Field(_T("url"), buffer, Field::STORE_YES | Field::INDEX_UNTOKENIZED)); /* indexed but not stored */ - STRCPY_AtoT(buffer, unaccentedTitle.c_str(), MAX_BUFFER_SIZE); + //STRCPY_AtoT(buffer, unaccentedTitle.c_str(), MAX_BUFFER_SIZE); + ::mbstowcs(buffer,unaccentedTitle.c_str(),MAX_BUFFER_SIZE); Field *titleField = new Field(_T("utitle"), buffer, Field::STORE_NO | Field::INDEX_TOKENIZED); titleField->setBoost(getTitleBoostFactor(content.size())); doc.add(*titleField); - STRCPY_AtoT(buffer, keywords.c_str(), MAX_BUFFER_SIZE); + //STRCPY_AtoT(buffer, keywords.c_str(), MAX_BUFFER_SIZE); + ::mbstowcs(buffer,keywords.c_str(),MAX_BUFFER_SIZE); Field *keywordsField = new Field(_T("keywords"), buffer, Field::STORE_NO | Field::INDEX_TOKENIZED); keywordsField->setBoost(keywordsBoostFactor); doc.add(*keywordsField); - STRCPY_AtoT(buffer, content.c_str(), MAX_BUFFER_SIZE); + //STRCPY_AtoT(buffer, content.c_str(), MAX_BUFFER_SIZE); + ::mbstowcs(buffer,content.c_str(),MAX_BUFFER_SIZE); doc.add(*_CLNEW Field(_T("content"), buffer, Field::STORE_NO | Field::INDEX_TOKENIZED)); /* Add the document to the index */ diff --git a/src/common/kiwix/cluceneSearcher.cpp b/src/common/kiwix/cluceneSearcher.cpp index 5aa141174..adc9e9b91 100644 --- a/src/common/kiwix/cluceneSearcher.cpp +++ b/src/common/kiwix/cluceneSearcher.cpp @@ -40,10 +40,12 @@ namespace kiwix { } /* Search strings in the database */ - void CluceneSearcher::searchInIndex(string &search, const unsigned int resultsCount, const bool verbose) { + void CluceneSearcher::searchInIndex(string &search, const unsigned int resultStart, + const unsigned int resultEnd, const bool verbose) { IndexSearcher searcher(reader); QueryParser parser(_T("content"), &analyzer); - STRCPY_AtoT(buffer, search.c_str(), MAX_BUFFER_SIZE); + //STRCPY_AtoT(buffer, search.c_str(), MAX_BUFFER_SIZE); + ::mbstowcs(buffer,search.c_str(),MAX_BUFFER_SIZE); Query* query = parser.parse(buffer); Hits* hits = searcher.search(query); cout << "--------------------------------" << hits->length() << endl; diff --git a/src/common/kiwix/cluceneSearcher.h b/src/common/kiwix/cluceneSearcher.h index 702db36e2..259c77458 100644 --- a/src/common/kiwix/cluceneSearcher.h +++ b/src/common/kiwix/cluceneSearcher.h @@ -41,7 +41,8 @@ namespace kiwix { public: CluceneSearcher(const string &cluceneDirectoryPath); - void searchInIndex(string &search, const unsigned int resultsCount, const bool verbose=false); + void searchInIndex(string &search, const unsigned int resultStart, + const unsigned int resultEnd, const bool verbose=false); protected: void closeIndex(); diff --git a/src/common/kiwix/searcher.cpp b/src/common/kiwix/searcher.cpp index f362d8a0d..b6a5255c3 100644 --- a/src/common/kiwix/searcher.cpp +++ b/src/common/kiwix/searcher.cpp @@ -43,7 +43,8 @@ namespace kiwix { } /* Search strings in the database */ - void Searcher::search(std::string &search, const unsigned int resultsCount, const bool verbose) { + void Searcher::search(std::string &search, const unsigned int resultStart, + const unsigned int resultEnd, const bool verbose) { this->reset(); @@ -52,7 +53,10 @@ namespace kiwix { } this->searchPattern = search; - searchInIndex(removeAccents(search), resultsCount, verbose); + this->resultCountPerPage = resultEnd - resultStart; + this->resultStart = resultStart; + this->resultEnd = resultEnd; + searchInIndex(removeAccents(search), resultStart, resultEnd, verbose); this->resultOffset = this->results.begin(); return; @@ -159,10 +163,25 @@ namespace kiwix { this->resultOffset++; } this->resultOffset = this->results.begin(); - oData["results"] = resultsCDT; + + // pages + CDT pagesCDT(CDT::ARRAY_VAL); + unsigned int pageCount = this->estimatedResultCount / this->resultCountPerPage + 1; + if (pageCount > 10) + pageCount = 10; + for (int i=0; iresultCountPerPage; + page["end"] = (i+1) * this->resultCountPerPage; + pagesCDT.PushBack(page); + } + oData["pages"] = pagesCDT; + oData["count"] = this->estimatedResultCount; oData["searchPattern"] = this->searchPattern; + oData["resultStart"] = this->resultStart; + oData["resultEnd"] = this->resultEnd; STLW::string sResult; StringOutputCollector oDataCollector(sResult); diff --git a/src/common/kiwix/searcher.h b/src/common/kiwix/searcher.h index 92c94ce21..41ff24faa 100644 --- a/src/common/kiwix/searcher.h +++ b/src/common/kiwix/searcher.h @@ -65,7 +65,8 @@ namespace kiwix { public: Searcher(); - void search(std::string &search, const unsigned int resultsCount, const bool verbose=false); + void search(std::string &search, const unsigned int resultStart, + const unsigned int resultEnd, const bool verbose=false); bool getNextResult(string &url, string &title, unsigned int &score); unsigned int getEstimatedResultCount(); bool setResultTemplatePath(const std::string path); @@ -75,11 +76,15 @@ namespace kiwix { protected: std::string beautifyInteger(const unsigned int number); virtual void closeIndex() = 0; - virtual void searchInIndex(string &search, const unsigned int resultsCount, const bool verbose=false) = 0; + virtual void searchInIndex(string &search, const unsigned int resultStart, + const unsigned int resultEnd, const bool verbose=false) = 0; std::vector results; std::vector::iterator resultOffset; std::string resultTemplatePath; + unsigned int resultCountPerPage; + unsigned int resultStart; + unsigned int resultEnd; unsigned int estimatedResultCount; std::string searchPattern; }; diff --git a/src/common/kiwix/xapianSearcher.cpp b/src/common/kiwix/xapianSearcher.cpp index 4270a7bdc..8d377bb42 100644 --- a/src/common/kiwix/xapianSearcher.cpp +++ b/src/common/kiwix/xapianSearcher.cpp @@ -39,7 +39,8 @@ namespace kiwix { } /* Search strings in the database */ - void XapianSearcher::searchInIndex(string &search, const unsigned int resultsCount, const bool verbose) { + void XapianSearcher::searchInIndex(string &search, const unsigned int resultStart, + const unsigned int resultEnd, const bool verbose) { /* Create the query */ Xapian::QueryParser queryParser; Xapian::Query query = queryParser.parse_query(search); @@ -49,7 +50,7 @@ namespace kiwix { enquire.set_query(query); /* Get the results */ - Xapian::MSet matches = enquire.get_mset(0, resultsCount); + Xapian::MSet matches = enquire.get_mset(resultStart, resultEnd - resultStart); Xapian::MSetIterator i; for (i = matches.begin(); i != matches.end(); ++i) { diff --git a/src/common/kiwix/xapianSearcher.h b/src/common/kiwix/xapianSearcher.h index 2c39a5d14..e01283be7 100644 --- a/src/common/kiwix/xapianSearcher.h +++ b/src/common/kiwix/xapianSearcher.h @@ -32,7 +32,8 @@ namespace kiwix { public: XapianSearcher(const string &xapianDirectoryPath); - void searchInIndex(string &search, const unsigned int resultsCount, const bool verbose=false); + void searchInIndex(string &search, const unsigned int resultStart, const unsigned int resultEnd, + const bool verbose=false); protected: void closeIndex(); diff --git a/static/results.tmpl b/static/results.tmpl index 97ce9e3d4..94b97da76 100644 --- a/static/results.tmpl +++ b/static/results.tmpl @@ -95,7 +95,7 @@
- Results 1-20 of for + Results - of for
@@ -113,9 +113,9 @@