mirror of https://github.com/kiwix/libkiwix.git
`?count=0` OPDS catalog queries return 0 results
... which is a useful way of finding out the total number of results with the least consumption of resources.
This commit is contained in:
parent
340fadd9be
commit
2e0124710a
|
@ -1021,9 +1021,9 @@ InternalServer::search_catalog(const RequestContext& request,
|
|||
const auto filter = get_search_filter(request);
|
||||
std::vector<std::string> 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;
|
||||
|
|
|
@ -377,7 +377,7 @@ TEST_F(LibraryServerTest, catalog_search_results_pagination)
|
|||
);
|
||||
}
|
||||
{
|
||||
// count=0 disables the limit on the number of results
|
||||
// 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),
|
||||
|
@ -387,11 +387,8 @@ TEST_F(LibraryServerTest, catalog_search_results_pagination)
|
|||
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
||||
" <totalResults>3</totalResults>\n"
|
||||
" <startIndex>0</startIndex>\n"
|
||||
" <itemsPerPage>3</itemsPerPage>\n"
|
||||
" <itemsPerPage>0</itemsPerPage>\n"
|
||||
CATALOG_LINK_TAGS
|
||||
CHARLES_RAY_CATALOG_ENTRY
|
||||
RAY_CHARLES_CATALOG_ENTRY
|
||||
UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY
|
||||
"</feed>\n"
|
||||
);
|
||||
}
|
||||
|
@ -695,7 +692,7 @@ TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_range)
|
|||
}
|
||||
|
||||
{
|
||||
// count=0 disables the limit on the number of results
|
||||
// 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),
|
||||
|
@ -704,10 +701,7 @@ TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_range)
|
|||
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
||||
" <totalResults>3</totalResults>\n"
|
||||
" <startIndex>0</startIndex>\n"
|
||||
" <itemsPerPage>3</itemsPerPage>\n"
|
||||
CHARLES_RAY_CATALOG_ENTRY
|
||||
RAY_CHARLES_CATALOG_ENTRY
|
||||
UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY
|
||||
" <itemsPerPage>0</itemsPerPage>\n"
|
||||
"</feed>\n"
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue