Do not handle external index.

Now that kiwix-lib do not handle external index, we must not try to handle
it ourselves.

See kiwix/kiwix-lib#190.
Fix #245
This commit is contained in:
Matthieu Gautier 2019-01-08 16:20:57 +01:00
parent 9ed3fc353b
commit 3c8da8c74c
3 changed files with 7 additions and 61 deletions

View File

@ -44,7 +44,6 @@ void show(kiwix::Library* library)
std::cout << "#" << inc++ << std::endl std::cout << "#" << inc++ << std::endl
<< "id:\t\t" << book.getId() << std::endl << "id:\t\t" << book.getId() << std::endl
<< "path:\t\t" << book.getPath() << std::endl << "path:\t\t" << book.getPath() << std::endl
<< "indexpath:\t" << book.getIndexPath() << std::endl
<< "url:\t\t" << book.getUrl() << std::endl << "url:\t\t" << book.getUrl() << std::endl
<< "title:\t\t" << book.getTitle() << std::endl << "title:\t\t" << book.getTitle() << std::endl
<< "name:\t\t" << book.getName() << std::endl << "name:\t\t" << book.getName() << std::endl
@ -64,7 +63,7 @@ void usage()
cerr << "Usage:" << endl; cerr << "Usage:" << endl;
cerr << "\tkiwix-manage LIBRARY_PATH add ZIM_PATH " cerr << "\tkiwix-manage LIBRARY_PATH add ZIM_PATH "
"[--zimPathToSave=../content/foobar.zim] [--current] " "[--zimPathToSave=../content/foobar.zim] [--current] "
"[--indexPath=FULLTEXT_IDX_PATH] [--url=http://...metalink]" "[--url=http://...metalink]"
<< endl; << endl;
cerr << "\tkiwix-manage LIBRARY_PATH show [CONTENTID1] [CONTENTID2] ... " cerr << "\tkiwix-manage LIBRARY_PATH show [CONTENTID1] [CONTENTID2] ... "
"(show everything if no param.)" "(show everything if no param.)"
@ -85,7 +84,6 @@ bool handle_add(kiwix::Library* library, const std::string& libraryPath,
{ {
string zimPath; string zimPath;
string zimPathToSave = "."; string zimPathToSave = ".";
string indexPath;
string url; string url;
string origID = ""; string origID = "";
int option_index = 0; int option_index = 0;
@ -102,11 +100,10 @@ bool handle_add(kiwix::Library* library, const std::string& libraryPath,
static struct option long_options[] static struct option long_options[]
= {{"url", required_argument, 0, 'u'}, = {{"url", required_argument, 0, 'u'},
{"origId", required_argument, 0, 'o'}, {"origId", required_argument, 0, 'o'},
{"indexPath", required_argument, 0, 'i'},
{"zimPathToSave", required_argument, 0, 'z'}, {"zimPathToSave", required_argument, 0, 'z'},
{0, 0, 0, 0}}; {0, 0, 0, 0}};
c = getopt_long(argc, argv, "cz:u:i:", long_options, &option_index); c = getopt_long(argc, argv, "cz:u:", long_options, &option_index);
if (c != -1) { if (c != -1) {
switch (c) { switch (c) {
@ -118,10 +115,6 @@ bool handle_add(kiwix::Library* library, const std::string& libraryPath,
origID = optarg; origID = optarg;
break; break;
case 'i':
indexPath = optarg;
break;
case 'z': case 'z':
zimPathToSave = optarg; zimPathToSave = optarg;
break; break;
@ -134,21 +127,7 @@ bool handle_add(kiwix::Library* library, const std::string& libraryPath,
if (!zimPath.empty()) { if (!zimPath.empty()) {
kiwix::Manager manager(library); kiwix::Manager manager(library);
zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave; zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave;
string bookId = manager.addBookFromPathAndGetId( manager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, false);
zimPath, zimPathToSave, url, false);
if (!bookId.empty()) {
/* Save the index infos if necessary */
if (!indexPath.empty()) {
if (isRelativePath(indexPath)) {
indexPath = computeAbsolutePath(indexPath, getCurrentDirectory());
}
library->getBookById(bookId).setIndexPath(indexPath);
}
} else {
cerr << "Unable to build or save library file '" << libraryPath << "'"
<< endl;
resultCode = 1;
}
} else { } else {
std::cerr << "Invalid zim file path" << std::endl; std::cerr << "Invalid zim file path" << std::endl;
resultCode = 1; resultCode = 1;

View File

@ -27,8 +27,7 @@ void usage()
{ {
cout << "Usage: kiwix-search [OPTIONS] ZIM PATTERN" << endl << endl cout << "Usage: kiwix-search [OPTIONS] ZIM PATTERN" << endl << endl
<< " kiwix-search allows to find articles based on the a fulltext search pattern." << endl << endl << " kiwix-search allows to find articles based on the a fulltext search pattern." << endl << endl
<< " ZIM is the full path of the ZIM file. This can also be a disctinct fulltext" << endl << " ZIM is the full path of the ZIM file." << endl
<< " index directory (usually distributed with the *.idx extension)." << endl
<< " PATTERN is/are word(s) - or part of - to search in the ZIM." << endl << endl << " PATTERN is/are word(s) - or part of - to search in the ZIM." << endl << endl
<< " -s, --suggestion\tSuggest article titles based on the few letters of the PATTERN instead of making a fulltext search. Work a bit like a completion solution." << endl << " -s, --suggestion\tSuggest article titles based on the few letters of the PATTERN instead of making a fulltext search. Work a bit like a completion solution." << endl
<< " -v, --verbose\t\tGive details about the search process" << endl; << " -v, --verbose\t\tGive details about the search process" << endl;
@ -102,12 +101,8 @@ int main(int argc, char** argv)
searcher = new kiwix::Searcher(); searcher = new kiwix::Searcher();
searcher->add_reader(reader, ""); searcher->add_reader(reader, "");
} else { } else {
try { cerr << "Unable to search through zim '" << zimPath << "'." << endl;
searcher = new kiwix::Searcher(zimPath, NULL, ""); exit(1);
} catch (...) {
cerr << "Unable to search through zim '" << zimPath << "'." << endl;
exit(1);
}
} }
/* Start the indexing */ /* Start the indexing */

View File

@ -914,7 +914,6 @@ int main(int argc, char** argv)
struct MHD_Daemon* daemon; struct MHD_Daemon* daemon;
vector<string> zimPathes; vector<string> zimPathes;
string libraryPath; string libraryPath;
string indexPath;
string rootPath; string rootPath;
string interface; string interface;
int serverPort = 80; int serverPort = 80;
@ -930,7 +929,6 @@ int main(int argc, char** argv)
{"library", no_argument, 0, 'l'}, {"library", no_argument, 0, 'l'},
{"nolibrarybutton", no_argument, 0, 'm'}, {"nolibrarybutton", no_argument, 0, 'm'},
{"nosearchbar", no_argument, 0, 'n'}, {"nosearchbar", no_argument, 0, 'n'},
{"index", required_argument, 0, 'i'},
{"attachToProcess", required_argument, 0, 'a'}, {"attachToProcess", required_argument, 0, 'a'},
{"port", required_argument, 0, 'p'}, {"port", required_argument, 0, 'p'},
{"interface", required_argument, 0, 'f'}, {"interface", required_argument, 0, 'f'},
@ -942,7 +940,7 @@ int main(int argc, char** argv)
while (true) { while (true) {
int option_index = 0; int option_index = 0;
int c int c
= getopt_long(argc, argv, "mndvli:a:p:f:t:r:", long_options, &option_index); = getopt_long(argc, argv, "mndvla:p:f:t:r:", long_options, &option_index);
if (c != -1) { if (c != -1) {
switch (c) { switch (c) {
@ -961,9 +959,6 @@ int main(int argc, char** argv)
case 'm': case 'm':
noLibraryButtonFlag = true; noLibraryButtonFlag = true;
break; break;
case 'i':
indexPath = optarg;
break;
case 'p': case 'p':
serverPort = atoi(optarg); serverPort = atoi(optarg);
break; break;
@ -1024,11 +1019,6 @@ int main(int argc, char** argv)
exit(1); exit(1);
} }
if ((zimPathes.size() > 1) && !indexPath.empty()) {
cerr << "You cannot set a indexPath if you also set several zimPathes";
exit(1);
}
/* Setup the library manager and get the list of books */ /* Setup the library manager and get the list of books */
kiwix::Manager manager(&library); kiwix::Manager manager(&library);
if (libraryFlag) { if (libraryFlag) {
@ -1071,12 +1061,6 @@ int main(int argc, char** argv)
exit(1); exit(1);
} }
} }
if (!indexPath.empty()) {
if (isRelativePath(indexPath)) {
indexPath = computeAbsolutePath(indexPath, getCurrentDirectory());
}
library.getBookById(library.getBooksIds()[0]).setIndexPath(indexPath);
}
} }
/* Instance the readers and searcher and build the corresponding maps */ /* Instance the readers and searcher and build the corresponding maps */
@ -1087,7 +1071,6 @@ int main(int argc, char** argv)
for (auto& bookId: booksIds) { for (auto& bookId: booksIds) {
auto& currentBook = library.getBookById(bookId); auto& currentBook = library.getBookById(bookId);
auto zimPath = currentBook.getPath(); auto zimPath = currentBook.getPath();
auto indexPath = currentBook.getIndexPath();
/* Instanciate the ZIM file handler */ /* Instanciate the ZIM file handler */
kiwix::Reader* reader = NULL; kiwix::Reader* reader = NULL;
@ -1108,17 +1091,6 @@ int main(int argc, char** argv)
searcher->add_reader(reader, humanReadableId); searcher->add_reader(reader, humanReadableId);
globalSearcher->add_reader(reader, humanReadableId); globalSearcher->add_reader(reader, humanReadableId);
searchers[humanReadableId] = searcher; searchers[humanReadableId] = searcher;
} else if ( !indexPath.empty() ) {
try {
kiwix::Searcher* searcher = new kiwix::Searcher(indexPath, reader, humanReadableId);
searcher->setProtocolPrefix(rootLocation + "/");
searcher->setSearchProtocolPrefix(rootLocation + "/" + "search?");
searchers[humanReadableId] = searcher;
} catch (...) {
cerr << "Unable to open the search index '" << indexPath << "'."
<< endl;
searchers[humanReadableId] = nullptr;
}
} else { } else {
searchers[humanReadableId] = nullptr; searchers[humanReadableId] = nullptr;
} }