mirror of https://github.com/kiwix/libkiwix.git
Dedicated 'category' parameter in catalog search
This commit is contained in:
parent
80d4f7e349
commit
e55bf514e8
|
@ -52,6 +52,7 @@ class Filter {
|
||||||
uint64_t activeFilters;
|
uint64_t activeFilters;
|
||||||
std::vector<std::string> _acceptTags;
|
std::vector<std::string> _acceptTags;
|
||||||
std::vector<std::string> _rejectTags;
|
std::vector<std::string> _rejectTags;
|
||||||
|
std::string _category;
|
||||||
std::string _lang;
|
std::string _lang;
|
||||||
std::string _publisher;
|
std::string _publisher;
|
||||||
std::string _creator;
|
std::string _creator;
|
||||||
|
@ -96,6 +97,7 @@ class Filter {
|
||||||
Filter& acceptTags(std::vector<std::string> tags);
|
Filter& acceptTags(std::vector<std::string> tags);
|
||||||
Filter& rejectTags(std::vector<std::string> tags);
|
Filter& rejectTags(std::vector<std::string> tags);
|
||||||
|
|
||||||
|
Filter& category(std::string category);
|
||||||
Filter& lang(std::string lang);
|
Filter& lang(std::string lang);
|
||||||
Filter& publisher(std::string publisher);
|
Filter& publisher(std::string publisher);
|
||||||
Filter& creator(std::string creator);
|
Filter& creator(std::string creator);
|
||||||
|
|
|
@ -391,6 +391,7 @@ enum filterTypes {
|
||||||
MAXSIZE = FLAG(11),
|
MAXSIZE = FLAG(11),
|
||||||
QUERY = FLAG(12),
|
QUERY = FLAG(12),
|
||||||
NAME = FLAG(13),
|
NAME = FLAG(13),
|
||||||
|
CATEGORY = FLAG(14),
|
||||||
};
|
};
|
||||||
|
|
||||||
Filter& Filter::local(bool accept)
|
Filter& Filter::local(bool accept)
|
||||||
|
@ -443,6 +444,13 @@ Filter& Filter::rejectTags(std::vector<std::string> tags)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Filter& Filter::category(std::string category)
|
||||||
|
{
|
||||||
|
_category = category;
|
||||||
|
activeFilters |= CATEGORY;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Filter& Filter::lang(std::string lang)
|
Filter& Filter::lang(std::string lang)
|
||||||
{
|
{
|
||||||
_lang = lang;
|
_lang = lang;
|
||||||
|
@ -502,6 +510,7 @@ bool Filter::accept(const Book& book) const
|
||||||
FILTER(_NOREMOTE, !remote)
|
FILTER(_NOREMOTE, !remote)
|
||||||
|
|
||||||
FILTER(MAXSIZE, book.getSize() <= _maxSize)
|
FILTER(MAXSIZE, book.getSize() <= _maxSize)
|
||||||
|
FILTER(CATEGORY, book.getCategory() == _category)
|
||||||
FILTER(LANG, book.getLanguage() == _lang)
|
FILTER(LANG, book.getLanguage() == _lang)
|
||||||
FILTER(_PUBLISHER, book.getPublisher() == _publisher)
|
FILTER(_PUBLISHER, book.getPublisher() == _publisher)
|
||||||
FILTER(_CREATOR, book.getCreator() == _creator)
|
FILTER(_CREATOR, book.getCreator() == _creator)
|
||||||
|
|
|
@ -698,6 +698,9 @@ InternalServer::search_catalog(const RequestContext& request,
|
||||||
try {
|
try {
|
||||||
filter.name(request.get_argument("name"));
|
filter.name(request.get_argument("name"));
|
||||||
} catch (const std::out_of_range&) {}
|
} catch (const std::out_of_range&) {}
|
||||||
|
try {
|
||||||
|
filter.category(request.get_argument("category"));
|
||||||
|
} catch (const std::out_of_range&) {}
|
||||||
try {
|
try {
|
||||||
filter.lang(request.get_argument("lang"));
|
filter.lang(request.get_argument("lang"));
|
||||||
} catch (const std::out_of_range&) {}
|
} catch (const std::out_of_range&) {}
|
||||||
|
|
|
@ -769,3 +769,21 @@ TEST_F(LibraryServerTest, catalog_search_by_tag)
|
||||||
"</feed>\n"
|
"</feed>\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(LibraryServerTest, catalog_search_by_category)
|
||||||
|
{
|
||||||
|
const auto r = zfs1_->GET("/catalog/search?category=jazz");
|
||||||
|
EXPECT_EQ(r->status, 200);
|
||||||
|
EXPECT_EQ(maskVariableOPDSFeedData(r->body),
|
||||||
|
OPDS_FEED_TAG
|
||||||
|
" <id>12345678-90ab-cdef-1234-567890abcdef</id>\n"
|
||||||
|
" <title>Search result for <Empty query></title>\n"
|
||||||
|
" <updated>YYYY-MM-DDThh:mm:ssZ</updated>\n"
|
||||||
|
" <totalResults>1</totalResults>\n"
|
||||||
|
" <startIndex>0</startIndex>\n"
|
||||||
|
" <itemsPerPage>1</itemsPerPage>\n"
|
||||||
|
CATALOG_LINK_TAGS
|
||||||
|
CHARLES_RAY_CATALOG_ENTRY
|
||||||
|
"</feed>\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue