From 41276341d07c43def5ca085073a5389a37d95783 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sat, 8 May 2021 23:36:49 +0400 Subject: [PATCH] Empty query acts as a match-all query After switching to Xapian-based search in the library/catalog, an empty query stopped acting as a match-all query. This commit restores the old behaviour in that regard. --- src/library.cpp | 2 +- test/library.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/library.cpp b/src/library.cpp index 8a49af35e..d8307c9ae 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -327,7 +327,7 @@ bool willSelectEverything(const Xapian::Query& query) Xapian::Query buildXapianQueryFromFilterQuery(const Filter& filter) { - if ( !filter.hasQuery() ) { + if ( !filter.hasQuery() || filter.getQuery().empty() ) { // This is a thread-safe way to construct an equivalent of // a Xapian::Query::MatchAll query return Xapian::Query(std::string()); diff --git a/test/library.cpp b/test/library.cpp index be2df95c9..247818990 100644 --- a/test/library.cpp +++ b/test/library.cpp @@ -479,6 +479,24 @@ TEST_F(LibraryTest, filterByQuery) } +TEST_F(LibraryTest, filteringByEmptyQueryReturnsAllEntries) +{ + EXPECT_FILTER_RESULTS(kiwix::Filter().query(""), + "An example ZIM archive", + "Encyclopédie de la Tunisie", + "Granblue Fantasy Wiki", + "Géographie par Wikipédia", + "Islam Stack Exchange", + "Mathématiques", + "Movies & TV Stack Exchange", + "Mythology & Folklore Stack Exchange", + "Ray Charles", + "TED talks - Business", + "Tania Louis", + "Wikiquote" + ); +} + TEST_F(LibraryTest, filterByCreator) { EXPECT_FILTER_RESULTS(kiwix::Filter().creator("Wikipedia"),