mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-09-09 15:18:55 -04:00
Allow to filter books by flavour.
This commit is contained in:
parent
a546effa15
commit
b16f6b9561
@ -71,6 +71,7 @@ class Filter {
|
|||||||
std::string _query;
|
std::string _query;
|
||||||
bool _queryIsPartial;
|
bool _queryIsPartial;
|
||||||
std::string _name;
|
std::string _name;
|
||||||
|
std::string _flavour;
|
||||||
|
|
||||||
public: // functions
|
public: // functions
|
||||||
Filter();
|
Filter();
|
||||||
@ -130,6 +131,7 @@ class Filter {
|
|||||||
Filter& maxSize(size_t size);
|
Filter& maxSize(size_t size);
|
||||||
Filter& query(std::string query, bool partial=true);
|
Filter& query(std::string query, bool partial=true);
|
||||||
Filter& name(std::string name);
|
Filter& name(std::string name);
|
||||||
|
Filter& flavour(std::string flavour);
|
||||||
Filter& clearLang();
|
Filter& clearLang();
|
||||||
Filter& clearCategory();
|
Filter& clearCategory();
|
||||||
|
|
||||||
@ -152,6 +154,9 @@ class Filter {
|
|||||||
bool hasCreator() const;
|
bool hasCreator() const;
|
||||||
const std::string& getCreator() const { return _creator; }
|
const std::string& getCreator() const { return _creator; }
|
||||||
|
|
||||||
|
bool hasFlavour() const;
|
||||||
|
const std::string& getFlavour() const { return _flavour; }
|
||||||
|
|
||||||
const Tags& getAcceptTags() const { return _acceptTags; }
|
const Tags& getAcceptTags() const { return _acceptTags; }
|
||||||
const Tags& getRejectTags() const { return _rejectTags; }
|
const Tags& getRejectTags() const { return _rejectTags; }
|
||||||
|
|
||||||
|
@ -437,6 +437,7 @@ void Library::updateBookDB(const Book& book)
|
|||||||
indexer.index_text(normalizeText(book.getCreator()), 1, "A");
|
indexer.index_text(normalizeText(book.getCreator()), 1, "A");
|
||||||
indexer.index_text(normalizeText(book.getPublisher()), 1, "XP");
|
indexer.index_text(normalizeText(book.getPublisher()), 1, "XP");
|
||||||
doc.add_term("XN"+normalizeText(book.getName()));
|
doc.add_term("XN"+normalizeText(book.getName()));
|
||||||
|
indexer.index_text(normalizeText(book.getFlavour()), 1, "XF");
|
||||||
indexer.index_text(normalizeText(book.getCategory()), 1, "XC");
|
indexer.index_text(normalizeText(book.getCategory()), 1, "XC");
|
||||||
|
|
||||||
for ( const auto& tag : split(normalizeText(book.getTags()), ";") ) {
|
for ( const auto& tag : split(normalizeText(book.getTags()), ";") ) {
|
||||||
@ -477,6 +478,7 @@ Xapian::Query buildXapianQueryFromFilterQuery(const Filter& filter)
|
|||||||
queryParser.add_prefix("title", "S");
|
queryParser.add_prefix("title", "S");
|
||||||
queryParser.add_prefix("description", "XD");
|
queryParser.add_prefix("description", "XD");
|
||||||
queryParser.add_prefix("name", "XN");
|
queryParser.add_prefix("name", "XN");
|
||||||
|
queryParser.add_prefix("flavour", "XF");
|
||||||
queryParser.add_prefix("category", "XC");
|
queryParser.add_prefix("category", "XC");
|
||||||
queryParser.add_prefix("lang", "L");
|
queryParser.add_prefix("lang", "L");
|
||||||
queryParser.add_prefix("publisher", "XP");
|
queryParser.add_prefix("publisher", "XP");
|
||||||
@ -503,6 +505,12 @@ Xapian::Query nameQuery(const std::string& name)
|
|||||||
return Xapian::Query("XN" + normalizeText(name));
|
return Xapian::Query("XN" + normalizeText(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Xapian::Query flavourQuery(const std::string& name)
|
||||||
|
{
|
||||||
|
return Xapian::Query("XF" + normalizeText(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Xapian::Query multipleParamQuery(const std::string& commaSeparatedList, const std::string& prefix)
|
Xapian::Query multipleParamQuery(const std::string& commaSeparatedList, const std::string& prefix)
|
||||||
{
|
{
|
||||||
Xapian::Query q;
|
Xapian::Query q;
|
||||||
@ -570,6 +578,9 @@ Xapian::Query buildXapianQuery(const Filter& filter)
|
|||||||
if ( filter.hasName() ) {
|
if ( filter.hasName() ) {
|
||||||
q = Xapian::Query(Xapian::Query::OP_AND, q, nameQuery(filter.getName()));
|
q = Xapian::Query(Xapian::Query::OP_AND, q, nameQuery(filter.getName()));
|
||||||
}
|
}
|
||||||
|
if ( filter.hasFlavour() ) {
|
||||||
|
q = Xapian::Query(Xapian::Query::OP_AND, q, flavourQuery(filter.getFlavour()));
|
||||||
|
}
|
||||||
if ( filter.hasCategory() ) {
|
if ( filter.hasCategory() ) {
|
||||||
q = Xapian::Query(Xapian::Query::OP_AND, q, categoryQuery(filter.getCategory()));
|
q = Xapian::Query(Xapian::Query::OP_AND, q, categoryQuery(filter.getCategory()));
|
||||||
}
|
}
|
||||||
@ -735,6 +746,7 @@ enum filterTypes {
|
|||||||
QUERY = FLAG(12),
|
QUERY = FLAG(12),
|
||||||
NAME = FLAG(13),
|
NAME = FLAG(13),
|
||||||
CATEGORY = FLAG(14),
|
CATEGORY = FLAG(14),
|
||||||
|
FLAVOUR = FLAG(15),
|
||||||
};
|
};
|
||||||
|
|
||||||
Filter& Filter::local(bool accept)
|
Filter& Filter::local(bool accept)
|
||||||
@ -836,6 +848,13 @@ Filter& Filter::name(std::string name)
|
|||||||
activeFilters |= NAME;
|
activeFilters |= NAME;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Filter& Filter::flavour(std::string flavour)
|
||||||
|
{
|
||||||
|
_flavour = flavour;
|
||||||
|
activeFilters |= FLAVOUR;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Filter& Filter::clearLang()
|
Filter& Filter::clearLang()
|
||||||
{
|
{
|
||||||
@ -881,6 +900,12 @@ bool Filter::hasCreator() const
|
|||||||
return ACTIVE(_CREATOR);
|
return ACTIVE(_CREATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Filter::hasFlavour() const
|
||||||
|
{
|
||||||
|
return ACTIVE(FLAVOUR);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Filter::accept(const Book& book) const
|
bool Filter::accept(const Book& book) const
|
||||||
{
|
{
|
||||||
auto local = !book.getPath().empty();
|
auto local = !book.getPath().empty();
|
||||||
|
@ -570,6 +570,25 @@ TEST_F(LibraryTest, filterByLanguage)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(LibraryTest, filterByFlavour)
|
||||||
|
{
|
||||||
|
EXPECT_FILTER_RESULTS(kiwix::Filter().flavour("full"),
|
||||||
|
"Géographie par Wikipédia",
|
||||||
|
"Tania Louis",
|
||||||
|
"Wikiquote"
|
||||||
|
);
|
||||||
|
|
||||||
|
EXPECT_FILTER_RESULTS(kiwix::Filter().query("flavour:full"),
|
||||||
|
"Géographie par Wikipédia",
|
||||||
|
"Tania Louis",
|
||||||
|
"Wikiquote"
|
||||||
|
);
|
||||||
|
|
||||||
|
EXPECT_FILTER_RESULTS(kiwix::Filter().query("full"),
|
||||||
|
/* no results */
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(LibraryTest, filterByTags)
|
TEST_F(LibraryTest, filterByTags)
|
||||||
{
|
{
|
||||||
EXPECT_FILTER_RESULTS(kiwix::Filter().acceptTags({"stackexchange"}),
|
EXPECT_FILTER_RESULTS(kiwix::Filter().acceptTags({"stackexchange"}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user