From cb20e719eeb5a2c5192ea7cc93736fa90e52ac9d Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 21 Mar 2017 16:33:57 +0100 Subject: [PATCH] Update to the new API of kiwix-lib. --- src/searcher/kiwix-search.cpp | 12 ++++++------ src/server/kiwix-serve.cpp | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/searcher/kiwix-search.cpp b/src/searcher/kiwix-search.cpp index d2a1bec..18afcb3 100644 --- a/src/searcher/kiwix-search.cpp +++ b/src/searcher/kiwix-search.cpp @@ -89,7 +89,8 @@ int main(int argc, char **argv) { /* Try to prepare the indexing */ try { - searcher = new kiwix::XapianSearcher(indexPath); + /* We will not get the snippets, So we do not need to pass the reader */ + searcher = new kiwix::XapianSearcher(indexPath, NULL); } catch (...) { cerr << "Unable to search through index '" << indexPath << "'." << endl; exit(1); @@ -99,11 +100,10 @@ int main(int argc, char **argv) { if (searcher != NULL) { string searchString(search); searcher->search(searchString, 0, 10); - string url; - string title; - unsigned int score; - while (searcher->getNextResult(url, title, score)) { - cout << title << endl; + Result* p_result; + while ( (p_result = searcher->getNextResult()) ) { + cout << p_result->get_title() << endl; + delete p_result; } delete searcher; diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 74dcb90..7ccb244 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -396,12 +396,14 @@ struct MHD_Response* handle_search(struct MHD_Connection * connection, /* Get the results */ pthread_mutex_lock(&searcherLock); + pthread_mutex_lock(&readerLock); try { searcher->search(patternString, startNumber, endNumber, isVerbose()); content = searcher->getHtml(); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; } + pthread_mutex_unlock(&readerLock); pthread_mutex_unlock(&searcherLock); } else { content = "\nFulltext search unavailable

Not Found

There is no article with the title \"" + kiwix::encodeDiples(patternString) + "\" and the fulltext search engine is not available for this content.

"; @@ -862,7 +864,7 @@ int main(int argc, char **argv) { if (!indexPath.empty()) { try { - kiwix::Searcher *searcher = new kiwix::XapianSearcher(indexPath); + kiwix::Searcher *searcher = new kiwix::XapianSearcher(indexPath, reader); searcher->setProtocolPrefix("/"); searcher->setSearchProtocolPrefix("/search?"); searcher->setContentHumanReadableId(humanReadableId);