diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 0a61f0ee4..498695220 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -177,8 +177,8 @@ ParameterizedMessage tooManyBooksMsg(size_t nbBooks, size_t limit) { return ParameterizedMessage("too-many-books", { - {"NB_BOOKS", nbBooks}, - {"LIMIT", limit}, + {"NB_BOOKS", beautifyInteger(nbBooks)}, + {"LIMIT", beautifyInteger(limit)}, } ); } diff --git a/test/server.cpp b/test/server.cpp index 2c4ac1ab8..94db3c944 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -133,6 +133,7 @@ void ZimFileServer::run(int serverPort, std::string indexTemplateString) server->setNbThreads(2); server->setVerbose(false); server->setTaskbar(withTaskbar, withTaskbar); + server->setMultiZimSearchLimit(3); if (!indexTemplateString.empty()) { server->setIndexTemplateString(indexTemplateString); } @@ -395,6 +396,10 @@ const char* urls400[] = { "/ROOT/search?content=zimfile", "/ROOT/search?content=non-existing-book&pattern=asdfqwerty", "/ROOT/search?content=non-existing-book&pattern=asd

- No query provided. + Too many books requested (4) where limit is 3

)" }, { /* url */ "/ROOT/search?content=zimfile", @@ -935,15 +940,25 @@ TEST_F(ServerTest, 400WithBodyTesting) )" }, // There is a flaw in our way to handle query string, we cannot differenciate // between `pattern` and `pattern=` - { /* url */ "/ROOT/search?pattern", + { /* url */ "/ROOT/search?books.filter.lang=eng&pattern", expected_body==R"(

Invalid request

- The requested URL "/ROOT/search?pattern=" is not a valid request. + The requested URL "/ROOT/search?books.filter.lang=eng&pattern=" is not a valid request.

No query provided.

+)" }, + { /* url */ "/ROOT/search?pattern=foo", + expected_body==R"( +

Invalid request

+

+ The requested URL "/ROOT/search?pattern=foo" is not a valid request. +

+

+ Too many books requested (4) where limit is 3 +

)" }, }; @@ -2122,6 +2137,7 @@ R"SEARCHRESULT( } }, + // We must return results from the two books { /* query */ "pattern=travel" "&books.id=" RAYCHARLESZIMID @@ -2152,6 +2168,116 @@ R"SEARCHRESULT( /* pagination */ {} }, + // Only RayCharles is in English. + // [TODO] We should extend our test data to have another zim file in english returning results. + { + /* query */ "pattern=travel" + "&books.filter.lang=eng", + /* start */ 0, + /* resultsPerPage */ 10, + /* totalResultCount */ 1, + /* firstResultIndex */ 1, + /* results */ { +R"SEARCHRESULT( + + If You Go Away + + ...Travel On" (1965) "If You Go Away" (1966) "Walk Away" (1967) Damita Jo reached #10 on the Adult Contemporary chart and #68 on the Billboard Hot 100 in 1966 for her version of the song. Terry Jacks recorded a version of the song which was released as a single in 1974 and reached #29 on the Adult Contemporary chart, #68 on the Billboard Hot 100, and went to #8 in the UK. The complex melody is partly derivative of classical music - the poignant "But if you stay..." passage comes from Franz Liszt's...... +
from Ray Charles
+
204 words
+)SEARCHRESULT", + }, + /* pagination */ {} + }, + + // Adding a book (without match) doesn't change the results + { + /* query */ "pattern=jazz" + "&books.id=" RAYCHARLESZIMID + "&books.id=" EXAMPLEZIMID, + /* start */ -1, + /* resultsPerPage */ 100, + /* totalResultCount */ 44, + /* firstResultIndex */ 1, + /* results */ LARGE_SEARCH_RESULTS, + /* pagination */ {} + }, + + { + /* query */ "pattern=jazz" + "&books.filter.lang=eng", + /* start */ -1, + /* resultsPerPage */ 5, + /* totalResultCount */ 44, + /* firstResultIndex */ 1, + /* results */ { + LARGE_SEARCH_RESULTS[0], + LARGE_SEARCH_RESULTS[1], + LARGE_SEARCH_RESULTS[2], + LARGE_SEARCH_RESULTS[3], + LARGE_SEARCH_RESULTS[4], + }, + + /* pagination */ { + { "1", 0, true }, + { "2", 5, false }, + { "3", 10, false }, + { "4", 15, false }, + { "5", 20, false }, + { "▶", 40, false }, + } + }, + + { + /* query */ "pattern=jazz" + "&books.filter.tag=wikipedia", + /* start */ -1, + /* resultsPerPage */ 5, + /* totalResultCount */ 44, + /* firstResultIndex */ 1, + /* results */ { + LARGE_SEARCH_RESULTS[0], + LARGE_SEARCH_RESULTS[1], + LARGE_SEARCH_RESULTS[2], + LARGE_SEARCH_RESULTS[3], + LARGE_SEARCH_RESULTS[4], + }, + + /* pagination */ { + { "1", 0, true }, + { "2", 5, false }, + { "3", 10, false }, + { "4", 15, false }, + { "5", 20, false }, + { "▶", 40, false }, + } + }, + + { + /* query */ "pattern=jazz" + "&books.filter.lang=eng" + "&books.filter.title=Ray%20Charles", + /* start */ -1, + /* resultsPerPage */ 5, + /* totalResultCount */ 44, + /* firstResultIndex */ 1, + /* results */ { + LARGE_SEARCH_RESULTS[0], + LARGE_SEARCH_RESULTS[1], + LARGE_SEARCH_RESULTS[2], + LARGE_SEARCH_RESULTS[3], + LARGE_SEARCH_RESULTS[4], + }, + + /* pagination */ { + { "1", 0, true }, + { "2", 5, false }, + { "3", 10, false }, + { "4", 15, false }, + { "5", 20, false }, + { "▶", 40, false }, + } + }, }; for ( const auto& t : testData ) {