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 7be4ea57a..4f8f83b1c 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 3 result + ASSERT_EQ(result3.size(), 3); + // Be able to do a different search using the same searcher. query.setQuery("super", false); auto search1 = searcher.search(query);