Class Searcher

Class Documentation

class kiwix::Searcher

The Searcher class is reponsible to do different kind of search using the fulltext index.

Public Functions

Searcher()

The default constructor.

~Searcher()
bool add_reader(Reader *reader)

Add a reader (containing embedded fulltext index) to the search.

Parameters

reader – The Reader for the zim containing the fulltext index.

Returns

true if the reader has been added. false if the reader cannot be added (no embedded fulltext index present)

Reader *get_reader(int index)
void search(const std::string &search, unsigned int resultStart, unsigned int maxResultCount, const bool verbose = false)

Start a search on the zim associated to the Searcher.

Search results should be retrived using the getNextResult method.

Parameters
  • search – The search query.

  • resultStart – the start offset of the search results (used for pagination).

  • maxResultCount – Maximum results to get from start (used for pagination).

  • verbose – print some info on stdout if true.

void geo_search(float latitude, float longitude, float distance, unsigned int resultStart, unsigned int maxResultCount, const bool verbose = false)

Start a geographique search. The search return result for entry in a disc of center latitude/longitude and radius distance.

Search results should be retrived using the getNextResult method.

Parameters
  • latitude – The latitude of the center point.

  • longitude – The longitude of the center point.

  • distance – The radius of the disc.

  • resultStart – the start offset of the search results (used for pagination).

  • maxResultCount – Maximum number of results to get from start (used for pagination).

  • verbose – print some info on stdout if true.

void suggestions(std::string &search, const bool verbose = false)

Start a suggestion search. The search made depend of the “version” of the embedded index.

  • If the index is newer enough and have a title namespace, the search is made in the titles only.

  • Else the search is made on the whole article content. In any case, the search is made “partial” (as adding ‘*’ at the end of the query)

Parameters
  • search – The search query.

  • verbose – print some info on stdout if true.

Result *getNextResult()

Get the next result of a started search. This is the method to use to loop hover the search results.

void restart_search()

Restart the previous search. Next call to getNextResult will return the first result.

unsigned int getEstimatedResultCount()

Get a estimation of the result count.

zim::SearchResultSet getSearchResultSet()

Get a SearchResultSet object for current search

inline unsigned int getResultStart()
inline unsigned int getMaxResultCount()

Protected Functions

std::string beautifyInteger(const unsigned int number)
void closeIndex()
void searchInIndex(string &search, const unsigned int resultStart, const unsigned int maxResultCount, const bool verbose = false)

Protected Attributes

std::vector<Reader*> readers
std::unique_ptr<SearcherInternal> internal
std::unique_ptr<SuggestionInternal> suggestionInternal
std::string searchPattern
unsigned int estimatedResultCount
unsigned int resultStart
unsigned int maxResultCount