mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-26 13:50:33 -04:00
Use a globalSearcher to do multi search on all zims.
This commit is contained in:
parent
5f0a05e8d8
commit
558a0375b0
@ -92,6 +92,7 @@ static bool verboseFlag = false;
|
|||||||
static std::map<std::string, std::string> extMimeTypes;
|
static std::map<std::string, std::string> extMimeTypes;
|
||||||
static std::map<std::string, kiwix::Reader*> readers;
|
static std::map<std::string, kiwix::Reader*> readers;
|
||||||
static std::map<std::string, kiwix::Searcher*> searchers;
|
static std::map<std::string, kiwix::Searcher*> searchers;
|
||||||
|
static kiwix::Searcher* globalSearcher = nullptr;
|
||||||
static pthread_mutex_t zimLock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t zimLock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static pthread_mutex_t mapLock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t mapLock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
static pthread_mutex_t welcomeLock = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t welcomeLock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
@ -417,7 +418,7 @@ static struct MHD_Response* handle_search(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Make the search */
|
/* Make the search */
|
||||||
if (patternCorrespondingUrl.empty() && searcher != NULL) {
|
if (searcher != NULL) {
|
||||||
const char* start = MHD_lookup_connection_value(
|
const char* start = MHD_lookup_connection_value(
|
||||||
connection, MHD_GET_ARGUMENT_KIND, "start");
|
connection, MHD_GET_ARGUMENT_KIND, "start");
|
||||||
const char* end
|
const char* end
|
||||||
@ -674,7 +675,7 @@ static int accessHandlerCallback(void* cls,
|
|||||||
kiwix::Searcher* searcher
|
kiwix::Searcher* searcher
|
||||||
= searchers.find(humanReadableBookId) != searchers.end()
|
= searchers.find(humanReadableBookId) != searchers.end()
|
||||||
? searchers.find(humanReadableBookId)->second
|
? searchers.find(humanReadableBookId)->second
|
||||||
: NULL;
|
: globalSearcher;
|
||||||
kiwix::Reader* reader = readers.find(humanReadableBookId) != readers.end()
|
kiwix::Reader* reader = readers.find(humanReadableBookId) != readers.end()
|
||||||
? readers.find(humanReadableBookId)->second
|
? readers.find(humanReadableBookId)->second
|
||||||
: NULL;
|
: NULL;
|
||||||
@ -906,6 +907,9 @@ int main(int argc, char** argv)
|
|||||||
vector<string> booksIds = libraryManager.getBooksIds();
|
vector<string> booksIds = libraryManager.getBooksIds();
|
||||||
vector<string>::iterator itr;
|
vector<string>::iterator itr;
|
||||||
kiwix::Book currentBook;
|
kiwix::Book currentBook;
|
||||||
|
globalSearcher = new kiwix::Searcher();
|
||||||
|
globalSearcher->setProtocolPrefix("/");
|
||||||
|
globalSearcher->setSearchProtocolPrefix("/search?");
|
||||||
for (itr = booksIds.begin(); itr != booksIds.end(); ++itr) {
|
for (itr = booksIds.begin(); itr != booksIds.end(); ++itr) {
|
||||||
bool zimFileOk = false;
|
bool zimFileOk = false;
|
||||||
libraryManager.getBookById(*itr, currentBook);
|
libraryManager.getBookById(*itr, currentBook);
|
||||||
@ -927,14 +931,12 @@ int main(int argc, char** argv)
|
|||||||
string humanReadableId = currentBook.getHumanReadableIdFromPath();
|
string humanReadableId = currentBook.getHumanReadableIdFromPath();
|
||||||
readers[humanReadableId] = reader;
|
readers[humanReadableId] = reader;
|
||||||
|
|
||||||
/* Try to instanciate the zim index.
|
if ( reader->hasFulltextIndex()) {
|
||||||
* If there is no specified indexPath, try to open the
|
kiwix::Searcher* searcher = new kiwix::Searcher();
|
||||||
* embedded index in the zim. */
|
searcher->add_reader(reader, humanReadableId);
|
||||||
if (indexPath.empty() && reader->hasFulltextIndex()) {
|
globalSearcher->add_reader(reader, humanReadableId);
|
||||||
indexPath = zimPath;
|
searchers[humanReadableId] = searcher;
|
||||||
}
|
} else if ( !indexPath.empty() ) {
|
||||||
|
|
||||||
if (!indexPath.empty()) {
|
|
||||||
try {
|
try {
|
||||||
kiwix::Searcher* searcher = new kiwix::Searcher(indexPath, reader);
|
kiwix::Searcher* searcher = new kiwix::Searcher(indexPath, reader);
|
||||||
searcher->setProtocolPrefix("/");
|
searcher->setProtocolPrefix("/");
|
||||||
@ -1141,6 +1143,8 @@ int main(int argc, char** argv)
|
|||||||
kiwix::sleep(1000);
|
kiwix::sleep(1000);
|
||||||
} while (waiting);
|
} while (waiting);
|
||||||
|
|
||||||
|
delete globalSearcher;
|
||||||
|
|
||||||
/* Stop the daemon */
|
/* Stop the daemon */
|
||||||
MHD_stop_daemon(daemon);
|
MHD_stop_daemon(daemon);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user