mirror of https://github.com/kiwix/libkiwix.git
+ stub of Clucene search code (still does not work)
This commit is contained in:
parent
92aec4e612
commit
e7923b75e9
|
@ -0,0 +1,47 @@
|
|||
#include "cluceneSearcher.h"
|
||||
|
||||
namespace kiwix {
|
||||
|
||||
/* Constructor */
|
||||
CluceneSearcher::CluceneSearcher(const string &cluceneDirectoryPath)
|
||||
: kiwix::Searcher() {
|
||||
this->openIndex(cluceneDirectoryPath);
|
||||
}
|
||||
|
||||
/* Open Clucene readable database */
|
||||
void CluceneSearcher::openIndex(const string &directoryPath) {
|
||||
this->reader = IndexReader::open(directoryPath.c_str());
|
||||
}
|
||||
|
||||
/* Close Clucene writable database */
|
||||
void CluceneSearcher::closeIndex() {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Search strings in the database */
|
||||
void CluceneSearcher::searchInIndex(string &search, const unsigned int resultsCount) {
|
||||
IndexSearcher searcher(reader);
|
||||
SimpleAnalyzer analyzer;
|
||||
QueryParser parser(_T("content"), &analyzer);
|
||||
Query* query = parser.parse((const wchar_t*)search.c_str());
|
||||
Hits* hits = searcher.search(query);
|
||||
|
||||
for (size_t i=0; i < hits->length() && i<10; i++) {
|
||||
Document* d = &hits->doc(i);
|
||||
_tprintf(_T("#%d. %s (score: %f)\n"),
|
||||
i, d->get(_T("contents")),
|
||||
hits->score(i));
|
||||
}
|
||||
|
||||
/*
|
||||
Result result;
|
||||
result.url = doc.get_data();
|
||||
result.title = doc.get_value(0);
|
||||
result.score = i.get_percent();
|
||||
|
||||
this->results.push_back(result);
|
||||
*/
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef KIWIX_CLUCENE_SEARCHER_H
|
||||
#define KIWIX_CLUCENE_SEARCHER_H
|
||||
|
||||
#include <CLucene.h>
|
||||
#include <CLucene/queryParser/MultiFieldQueryParser.h>
|
||||
#include "searcher.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace lucene::analysis;
|
||||
using namespace lucene::index;
|
||||
using namespace lucene::document;
|
||||
using namespace lucene::queryParser;
|
||||
using namespace lucene::search;
|
||||
using namespace lucene::store;
|
||||
|
||||
namespace kiwix {
|
||||
|
||||
class CluceneSearcher : public Searcher {
|
||||
|
||||
public:
|
||||
CluceneSearcher(const string &cluceneDirectoryPath);
|
||||
|
||||
void searchInIndex(string &search, const unsigned int resultsCount);
|
||||
|
||||
protected:
|
||||
void closeIndex();
|
||||
void openIndex(const string &cluceneDirectoryPath);
|
||||
|
||||
IndexReader* reader;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -15,7 +15,7 @@ namespace kiwix {
|
|||
cout << "Performing query `" << search << "'" << endl;
|
||||
}
|
||||
|
||||
searchInIndex(search, resultsCount);
|
||||
searchInIndex(removeAccents(search), resultsCount);
|
||||
|
||||
this->resultOffset = this->results.begin();
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace kiwix {
|
|||
void XapianSearcher::searchInIndex(string &search, const unsigned int resultsCount) {
|
||||
/* Create the query */
|
||||
Xapian::QueryParser queryParser;
|
||||
Xapian::Query query = queryParser.parse_query(removeAccents(search));
|
||||
Xapian::Query query = queryParser.parse_query(search);
|
||||
|
||||
/* Create the enquire object */
|
||||
Xapian::Enquire enquire(this->readableDatabase);
|
||||
|
|
Loading…
Reference in New Issue