Merge pull request #302 from kiwix/adapt_to_new_book_filter

Adapt kiwix-serve to the new api to filter library.
This commit is contained in:
Matthieu Gautier 2019-06-27 09:55:50 +02:00 committed by GitHub
commit fc5572f495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -694,8 +694,7 @@ static struct MHD_Response* handle_catalog(RequestContext* request)
opdsDumper.setTitle("All zims");
uuid = zim::Uuid::generate(host);
bookIdsToDump = library.listBooksIds(
kiwix::VALID|kiwix::LOCAL|kiwix::REMOTE);
bookIdsToDump = library.filter(kiwix::Filter().valid(true).local(true).remote(true));
} else if (url == "search") {
std::string query;
std::string language;
@ -719,14 +718,11 @@ static struct MHD_Response* handle_catalog(RequestContext* request)
} catch (...) {}
opdsDumper.setTitle("Search result for " + query);
uuid = zim::Uuid::generate();
bookIdsToDump = library.listBooksIds(
kiwix::VALID|kiwix::LOCAL|kiwix::REMOTE,
kiwix::UNSORTED,
query,
language,
"", // creator
"", // publisher
tags);
bookIdsToDump = library.filter(
kiwix::Filter().valid(true).local(true).remote(true)
.query(query)
.lang(language)
.acceptTags(tags));
auto totalResults = bookIdsToDump.size();
bookIdsToDump.erase(bookIdsToDump.begin(), bookIdsToDump.begin()+startIndex);
if (count>0 && bookIdsToDump.size() > count) {
@ -1118,7 +1114,7 @@ int main(int argc, char** argv)
}
/* Instance the readers and searcher and build the corresponding maps */
vector<string> booksIds = library.listBooksIds(kiwix::LOCAL);
vector<string> booksIds = library.filter(kiwix::Filter().local(true));
globalSearcher = new kiwix::Searcher();
globalSearcher->setProtocolPrefix(rootLocation + "/");
globalSearcher->setSearchProtocolPrefix(rootLocation + "/" + "search?");