From 478f0ce322c37d3e060583ad290b034c892cc7b0 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Fri, 30 Aug 2024 14:39:29 +0530 Subject: [PATCH] Don't return error if limit_hits is hit. --- src/collection.cpp | 8 +------- test/collection_test.cpp | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/collection.cpp b/src/collection.cpp index 6a657d93..c3b247c4 100644 --- a/src/collection.cpp +++ b/src/collection.cpp @@ -2079,13 +2079,7 @@ Option Collection::search(std::string raw_query, offset = (per_page * (actual_page - 1)); } - size_t fetch_size = offset + per_page; - - if(fetch_size > limit_hits) { - std::string message = "Only upto " + std::to_string(limit_hits) + " hits can be fetched. " + - "Ensure that `page` and `per_page` parameters are within this range."; - return Option(422, message); - } + size_t fetch_size = std::min(offset + per_page, limit_hits); size_t max_hits = DEFAULT_TOPSTER_SIZE; diff --git a/test/collection_test.cpp b/test/collection_test.cpp index 2d6610a6..e5a3b841 100644 --- a/test/collection_test.cpp +++ b/test/collection_test.cpp @@ -3072,16 +3072,24 @@ TEST_F(CollectionTest, WildcardQueryReturnsResultsBasedOnPerPageParam) { ASSERT_EQ(25, results["found"].get()); // enforce limit_hits - res_op = collection->search("*", query_fields, "", facets, sort_fields, {0}, 10, 3, + auto limit_hits = 20; + results = collection->search("*", query_fields, "", facets, sort_fields, {0}, 10, 3, FREQUENCY, {false}, 1000, spp::sparse_hash_set(), spp::sparse_hash_set(), 10, "", 30, 4, "", 40, {}, {}, {}, 0, - "", "", {1}, 20); + "", "", {1}, limit_hits).get(); - ASSERT_FALSE(res_op.ok()); - ASSERT_STREQ( - "Only upto 20 hits can be fetched. Ensure that `page` and `per_page` parameters are within this range.", - res_op.error().c_str()); + ASSERT_EQ(0, results["hits"].size()); + ASSERT_EQ(25, results["found"].get()); + + results = collection->search("*", query_fields, "", facets, sort_fields, {0}, 15, 2, + FREQUENCY, {false}, 1000, + spp::sparse_hash_set(), + spp::sparse_hash_set(), 10, "", 30, 4, "", 40, {}, {}, {}, 0, + "", "", {1}, limit_hits).get(); + + ASSERT_EQ(5, results["hits"].size()); + ASSERT_EQ(25, results["found"].get()); } TEST_F(CollectionTest, RemoveIfFound) {