mirror of https://github.com/kiwix/libkiwix.git
+ search page navigation
This commit is contained in:
parent
8b291cd219
commit
41217c22d8
|
@ -45,24 +45,29 @@ namespace kiwix {
|
||||||
Document doc;
|
Document doc;
|
||||||
|
|
||||||
/* Not indexed but stored */
|
/* 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));
|
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));
|
doc.add(*_CLNEW Field(_T("url"), buffer, Field::STORE_YES | Field::INDEX_UNTOKENIZED));
|
||||||
|
|
||||||
/* indexed but not stored */
|
/* 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);
|
Field *titleField = new Field(_T("utitle"), buffer, Field::STORE_NO | Field::INDEX_TOKENIZED);
|
||||||
titleField->setBoost(getTitleBoostFactor(content.size()));
|
titleField->setBoost(getTitleBoostFactor(content.size()));
|
||||||
doc.add(*titleField);
|
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);
|
Field *keywordsField = new Field(_T("keywords"), buffer, Field::STORE_NO | Field::INDEX_TOKENIZED);
|
||||||
keywordsField->setBoost(keywordsBoostFactor);
|
keywordsField->setBoost(keywordsBoostFactor);
|
||||||
doc.add(*keywordsField);
|
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));
|
doc.add(*_CLNEW Field(_T("content"), buffer, Field::STORE_NO | Field::INDEX_TOKENIZED));
|
||||||
|
|
||||||
/* Add the document to the index */
|
/* Add the document to the index */
|
||||||
|
|
|
@ -40,10 +40,12 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search strings in the database */
|
/* 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);
|
IndexSearcher searcher(reader);
|
||||||
QueryParser parser(_T("content"), &analyzer);
|
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);
|
Query* query = parser.parse(buffer);
|
||||||
Hits* hits = searcher.search(query);
|
Hits* hits = searcher.search(query);
|
||||||
cout << "--------------------------------" << hits->length() << endl;
|
cout << "--------------------------------" << hits->length() << endl;
|
||||||
|
|
|
@ -41,7 +41,8 @@ namespace kiwix {
|
||||||
public:
|
public:
|
||||||
CluceneSearcher(const string &cluceneDirectoryPath);
|
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:
|
protected:
|
||||||
void closeIndex();
|
void closeIndex();
|
||||||
|
|
|
@ -43,7 +43,8 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search strings in the database */
|
/* 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();
|
this->reset();
|
||||||
|
|
||||||
|
@ -52,7 +53,10 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
|
|
||||||
this->searchPattern = search;
|
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();
|
this->resultOffset = this->results.begin();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -159,10 +163,25 @@ namespace kiwix {
|
||||||
this->resultOffset++;
|
this->resultOffset++;
|
||||||
}
|
}
|
||||||
this->resultOffset = this->results.begin();
|
this->resultOffset = this->results.begin();
|
||||||
|
|
||||||
oData["results"] = resultsCDT;
|
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; i<pageCount; i++) {
|
||||||
|
CDT page;
|
||||||
|
page["start"] = i * this->resultCountPerPage;
|
||||||
|
page["end"] = (i+1) * this->resultCountPerPage;
|
||||||
|
pagesCDT.PushBack(page);
|
||||||
|
}
|
||||||
|
oData["pages"] = pagesCDT;
|
||||||
|
|
||||||
oData["count"] = this->estimatedResultCount;
|
oData["count"] = this->estimatedResultCount;
|
||||||
oData["searchPattern"] = this->searchPattern;
|
oData["searchPattern"] = this->searchPattern;
|
||||||
|
oData["resultStart"] = this->resultStart;
|
||||||
|
oData["resultEnd"] = this->resultEnd;
|
||||||
|
|
||||||
STLW::string sResult;
|
STLW::string sResult;
|
||||||
StringOutputCollector oDataCollector(sResult);
|
StringOutputCollector oDataCollector(sResult);
|
||||||
|
|
|
@ -65,7 +65,8 @@ namespace kiwix {
|
||||||
public:
|
public:
|
||||||
Searcher();
|
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);
|
bool getNextResult(string &url, string &title, unsigned int &score);
|
||||||
unsigned int getEstimatedResultCount();
|
unsigned int getEstimatedResultCount();
|
||||||
bool setResultTemplatePath(const std::string path);
|
bool setResultTemplatePath(const std::string path);
|
||||||
|
@ -75,11 +76,15 @@ namespace kiwix {
|
||||||
protected:
|
protected:
|
||||||
std::string beautifyInteger(const unsigned int number);
|
std::string beautifyInteger(const unsigned int number);
|
||||||
virtual void closeIndex() = 0;
|
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<Result> results;
|
std::vector<Result> results;
|
||||||
std::vector<Result>::iterator resultOffset;
|
std::vector<Result>::iterator resultOffset;
|
||||||
std::string resultTemplatePath;
|
std::string resultTemplatePath;
|
||||||
|
unsigned int resultCountPerPage;
|
||||||
|
unsigned int resultStart;
|
||||||
|
unsigned int resultEnd;
|
||||||
unsigned int estimatedResultCount;
|
unsigned int estimatedResultCount;
|
||||||
std::string searchPattern;
|
std::string searchPattern;
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,7 +39,8 @@ namespace kiwix {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search strings in the database */
|
/* 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 */
|
/* Create the query */
|
||||||
Xapian::QueryParser queryParser;
|
Xapian::QueryParser queryParser;
|
||||||
Xapian::Query query = queryParser.parse_query(search);
|
Xapian::Query query = queryParser.parse_query(search);
|
||||||
|
@ -49,7 +50,7 @@ namespace kiwix {
|
||||||
enquire.set_query(query);
|
enquire.set_query(query);
|
||||||
|
|
||||||
/* Get the results */
|
/* Get the results */
|
||||||
Xapian::MSet matches = enquire.get_mset(0, resultsCount);
|
Xapian::MSet matches = enquire.get_mset(resultStart, resultEnd - resultStart);
|
||||||
|
|
||||||
Xapian::MSetIterator i;
|
Xapian::MSetIterator i;
|
||||||
for (i = matches.begin(); i != matches.end(); ++i) {
|
for (i = matches.begin(); i != matches.end(); ++i) {
|
||||||
|
|
|
@ -32,7 +32,8 @@ namespace kiwix {
|
||||||
public:
|
public:
|
||||||
XapianSearcher(const string &xapianDirectoryPath);
|
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:
|
protected:
|
||||||
void closeIndex();
|
void closeIndex();
|
||||||
|
|
|
@ -95,7 +95,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
Results <b>1-20</b> of <b><TMPL_var count></b> for <b><TMPL_var searchPattern></b>
|
Results <b><TMPL_var resultStart>-<TMPL_var resultEnd></b> of <b><TMPL_var count></b> for <b><TMPL_var searchPattern></b>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="results">
|
<div class="results">
|
||||||
|
@ -113,9 +113,9 @@
|
||||||
|
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a class="selected" href="asdf">1</a></li>
|
<TMPL_loop pages>
|
||||||
<li><a>2</a></li>
|
<li><a class="selected" href="http://search/<TMPL_var searchPattern>/<TMPL_var start>/<TMPL_var end>"><TMPL_var __COUNTER__></a></li>
|
||||||
<li><a>3</a></li>
|
</TMPL_LOOP>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue