Skip to content

Commit

Permalink
Multivalue support for book query
Browse files Browse the repository at this point in the history
Adds support for putting multiple `book` query parameter.
  • Loading branch information
juuz0 committed Aug 15, 2022
1 parent 22bb98c commit d42b0d1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
8 changes: 4 additions & 4 deletions include/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum supportedListMode {
class Filter {
public: // types
using Tags = std::vector<std::string>;
using AliasNames = std::vector<std::string>;

private: // data
uint64_t activeFilters;
Expand All @@ -67,7 +68,7 @@ class Filter {
std::string _query;
bool _queryIsPartial;
std::string _name;
std::string _aliasName;
AliasNames _aliasNames;

public: // functions
Filter();
Expand Down Expand Up @@ -113,7 +114,7 @@ class Filter {
Filter& maxSize(size_t size);
Filter& query(std::string query, bool partial=true);
Filter& name(std::string name);
Filter& aliasName(std::string aliasName);
Filter& aliasNames(const AliasNames& aliasNames);

bool hasQuery() const;
const std::string& getQuery() const { return _query; }
Expand All @@ -137,8 +138,7 @@ class Filter {
const Tags& getAcceptTags() const { return _acceptTags; }
const Tags& getRejectTags() const { return _rejectTags; }

bool hasAliasName() const;
const std::string& getAliasName() const { return _aliasName; }
const AliasNames& getAliasNames() const { return _aliasNames; }

private: // functions
friend class Library;
Expand Down
28 changes: 15 additions & 13 deletions src/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,16 @@ Xapian::Query categoryQuery(const std::string& category)
return Xapian::Query("XC" + normalizeText(category));
}

Xapian::Query aliasNameQuery(const std::string& fileName)
Xapian::Query aliasNamesQuery(const Filter::AliasNames& aliasNames)
{
return parseQuery(fileName, "XF");
Xapian::Query q = Xapian::Query(std::string());
std::vector<Xapian::Query> queryVec;
for (const auto& aliasName : aliasNames) {
queryVec.push_back(parseQuery(aliasName, "XF"));
}
Xapian::Query combinedQuery(Xapian::Query::OP_OR, queryVec.begin(), queryVec.end());
q = Xapian::Query(Xapian::Query::OP_FILTER, q, combinedQuery);
return q;
}

Xapian::Query langQuery(const std::string& lang)
Expand Down Expand Up @@ -602,8 +609,8 @@ Xapian::Query buildXapianQuery(const Filter& filter)
const auto tq = tagsQuery(filter.getAcceptTags(), filter.getRejectTags());
q = Xapian::Query(Xapian::Query::OP_AND, q, tq);;
}
if ( filter.hasAliasName() ) {
q = Xapian::Query(Xapian::Query::OP_AND, q, aliasNameQuery(filter.getAliasName()));
if ( !filter.getAliasNames().empty() ) {
q = Xapian::Query(Xapian::Query::OP_AND, q, aliasNamesQuery(filter.getAliasNames()));
}
return q;
}
Expand Down Expand Up @@ -754,7 +761,7 @@ enum filterTypes {
QUERY = FLAG(12),
NAME = FLAG(13),
CATEGORY = FLAG(14),
ALIASNAME = FLAG(15),
ALIASNAMES = FLAG(15),
};

Filter& Filter::local(bool accept)
Expand Down Expand Up @@ -857,10 +864,10 @@ Filter& Filter::name(std::string name)
return *this;
}

Filter& Filter::aliasName(std::string aliasName)
Filter& Filter::aliasNames(const AliasNames& aliasNames)
{
_aliasName = aliasName;
activeFilters |= ALIASNAME;
_aliasNames = aliasNames;
activeFilters |= ALIASNAMES;
return *this;
}

Expand All @@ -876,11 +883,6 @@ bool Filter::hasName() const
return ACTIVE(NAME);
}

bool Filter::hasAliasName() const
{
return ACTIVE(ALIASNAME);
}

bool Filter::hasCategory() const
{
return ACTIVE(CATEGORY);
Expand Down
2 changes: 1 addition & 1 deletion src/server/internalServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Filter get_search_filter(const RequestContext& request, const std::string& prefi
filter.rejectTags(kiwix::split(request.get_argument(prefix+"notag"), ";"));
} catch (...) {}
try {
filter.aliasName(request.get_argument(prefix + "book"));
filter.aliasNames(request.get_arguments(prefix + "book"));
} catch (...) {}
return filter;
}
Expand Down

0 comments on commit d42b0d1

Please sign in to comment.