From 953cba7f9092edb2f432fc6544b822ac13fb9ebb Mon Sep 17 00:00:00 2001 From: Maneesh P M Date: Tue, 3 Aug 2021 16:27:40 +0530 Subject: [PATCH 1/2] Add getResult unit test for in between range searching Search::getResult(start, end) seems to be broken for getting results in range that not starting with 0. --- test/search.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/search.cpp b/test/search.cpp index 7be4ea57a..672a883a5 100644 --- a/test/search.cpp +++ b/test/search.cpp @@ -167,6 +167,14 @@ TEST(Search, multiSearch) it1++;it1++;it1++; ASSERT_EQ(it1, result1.end()); + // Check result retrieval in start ranges + auto result2 = search0.getResults(0, 3); // Should return 3 results + ASSERT_EQ(result2.size(), 3); + + // Check result retrieval in middle ranges + auto result3 = search0.getResults(2, 3); // Should Return 1 result + ASSERT_EQ(result3.size(), 1); // Fails! + // Be able to do a different search using the same searcher. query.setQuery("super", false); auto search1 = searcher.search(query); From 6a0bcbe47ae877c5ae99f0164315985a89bc79fe Mon Sep 17 00:00:00 2001 From: Maneesh P M Date: Fri, 30 Jul 2021 22:05:38 +0530 Subject: [PATCH 2/2] Fix documentation of getResults getReturn should follow the same convention used by Xapian for consistency. The second argument maxResults is the maximum number of results to return starting from the first argument start. --- include/zim/search.h | 6 +++--- src/search.cpp | 4 ++-- test/search.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/zim/search.h b/include/zim/search.h index ae4c54627..61bf7623d 100644 --- a/include/zim/search.h +++ b/include/zim/search.h @@ -167,10 +167,10 @@ class Search * * @param start The begining of the range to get * (offset of the first result). - * @param end The end of the range to get - * (offset of the result past the end of the range). + * @param maxResults The maximum number of results to return + * (offset of last result from the start of range). */ - const SearchResultSet getResults(int start, int end) const; + const SearchResultSet getResults(int start, int maxResults) const; /** Get the number of estimated results for this search. * diff --git a/src/search.cpp b/src/search.cpp index 7049bbe94..461a15472 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -357,10 +357,10 @@ int Search::getEstimatedMatches() const } } -const SearchResultSet Search::getResults(int start, int end) const { +const SearchResultSet Search::getResults(int start, int maxResults) const { try { auto enquire = getEnquire(); - auto mset = enquire.get_mset(start, end); + auto mset = enquire.get_mset(start, maxResults); return SearchResultSet(mp_internalDb, std::move(mset)); } catch(Xapian::QueryParserError& e) { return SearchResultSet(mp_internalDb); diff --git a/test/search.cpp b/test/search.cpp index 672a883a5..4f8f83b1c 100644 --- a/test/search.cpp +++ b/test/search.cpp @@ -172,8 +172,8 @@ TEST(Search, multiSearch) ASSERT_EQ(result2.size(), 3); // Check result retrieval in middle ranges - auto result3 = search0.getResults(2, 3); // Should Return 1 result - ASSERT_EQ(result3.size(), 1); // Fails! + auto result3 = search0.getResults(2, 3); // Should Return 3 result + ASSERT_EQ(result3.size(), 3); // Be able to do a different search using the same searcher. query.setQuery("super", false);