+ fix bug in idx loadin (in case of direct loading - no library file)

This commit is contained in:
kelson42 2012-04-23 19:09:17 +00:00
parent db7281c15f
commit 83d0f749f8

View File

@ -59,6 +59,7 @@ typedef int off_t;
#include <pathTools.h> #include <pathTools.h>
#include <regexTools.h> #include <regexTools.h>
#include <splitString.h> #include <splitString.h>
#include <resourceTools.h>
using namespace std; using namespace std;
@ -234,7 +235,6 @@ static int accessHandlerCallback(void *cls,
if (!strcmp(url, "/search")) { if (!strcmp(url, "/search")) {
const char* tmpGetValue = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "content"); const char* tmpGetValue = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "content");
humanReadableBookId = (tmpGetValue != NULL ? string(tmpGetValue) : ""); humanReadableBookId = (tmpGetValue != NULL ? string(tmpGetValue) : "");
cout << humanReadableBookId << endl;
} else { } else {
humanReadableBookId = urlStr.substr(1, urlStr.find("/", 1) != string::npos ? urlStr.find("/", 1) - 1 : urlStr.size() - 2); humanReadableBookId = urlStr.substr(1, urlStr.find("/", 1) != string::npos ? urlStr.find("/", 1) - 1 : urlStr.size() - 2);
if (!humanReadableBookId.empty()) { if (!humanReadableBookId.empty()) {
@ -477,11 +477,36 @@ int main(int argc, char **argv) {
if (!libraryManager.addBookFromPath(zimPath, zimPath, "", false)) { if (!libraryManager.addBookFromPath(zimPath, zimPath, "", false)) {
cerr << "Unable to add the ZIM file '" << libraryPath << "' to the internal library." << endl; cerr << "Unable to add the ZIM file '" << libraryPath << "' to the internal library." << endl;
exit(1); exit(1);
} else if (!indexPath.empty()) {
vector<string> booksIds = libraryManager.getBooksIds();
kiwix::supportedIndexType indexType = kiwix::UNKNOWN;
bool hasSearchIndex = false;
/* Try with the XapianSearcher */
try {
new kiwix::XapianSearcher(indexPath);
hasSearchIndex = true;
indexType = kiwix::XAPIAN;
} catch (...) {
}
#ifndef _WIN32
/* Try with the CluceneSearcher */
if (!hasSearchIndex) {
try {
new kiwix::CluceneSearcher(indexPath);
indexType = kiwix::CLUCENE;
} catch (...) {
cerr << "Unable to open the search index '" << zimPath << "' neither with the Xapian nor with CLucene." << endl;
exit(1);
}
}
#endif
libraryManager.setBookIndex(booksIds[0], indexPath, indexType);
} }
} }
/* Try to load the result template */
/* Change the current dir to binary dir */ /* Change the current dir to binary dir */
/* Non portable linux solution */ /* Non portable linux solution */
rootPath = getExecutablePath(); rootPath = getExecutablePath();
@ -542,25 +567,20 @@ int main(int argc, char **argv) {
if (indexPath != "") { if (indexPath != "") {
bool hasSearchIndex = false; bool hasSearchIndex = false;
/* Try with the XapianSearcher */ /* Try to load the search */
try { try {
if (currentBook.indexType == kiwix::XAPIAN) {
searcher = new kiwix::XapianSearcher(indexPath); searcher = new kiwix::XapianSearcher(indexPath);
} else if (currentBook.indexType == kiwix::CLUCENE) {
searcher = new kiwix::CluceneSearcher(indexPath);
} else {
throw("Unknown index type");
}
hasSearchIndex = true; hasSearchIndex = true;
} catch (...) { } catch (...) {
cerr << "Unable to open the search index '" << zimPath << "' with the XapianSearcher." << endl; cerr << "Unable to open the search index '" << zimPath << "'." << endl;
} }
#ifndef _WIN32
/* Try with the CluceneSearcher */
if (!hasSearchIndex) {
try {
searcher = new kiwix::CluceneSearcher(indexPath);
} catch (...) {
cerr << "Unable to open the search index '" << zimPath << "' with the CluceneSearcher." << endl;
exit(1);
}
}
#endif
searcher->setProtocolPrefix("/"); searcher->setProtocolPrefix("/");
searcher->setSearchProtocolPrefix("/search"); searcher->setSearchProtocolPrefix("/search");
searcher->setContentHumanReadableId(humanReadableId); searcher->setContentHumanReadableId(humanReadableId);