diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index b50c6e650..89b2efb13 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -1021,9 +1021,9 @@ InternalServer::search_catalog(const RequestContext& request, const auto filter = get_search_filter(request); std::vector bookIdsToDump = mp_library->filter(filter); const auto totalResults = bookIdsToDump.size(); - const size_t count = request.get_optional_param("count", 10UL); + const long count = request.get_optional_param("count", 10L); const size_t startIndex = request.get_optional_param("start", 0UL); - const size_t intendedCount = count > 0 ? count : bookIdsToDump.size(); + const size_t intendedCount = count >= 0 ? count : bookIdsToDump.size(); bookIdsToDump = subrange(bookIdsToDump, startIndex, intendedCount); opdsDumper.setOpenSearchInfo(totalResults, startIndex, bookIdsToDump.size()); return bookIdsToDump; diff --git a/test/library_server.cpp b/test/library_server.cpp index 5c0d65b1f..723d0c60c 100644 --- a/test/library_server.cpp +++ b/test/library_server.cpp @@ -358,6 +358,26 @@ TEST_F(LibraryServerTest, catalog_search_by_language) TEST_F(LibraryServerTest, catalog_search_results_pagination) { { + // count=-1 disables the limit on the number of results + const auto r = zfs1_->GET("/ROOT%23%3F/catalog/search?count=-1"); + EXPECT_EQ(r->status, 200); + EXPECT_EQ(maskVariableOPDSFeedData(r->body), + OPDS_FEED_TAG + " 12345678-90ab-cdef-1234-567890abcdef\n" + " Filtered zims (count=-1)\n" + " YYYY-MM-DDThh:mm:ssZ\n" + " 3\n" + " 0\n" + " 3\n" + CATALOG_LINK_TAGS + CHARLES_RAY_CATALOG_ENTRY + RAY_CHARLES_CATALOG_ENTRY + UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY + "\n" + ); + } + { + // count=0 returns 0 results const auto r = zfs1_->GET("/ROOT%23%3F/catalog/search?count=0"); EXPECT_EQ(r->status, 200); EXPECT_EQ(maskVariableOPDSFeedData(r->body), @@ -367,11 +387,8 @@ TEST_F(LibraryServerTest, catalog_search_results_pagination) " YYYY-MM-DDThh:mm:ssZ\n" " 3\n" " 0\n" - " 3\n" + " 0\n" CATALOG_LINK_TAGS - CHARLES_RAY_CATALOG_ENTRY - RAY_CHARLES_CATALOG_ENTRY - UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY "\n" ); } @@ -656,6 +673,39 @@ TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_range) ); } + { + // count=-1 disables the limit on the number of results + const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?count=-1"); + EXPECT_EQ(r->status, 200); + EXPECT_EQ(maskVariableOPDSFeedData(r->body), + CATALOG_V2_ENTRIES_PREAMBLE("?count=-1") + " Filtered Entries (count=-1)\n" + " YYYY-MM-DDThh:mm:ssZ\n" + " 3\n" + " 0\n" + " 3\n" + CHARLES_RAY_CATALOG_ENTRY + RAY_CHARLES_CATALOG_ENTRY + UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY + "\n" + ); + } + + { + // count=0 returns 0 results + const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?count=0"); + EXPECT_EQ(r->status, 200); + EXPECT_EQ(maskVariableOPDSFeedData(r->body), + CATALOG_V2_ENTRIES_PREAMBLE("?count=0") + " Filtered Entries (count=0)\n" + " YYYY-MM-DDThh:mm:ssZ\n" + " 3\n" + " 0\n" + " 0\n" + "\n" + ); + } + { const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?count=2"); EXPECT_EQ(r->status, 200);