Update to the new API of kiwix-lib.

This commit is contained in:
Matthieu Gautier 2017-03-21 16:33:57 +01:00
parent a3a0127edb
commit cb20e719ee
2 changed files with 9 additions and 7 deletions

View File

@ -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;

View File

@ -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 = "<!DOCTYPE html>\n<html><head><meta content=\"text/html;charset=UTF-8\" http-equiv=\"content-type\" /><title>Fulltext search unavailable</title></head><body><h1>Not Found</h1><p>There is no article with the title <b>\"" + kiwix::encodeDiples(patternString) + "\"</b> and the fulltext search engine is not available for this content.</p></body></html>";
@ -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);