mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #894 from kiwix/zerocount_catalog_query
This commit is contained in:
commit
595817852d
|
@ -1021,9 +1021,9 @@ InternalServer::search_catalog(const RequestContext& request,
|
||||||
const auto filter = get_search_filter(request);
|
const auto filter = get_search_filter(request);
|
||||||
std::vector<std::string> bookIdsToDump = mp_library->filter(filter);
|
std::vector<std::string> bookIdsToDump = mp_library->filter(filter);
|
||||||
const auto totalResults = bookIdsToDump.size();
|
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 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);
|
bookIdsToDump = subrange(bookIdsToDump, startIndex, intendedCount);
|
||||||
opdsDumper.setOpenSearchInfo(totalResults, startIndex, bookIdsToDump.size());
|
opdsDumper.setOpenSearchInfo(totalResults, startIndex, bookIdsToDump.size());
|
||||||
return bookIdsToDump;
|
return bookIdsToDump;
|
||||||
|
|
|
@ -358,6 +358,26 @@ TEST_F(LibraryServerTest, catalog_search_by_language)
|
||||||
TEST_F(LibraryServerTest, catalog_search_results_pagination)
|
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
|
||||||
|
" <id>12345678-90ab-cdef-1234-567890abcdef</id>\n"
|
||||||
|
" <title>Filtered zims (count=-1)</title>\n"
|
||||||
|
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
||||||
|
" <totalResults>3</totalResults>\n"
|
||||||
|
" <startIndex>0</startIndex>\n"
|
||||||
|
" <itemsPerPage>3</itemsPerPage>\n"
|
||||||
|
CATALOG_LINK_TAGS
|
||||||
|
CHARLES_RAY_CATALOG_ENTRY
|
||||||
|
RAY_CHARLES_CATALOG_ENTRY
|
||||||
|
UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY
|
||||||
|
"</feed>\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// count=0 returns 0 results
|
||||||
const auto r = zfs1_->GET("/ROOT%23%3F/catalog/search?count=0");
|
const auto r = zfs1_->GET("/ROOT%23%3F/catalog/search?count=0");
|
||||||
EXPECT_EQ(r->status, 200);
|
EXPECT_EQ(r->status, 200);
|
||||||
EXPECT_EQ(maskVariableOPDSFeedData(r->body),
|
EXPECT_EQ(maskVariableOPDSFeedData(r->body),
|
||||||
|
@ -367,11 +387,8 @@ TEST_F(LibraryServerTest, catalog_search_results_pagination)
|
||||||
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
||||||
" <totalResults>3</totalResults>\n"
|
" <totalResults>3</totalResults>\n"
|
||||||
" <startIndex>0</startIndex>\n"
|
" <startIndex>0</startIndex>\n"
|
||||||
" <itemsPerPage>3</itemsPerPage>\n"
|
" <itemsPerPage>0</itemsPerPage>\n"
|
||||||
CATALOG_LINK_TAGS
|
CATALOG_LINK_TAGS
|
||||||
CHARLES_RAY_CATALOG_ENTRY
|
|
||||||
RAY_CHARLES_CATALOG_ENTRY
|
|
||||||
UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY
|
|
||||||
"</feed>\n"
|
"</feed>\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")
|
||||||
|
" <title>Filtered Entries (count=-1)</title>\n"
|
||||||
|
" <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
|
||||||
|
"</feed>\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")
|
||||||
|
" <title>Filtered Entries (count=0)</title>\n"
|
||||||
|
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
||||||
|
" <totalResults>3</totalResults>\n"
|
||||||
|
" <startIndex>0</startIndex>\n"
|
||||||
|
" <itemsPerPage>0</itemsPerPage>\n"
|
||||||
|
"</feed>\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?count=2");
|
const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?count=2");
|
||||||
EXPECT_EQ(r->status, 200);
|
EXPECT_EQ(r->status, 200);
|
||||||
|
|
Loading…
Reference in New Issue