mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-26 10:11:30 +00:00
Do not create all the results at once. Be a bit lazy.
We don't need to generate a vector of result when we do a search. We better to just keep the handle to the current MSetIterator and generate the wanted values when needed.
This commit is contained in:
@ -35,14 +35,16 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct Result
|
||||
class Result
|
||||
{
|
||||
string url;
|
||||
string title;
|
||||
int score;
|
||||
string snippet;
|
||||
int wordCount;
|
||||
int size;
|
||||
public:
|
||||
virtual ~Result() {};
|
||||
virtual std::string get_url() = 0;
|
||||
virtual std::string get_title() = 0;
|
||||
virtual int get_score() = 0;
|
||||
virtual std::string get_snippet() = 0;
|
||||
virtual int get_wordCount() = 0;
|
||||
virtual int get_size() = 0;
|
||||
};
|
||||
|
||||
namespace kiwix {
|
||||
@ -55,7 +57,8 @@ namespace kiwix {
|
||||
|
||||
void search(std::string &search, unsigned int resultStart,
|
||||
unsigned int resultEnd, const bool verbose=false);
|
||||
bool getNextResult(string &url, string &title, unsigned int &score);
|
||||
virtual Result* getNextResult() = 0;
|
||||
virtual void restart_search() = 0;
|
||||
unsigned int getEstimatedResultCount();
|
||||
bool setProtocolPrefix(const std::string prefix);
|
||||
bool setSearchProtocolPrefix(const std::string prefix);
|
||||
@ -72,8 +75,6 @@ namespace kiwix {
|
||||
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>::iterator resultOffset;
|
||||
std::string searchPattern;
|
||||
std::string protocolPrefix;
|
||||
std::string searchProtocolPrefix;
|
||||
|
@ -27,6 +27,23 @@ using namespace std;
|
||||
|
||||
namespace kiwix {
|
||||
|
||||
class XapianResult : public Result {
|
||||
public:
|
||||
XapianResult(Xapian::MSetIterator& iterator);
|
||||
virtual ~XapianResult() {};
|
||||
|
||||
virtual std::string get_url();
|
||||
virtual std::string get_title();
|
||||
virtual int get_score();
|
||||
virtual std::string get_snippet();
|
||||
virtual int get_wordCount();
|
||||
virtual int get_size();
|
||||
|
||||
private:
|
||||
Xapian::MSetIterator iterator;
|
||||
Xapian::Document document;
|
||||
};
|
||||
|
||||
class NoXapianIndexInZim: public exception {
|
||||
virtual const char* what() const throw() {
|
||||
return "There is no fulltext index in the zim file";
|
||||
@ -40,6 +57,8 @@ namespace kiwix {
|
||||
virtual ~XapianSearcher() {};
|
||||
void searchInIndex(string &search, const unsigned int resultStart, const unsigned int resultEnd,
|
||||
const bool verbose=false);
|
||||
virtual Result* getNextResult();
|
||||
void restart_search();
|
||||
|
||||
protected:
|
||||
void closeIndex();
|
||||
@ -47,6 +66,8 @@ namespace kiwix {
|
||||
|
||||
Xapian::Database readableDatabase;
|
||||
Xapian::Stem stemmer;
|
||||
Xapian::MSet results;
|
||||
Xapian::MSetIterator current_result;
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user