Cleared kiwix-search of libkiwix deprecated API

pull/535/head
Veloman Yunkan 4 years ago
parent dd5aa33775
commit 2bb080ee3b

@ -18,11 +18,16 @@
*/ */
#include <getopt.h> #include <getopt.h>
#include <kiwix/reader.h>
#include <kiwix/searcher.h> #include <zim/search.h>
#include <zim/suggestion.h>
#include <iostream>
#include "../version.h" #include "../version.h"
using namespace std;
void usage() void usage()
{ {
cout << "Usage: kiwix-search [OPTIONS] ZIM PATTERN" << endl << endl cout << "Usage: kiwix-search [OPTIONS] ZIM PATTERN" << endl << endl
@ -48,9 +53,6 @@ int main(int argc, char** argv)
int option_index = 0; int option_index = 0;
int c = 0; int c = 0;
kiwix::Searcher* searcher = NULL;
kiwix::Reader* reader = NULL;
/* Argument parsing */ /* Argument parsing */
while (42) { while (42) {
static struct option long_options[] static struct option long_options[]
@ -96,47 +98,24 @@ int main(int argc, char** argv)
/* Try to prepare the indexing */ /* Try to prepare the indexing */
try { try {
reader = new kiwix::Reader(zimPath); zim::Archive archive(zimPath);
} catch (...) {
/* Cannot open the zimPath, maybe it is a plain old xapian database
* directory */
}
if (reader) {
searcher = new kiwix::Searcher();
bool contians_FTIndex=searcher->add_reader(reader);
if(!contians_FTIndex){
std::cerr << "The Zim file does not contain a full-text index." << std::endl;
if(suggestionFlag){
exit(0);
}
exit(1);
}
} else {
cerr << "Unable to search through zim '" << zimPath << "'." << endl;
exit(1);
}
/* Start the indexing */
if (searcher != NULL) {
string searchString(search);
if (suggestionFlag) { if (suggestionFlag) {
searcher->suggestions(searchString, verboseFlag); zim::SuggestionSearcher searcher({archive});
} else { searcher.setVerbose(verboseFlag);
searcher->search(searchString, 0, 10, verboseFlag); for (const auto& r : searcher.suggest(search).getResults(0, 10) ) {
} cout << r.getTitle() << endl;
kiwix::Result* p_result; }
while ((p_result = searcher->getNextResult())) { } else {
cout << p_result->get_title() << endl; zim::Searcher searcher({archive});
delete p_result; searcher.setVerbose(verboseFlag);
const zim::Query query(search);
for (const auto& r : searcher.search(query).getResults(0, 10) ) {
cout << r.getTitle() << endl;
}
} }
} catch ( const std::runtime_error& err) {
delete searcher; cerr << err.what() << endl;
delete reader;
// kiwix::XapianSearcher::terminate();
} else {
cerr << "Unable instanciate the Kiwix searcher." << endl;
exit(1); exit(1);
} }

Loading…
Cancel
Save