From 0081b4d8e7c64eef3d063975546e1e756a824bed Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 23 May 2022 17:06:58 +0200 Subject: [PATCH] Make the limit of zim files per search configurable. The default value is 0, which means no limit. --- include/server.h | 4 +++- src/server.cpp | 1 + src/server/internalServer.cpp | 6 ++++-- src/server/internalServer.h | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/server.h b/include/server.h index b3cd240fd..0cd579c57 100644 --- a/include/server.h +++ b/include/server.h @@ -54,6 +54,7 @@ namespace kiwix void setAddress(const std::string& addr) { m_addr = addr; } void setPort(int port) { m_port = port; } void setNbThreads(int threads) { m_nbThreads = threads; } + void setMultiZimSearchLimit(unsigned int limit) { m_multizimSearchLimit = limit; } void setIpConnectionLimit(int limit) { m_ipConnectionLimit = limit; } void setVerbose(bool verbose) { m_verbose = verbose; } void setIndexTemplateString(const std::string& indexTemplateString) { m_indexTemplateString = indexTemplateString; } @@ -63,7 +64,7 @@ namespace kiwix { m_blockExternalLinks = blockExternalLinks; } int getPort(); std::string getAddress(); - + protected: Library* mp_library; NameMapper* mp_nameMapper; @@ -72,6 +73,7 @@ namespace kiwix std::string m_indexTemplateString = ""; int m_port = 80; int m_nbThreads = 1; + unsigned int m_multizimSearchLimit = 0; bool m_verbose = false; bool m_withTaskbar = true; bool m_withLibraryButton = true; diff --git a/src/server.cpp b/src/server.cpp index 52355afe7..bd478c526 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -45,6 +45,7 @@ bool Server::start() { m_port, m_root, m_nbThreads, + m_multizimSearchLimit, m_verbose, m_withTaskbar, m_withLibraryButton, diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 2025a0380..c4f6fd7cb 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -207,7 +207,7 @@ void checkBookNumber(const Library::BookIdSet& bookIds, size_t limit) { if (bookIds.empty()) { throw Error(nonParameterizedMessage("no-book-found")); } - if (bookIds.size() > limit) { + if (limit > 0 && bookIds.size() > limit) { throw Error(tooManyBooksMsg(bookIds.size(), limit)); } } @@ -269,7 +269,7 @@ Library::BookIdSet InternalServer::selectBooks(const RequestContext& request) co SearchInfo InternalServer::getSearchInfo(const RequestContext& request) const { auto bookIds = selectBooks(request); - checkBookNumber(bookIds, 5); + checkBookNumber(bookIds, m_multizimSearchLimit); auto pattern = request.get_optional_param("pattern", ""); GeoQuery geoQuery; @@ -332,6 +332,7 @@ InternalServer::InternalServer(Library* library, int port, std::string root, int nbThreads, + unsigned int multizimSearchLimit, bool verbose, bool withTaskbar, bool withLibraryButton, @@ -342,6 +343,7 @@ InternalServer::InternalServer(Library* library, m_port(port), m_root(normalizeRootUrl(root)), m_nbThreads(nbThreads), + m_multizimSearchLimit(multizimSearchLimit), m_verbose(verbose), m_withTaskbar(withTaskbar), m_withLibraryButton(withLibraryButton), diff --git a/src/server/internalServer.h b/src/server/internalServer.h index 6200e2564..cd3174189 100644 --- a/src/server/internalServer.h +++ b/src/server/internalServer.h @@ -101,6 +101,7 @@ class InternalServer { int port, std::string root, int nbThreads, + unsigned int multizimSearchLimit, bool verbose, bool withTaskbar, bool withLibraryButton, @@ -156,6 +157,7 @@ class InternalServer { int m_port; std::string m_root; int m_nbThreads; + unsigned int m_multizimSearchLimit; std::atomic_bool m_verbose; bool m_withTaskbar; bool m_withLibraryButton;