From 799a47142bb40e9c9fe89988f3b9f7e8ccbaec28 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 7 Apr 2017 11:24:49 +0200 Subject: [PATCH 1/2] Adapt kiwix-tools to last kiwix-lib API (Xapian in zimlib). --- src/searcher/kiwix-search.cpp | 35 ++++++++++++++--------------------- src/server/kiwix-serve.cpp | 4 ++-- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/searcher/kiwix-search.cpp b/src/searcher/kiwix-search.cpp index 18afcb3..bd53c9c 100644 --- a/src/searcher/kiwix-search.cpp +++ b/src/searcher/kiwix-search.cpp @@ -19,12 +19,11 @@ #include #include -#include - -enum supportedBackend { XAPIAN }; +#include +#include void usage() { - cout << "Usage: kiwix-search [--verbose|-v] [--backend|-b=xapian] INDEX_PATH SEARCH" << endl; + cout << "Usage: kiwix-search [--verbose|-v] ZIM_PATH SEARCH" << endl; exit(1); } @@ -33,21 +32,20 @@ int main(int argc, char **argv) { /* Init the variables */ //const char *indexPath = "/home/itamar/.www.kiwix.org/kiwix/43k0i1j4.default/6d2e587b-d586-dc6a-dc6a-e4ef035a1495d15c.index"; //const char *indexPath = "/home/itamar/testindex"; - const char *indexPath = NULL; + const char *zimPath = NULL; const char *search = NULL; bool verboseFlag = false; int option_index = 0; int c = 0; - supportedBackend backend = XAPIAN; kiwix::Searcher *searcher = NULL; + kiwix::Reader *reader = NULL; /* Argument parsing */ while (42) { static struct option long_options[] = { {"verbose", no_argument, 0, 'v'}, - {"backend", required_argument, 0, 'b'}, {0, 0, 0, 0} }; @@ -58,22 +56,15 @@ int main(int argc, char **argv) { case 'v': verboseFlag = true; break; - case 'b': - if (!strcmp(optarg, "xapian")) { - backend = XAPIAN; - } else { - usage(); - } - break; } } else { if (optind < argc) { - if (indexPath == NULL) { - indexPath = argv[optind++]; + if (zimPath == NULL) { + zimPath = argv[optind++]; } else if (search == NULL) { search = argv[optind++]; } else { - cout << indexPath << endl; + cout << zimPath << endl; usage(); } } else { @@ -83,16 +74,17 @@ int main(int argc, char **argv) { } /* Check if we have enough arguments */ - if (indexPath == NULL || search == NULL) { + if (zimPath == NULL || search == NULL) { usage(); } /* Try to prepare the indexing */ try { /* We will not get the snippets, So we do not need to pass the reader */ - searcher = new kiwix::XapianSearcher(indexPath, NULL); + reader = new kiwix::Reader(zimPath); + searcher = new kiwix::Searcher(reader); } catch (...) { - cerr << "Unable to search through index '" << indexPath << "'." << endl; + cerr << "Unable to search through zim '" << zimPath << "'." << endl; exit(1); } @@ -100,13 +92,14 @@ int main(int argc, char **argv) { if (searcher != NULL) { string searchString(search); searcher->search(searchString, 0, 10); - Result* p_result; + kiwix::Result* p_result; while ( (p_result = searcher->getNextResult()) ) { cout << p_result->get_title() << endl; delete p_result; } delete searcher; + delete reader; // kiwix::XapianSearcher::terminate(); } else { diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 69aa65c..6d4e1bc 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -62,7 +62,7 @@ extern "C" { #include #include #include -#include +#include #include #include #include @@ -860,7 +860,7 @@ int main(int argc, char **argv) { if (!indexPath.empty()) { try { - kiwix::Searcher *searcher = new kiwix::XapianSearcher(indexPath, reader); + kiwix::Searcher *searcher = new kiwix::Searcher(reader); searcher->setProtocolPrefix("/"); searcher->setSearchProtocolPrefix("/search?"); searcher->setContentHumanReadableId(humanReadableId); From 643293c7df608249e4c94b63477d44b447521b2c Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 7 Apr 2017 11:25:17 +0200 Subject: [PATCH 2/2] Try to link with uuid only if xapian is present. --- meson.build | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index dc08a9d..19d86c6 100644 --- a/meson.build +++ b/meson.build @@ -19,7 +19,12 @@ if meson.is_cross_build() and host_machine.system() == 'windows' # xapian doesn't use uuid on windows. uuid_dep = declare_dependency() else - uuid_dep = declare_dependency(link_args:['-luuid', '-lrt']) + xapian_dep = dependency('xapian-core', required : false) + if xapian_dep.found() + uuid_dep = declare_dependency(link_args:['-luuid', '-lrt']) + else + uuid_dep = declare_dependency() + endif endif all_deps = [thread_dep, kiwixlib_dep, microhttpd_dep, z_dep, uuid_dep]