Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Calculate max_hits dynamically from per_page and page params.

kishorenca4a51846f700
diff --git a/include/collection.h b/include/collection.h
index 36c173ad..98959732 100644
--- a/include/collection.h
+++ b/include/collection.h
@@ -229,7 +229,7 @@ public:
size_t drop_tokens_threshold = Index::DROP_TOKENS_THRESHOLD,
const spp::sparse_hash_set<std::string> & include_fields = spp::sparse_hash_set<std::string>(),
const spp::sparse_hash_set<std::string> & exclude_fields = spp::sparse_hash_set<std::string>(),
- size_t max_facet_values=10, int max_hits=500,
+ size_t max_facet_values=10,
const std::string & simple_facet_query = "",
const size_t snippet_threshold = 30,
const std::string & highlight_full_fields = "",
diff --git a/src/collection.cpp b/src/collection.cpp
index f679c1c6..42158f44 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -343,7 +343,7 @@ Option<nlohmann::json> Collection::search(const std::string & query, const std::
const size_t drop_tokens_threshold,
const spp::sparse_hash_set<std::string> & include_fields,
const spp::sparse_hash_set<std::string> & exclude_fields,
- const size_t max_facet_values, const int _max_hits,
+ const size_t max_facet_values,
const std::string & simple_facet_query,
const size_t snippet_threshold,
const std::string & highlight_full_fields,
@@ -599,15 +599,7 @@ Option<nlohmann::json> Collection::search(const std::string & query, const std::
return Option<nlohmann::json>(422, message);
}
- const size_t maximum_hits = (_max_hits < 0) ? std::max((size_t)100, get_num_documents()) : size_t(_max_hits);
-
- const size_t results_per_page = std::min(per_page, maximum_hits);
- const size_t num_results = (page * results_per_page);
-
- if(num_results > maximum_hits) {
- std::string message = "Only the first " + std::to_string(maximum_hits) + " results are available.";
- return Option<nlohmann::json>(422, message);
- }
+ const size_t max_hits = (page * per_page);
std::vector<std::vector<art_leaf*>> searched_queries; // search queries used for generating the results
std::vector<KV> raw_result_kvs;
@@ -620,8 +612,8 @@ Option<nlohmann::json> Collection::search(const std::string & query, const std::
for(Index* index: indices) {
index->search_params = search_args(query, search_fields, filters, facets,
index_to_included_ids[index_id], index_to_excluded_ids[index_id],
- sort_fields_std, facet_query, num_typos, max_facet_values, maximum_hits,
- results_per_page, page, token_order, prefix,
+ sort_fields_std, facet_query, num_typos, max_facet_values, max_hits,
+ per_page, page, token_order, prefix,
drop_tokens_threshold, typo_tokens_threshold);
{
std::lock_guard<std::mutex> lk(index->m);
@@ -742,8 +734,8 @@ Option<nlohmann::json> Collection::search(const std::string & query, const std::
raw_results_index++;
}
- const long start_result_index = (page - 1) * results_per_page;
- const long end_result_index = std::min(num_results, result_kvs.size()) - 1; // could be -1 when max_hits is 0
+ const long start_result_index = (page - 1) * per_page;
+ const long end_result_index = std::min(max_hits, result_kvs.size()) - 1; // could be -1 when max_hits is 0
// construct results array
for(long result_kvs_index = start_result_index; result_kvs_index <= end_result_index; result_kvs_index++) {
diff --git a/src/core_api.cpp b/src/core_api.cpp
index 2c6d8bcd..88881ddf 100644
--- a/src/core_api.cpp
+++ b/src/core_api.cpp
@@ -235,7 +235,6 @@ bool get_search(http_req & req, http_res & res) {
const char *FACET_QUERY = "facet_query";
const char *MAX_FACET_VALUES = "max_facet_values";
- const char *MAX_HITS = "max_hits";
const char *PER_PAGE = "per_page";
const char *PAGE = "page";
const char *CALLBACK = "callback";
@@ -286,18 +285,6 @@ bool get_search(http_req & req, http_res & res) {
req.params[FACET_QUERY] = "";
}
- if(req.params.count(MAX_HITS) == 0) {
- // for facet query, let max hits be 0 if it is not explicitly set
- if(req.params[FACET_QUERY].empty()) {
- req.params[MAX_HITS] = "500";
- } else {
- req.params[MAX_HITS] = "0";
- }
- } else if(req.params[MAX_HITS] == "all") {
- // engine will default to size of collection
- req.params[MAX_HITS] = "-1";
- }
-
if(req.params.count(SNIPPET_THRESHOLD) == 0) {
req.params[SNIPPET_THRESHOLD] = "30";
}
@@ -307,7 +294,12 @@ bool get_search(http_req & req, http_res & res) {
}
if(req.params.count(PER_PAGE) == 0) {
- req.params[PER_PAGE] = "10";
+ if(req.params[FACET_QUERY].empty()) {
+ req.params[PER_PAGE] = "10";
+ } else {
+ // for facet query we will set per_page to zero if it is not explicitly overridden
+ req.params[PER_PAGE] = "0";
+ }
}
if(req.params.count(PAGE) == 0) {
@@ -352,11 +344,6 @@ bool get_search(http_req & req, http_res & res) {
return false;
}
- if(!StringUtils::is_uint64_t(req.params[MAX_HITS])) {
- res.set_400("Parameter `" + std::string(MAX_HITS) + "` must be an unsigned integer.");
- return false;
- }
-
if(!StringUtils::is_uint64_t(req.params[SNIPPET_THRESHOLD])) {
res.set_400("Parameter `" + std::string(SNIPPET_THRESHOLD) + "` must be an unsigned integer.");
return false;
@@ -463,7 +450,6 @@ bool get_search(http_req & req, http_res & res) {
token_order, prefix, drop_tokens_threshold,
include_fields, exclude_fields,
static_cast<size_t>(std::stoi(req.params[MAX_FACET_VALUES])),
- static_cast<size_t>(std::stoi(req.params[MAX_HITS])),
req.params[FACET_QUERY],
static_cast<size_t>(std::stoi(req.params[SNIPPET_THRESHOLD])),
req.params[HIGHLIGHT_FULL_FIELDS],
diff --git a/test/collection_faceting_test.cpp b/test/collection_faceting_test.cpp
index 72cb1f05..5db5bac6 100644
--- a/test/collection_faceting_test.cpp
+++ b/test/collection_faceting_test.cpp
@@ -162,7 +162,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
results = coll_array_fields->search("*", query_fields, "", facets, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, " tags : sliver").get();
+ spp::sparse_hash_set<std::string>(), 10, " tags : sliver").get();
ASSERT_EQ(5, results["hits"].size());
ASSERT_EQ(1, results["facet_counts"].size());
@@ -174,7 +174,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
results = coll_array_fields->search("*", query_fields, "", facets, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "tags: fine pltinum").get();
+ spp::sparse_hash_set<std::string>(), 10, "tags: fine pltinum").get();
ASSERT_EQ(5, results["hits"].size());
ASSERT_EQ(1, results["facet_counts"].size());
@@ -186,7 +186,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
results = coll_array_fields->search("*", query_fields, "", facets, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "tags: fine").get();
+ spp::sparse_hash_set<std::string>(), 10, "tags: fine").get();
ASSERT_EQ(5, results["hits"].size());
ASSERT_EQ(1, results["facet_counts"].size());
@@ -198,7 +198,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
results = coll_array_fields->search("*", query_fields, "", facets, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "tags: pltinum").get();
+ spp::sparse_hash_set<std::string>(), 10, "tags: pltinum").get();
ASSERT_EQ(5, results["hits"].size());
ASSERT_EQ(1, results["facet_counts"].size());
@@ -210,7 +210,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
results = coll_array_fields->search("*", query_fields, "", {"age"}, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "age: 2").get();
+ spp::sparse_hash_set<std::string>(), 10, "age: 2").get();
ASSERT_EQ(5, results["hits"].size());
ASSERT_EQ(1, results["facet_counts"].size());
@@ -227,7 +227,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
results = coll_array_fields->search("*", query_fields, "", {"rating"}, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "").get();
+ spp::sparse_hash_set<std::string>(), 10, "").get();
ASSERT_EQ(4, results["facet_counts"][0]["stats"].size());
ASSERT_FLOAT_EQ(4.880199885368347, results["facet_counts"][0]["stats"]["avg"].get<double>());
ASSERT_FLOAT_EQ(0.0, results["facet_counts"][0]["stats"]["min"].get<double>());
@@ -238,7 +238,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
results = coll_array_fields->search("*", query_fields, "", {"rating"}, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "rating: 7").get();
+ spp::sparse_hash_set<std::string>(), 10, "rating: 7").get();
ASSERT_EQ(5, results["hits"].size());
ASSERT_EQ(1, results["facet_counts"].size());
@@ -258,7 +258,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
results = coll_array_fields->search("*", query_fields, "", {"timestamps"}, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "timestamps: 142189002").get();
+ spp::sparse_hash_set<std::string>(), 10, "timestamps: 142189002").get();
ASSERT_EQ(5, results["hits"].size());
ASSERT_EQ(1, results["facet_counts"].size());
@@ -278,7 +278,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
results = coll_array_fields->search("*", query_fields, "", {facets}, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, " tags : notfound").get();
+ spp::sparse_hash_set<std::string>(), 10, " tags : notfound").get();
ASSERT_EQ(5, results["hits"].size());
ASSERT_EQ(1, results["facet_counts"].size());
@@ -289,7 +289,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
auto res_op = coll_array_fields->search("*", query_fields, "", facets, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "foobar");
+ spp::sparse_hash_set<std::string>(), 10, "foobar");
ASSERT_FALSE(res_op.ok());
ASSERT_STREQ("Facet query must be in the `facet_field: value` format.", res_op.error().c_str());
@@ -298,7 +298,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
res_op = coll_array_fields->search("*", query_fields, "", {"foobar"}, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "foobar: baz");
+ spp::sparse_hash_set<std::string>(), 10, "foobar: baz");
ASSERT_FALSE(res_op.ok());
ASSERT_STREQ("Could not find a facet field named `foobar` in the schema.", res_op.error().c_str());
@@ -307,7 +307,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
res_op = coll_array_fields->search("*", query_fields, "", {}, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "tags: foo");
+ spp::sparse_hash_set<std::string>(), 10, "tags: foo");
ASSERT_FALSE(res_op.ok());
ASSERT_STREQ("The `facet_query` parameter is supplied without a `facet_by` parameter.", res_op.error().c_str());
@@ -316,7 +316,7 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
res_op = coll_array_fields->search("*", query_fields, "", facets, sort_fields, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "name_facet: jeremy");
+ spp::sparse_hash_set<std::string>(), 10, "name_facet: jeremy");
ASSERT_FALSE(res_op.ok());
ASSERT_STREQ("Facet query refers to a facet field `name_facet` that is not part of `facet_by` parameter.", res_op.error().c_str());
@@ -364,7 +364,7 @@ TEST_F(CollectionFacetingTest, FacetCountsBool) {
nlohmann::json results = coll1->search("*", {"title"}, "in_stock:true", facets, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "in_stock:true").get();
+ spp::sparse_hash_set<std::string>(), 10, "in_stock:true").get();
ASSERT_EQ(1, results["facet_counts"].size());
ASSERT_EQ(1, results["facet_counts"][0]["counts"].size());
@@ -403,7 +403,7 @@ TEST_F(CollectionFacetingTest, FacetCountsHighlighting) {
nlohmann::json results = coll1->search("phone", {"categories"}, "", facets, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "categories:cell").get();
+ spp::sparse_hash_set<std::string>(), 10, "categories:cell").get();
ASSERT_EQ(1, results["facet_counts"].size());
ASSERT_EQ(3, results["facet_counts"][0]["counts"].size());
@@ -428,7 +428,7 @@ TEST_F(CollectionFacetingTest, FacetCountsHighlighting) {
results = coll1->search("phone", {"categories"}, "", facets, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "categories:cell").get();
+ spp::sparse_hash_set<std::string>(), 10, "categories:cell").get();
ASSERT_EQ(1, results["facet_counts"].size());
ASSERT_STREQ("categories", results["facet_counts"][0]["field_name"].get<std::string>().c_str());
@@ -450,7 +450,7 @@ TEST_F(CollectionFacetingTest, FacetCountsHighlighting) {
results = coll1->search("phone", {"categories"}, "", facets, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "categories:acces").get();
+ spp::sparse_hash_set<std::string>(), 10, "categories:acces").get();
ASSERT_EQ(1, results["facet_counts"].size());
@@ -464,7 +464,7 @@ TEST_F(CollectionFacetingTest, FacetCountsHighlighting) {
results = coll1->search("phone", {"categories"}, "", facets, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "categories:ACCES").get();
+ spp::sparse_hash_set<std::string>(), 10, "categories:ACCES").get();
ASSERT_EQ(1, results["facet_counts"].size());
ASSERT_EQ(1, results["facet_counts"][0]["counts"].size());
@@ -481,7 +481,7 @@ TEST_F(CollectionFacetingTest, FacetCountsHighlighting) {
results = coll1->search("phone", {"categories"}, "", facets, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "categories:cell ph").get();
+ spp::sparse_hash_set<std::string>(), 10, "categories:cell ph").get();
ASSERT_EQ(1, results["facet_counts"].size());
ASSERT_EQ(2, results["facet_counts"][0]["counts"].size());
@@ -547,7 +547,7 @@ TEST_F(CollectionFacetingTest, FacetStatOnFloatFields) {
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
spp::sparse_hash_set<std::string>(),
- 10, 500, "average: 11").get();
+ 10, "average: 11").get();
ASSERT_EQ(4, results["facet_counts"][0]["stats"].size());
ASSERT_FLOAT_EQ(39.68800011036053, results["facet_counts"][0]["stats"]["avg"].get<double>());
diff --git a/test/collection_override_test.cpp b/test/collection_override_test.cpp
index 0aa386ee..a94bfbc0 100644
--- a/test/collection_override_test.cpp
+++ b/test/collection_override_test.cpp
@@ -189,7 +189,7 @@ TEST_F(CollectionOverrideTest, ExcludeIncludeFacetFilterQuery) {
auto results = coll_mul_fields->search("not-found", {"title"}, "", {"starring"}, {}, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "starring: will").get();
+ spp::sparse_hash_set<std::string>(), 10, "starring: will").get();
ASSERT_EQ("<mark>Will</mark> Ferrell", results["facet_counts"][0]["counts"][0]["highlighted"].get<std::string>());
ASSERT_EQ("Will Ferrell", results["facet_counts"][0]["counts"][0]["value"].get<std::string>());
@@ -217,7 +217,7 @@ TEST_F(CollectionOverrideTest, ExcludeIncludeFacetFilterQuery) {
results = coll_mul_fields->search("the", {"title"}, "", {"starring"}, {}, 0, 10, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "starring: scott").get();
+ spp::sparse_hash_set<std::string>(), 10, "starring: scott").get();
// "count" would be `2` without exclusion
ASSERT_EQ("<mark>Scott</mark> Glenn", results["facet_counts"][0]["counts"][0]["highlighted"].get<std::string>());
@@ -226,25 +226,25 @@ TEST_F(CollectionOverrideTest, ExcludeIncludeFacetFilterQuery) {
ASSERT_EQ("Kristin <mark>Scott</mark> Thomas", results["facet_counts"][0]["counts"][1]["highlighted"].get<std::string>());
ASSERT_EQ(1, results["facet_counts"][0]["counts"][1]["count"].get<size_t>());
- // ensure max_hits is respected
- // first with max_hits = 0
- results = coll_mul_fields->search("the", {"title"}, "", {"starring"}, {}, 0, 10, 1, FREQUENCY,
+ // ensure per_page is respected
+ // first with per_page = 0
+ results = coll_mul_fields->search("the", {"title"}, "", {"starring"}, {}, 0, 0, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 0, "starring: scott").get();
+ spp::sparse_hash_set<std::string>(), 10, "starring: scott").get();
ASSERT_EQ(10, results["found"].get<size_t>());
ASSERT_EQ(0, results["hits"].size());
coll_mul_fields->remove_override("exclude-rule");
- // now with max_hits = 1, and an include query
+ // now with per_page = 1, and an include query
coll_mul_fields->add_override(override_include);
- results = coll_mul_fields->search("not-found", {"title"}, "", {"starring"}, {}, 0, 10, 1, FREQUENCY,
+ results = coll_mul_fields->search("not-found", {"title"}, "", {"starring"}, {}, 0, 1, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 1, "").get();
+ spp::sparse_hash_set<std::string>(), 10, "").get();
ASSERT_EQ(1, results["found"].get<size_t>());
ASSERT_EQ(1, results["hits"].size());
@@ -264,7 +264,7 @@ TEST_F(CollectionOverrideTest, IncludeExcludeHitsQuery) {
auto results = coll_mul_fields->search("the", {"title"}, "", {"starring"}, {}, 0, 50, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "starring: will", 30,
+ spp::sparse_hash_set<std::string>(), 10, "starring: will", 30,
"", 10,
pinned_hits, {}).get();
@@ -281,7 +281,7 @@ TEST_F(CollectionOverrideTest, IncludeExcludeHitsQuery) {
results = coll_mul_fields->search("the", {"title"}, "", {"starring"}, {}, 0, 50, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "starring: will", 30,
+ spp::sparse_hash_set<std::string>(), 10, "starring: will", 30,
"", 10,
pinned_hits, hidden_hits).get();
@@ -318,7 +318,7 @@ TEST_F(CollectionOverrideTest, IncludeExcludeHitsQuery) {
results = coll_mul_fields->search("the", {"title"}, "", {"starring"}, {}, 0, 50, 1, FREQUENCY,
false, Index::DROP_TOKENS_THRESHOLD,
spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "starring: will", 30,
+ spp::sparse_hash_set<std::string>(), 10, "starring: will", 30,
"", 10,
{}, {hidden_hits}).get();
diff --git a/test/collection_test.cpp b/test/collection_test.cpp
index 2660f37d..fd213703 100644
--- a/test/collection_test.cpp
+++ b/test/collection_test.cpp
@@ -545,14 +545,14 @@ TEST_F(CollectionTest, TypoTokensThreshold) {
// Query expansion should happen only based on the `typo_tokens_threshold` value
auto results = collection->search("launch", {"title"}, "", {}, sort_fields, 2, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "", 5, "", 0).get();
+ spp::sparse_hash_set<std::string>(), 10, "", 5, "", 0).get();
ASSERT_EQ(5, results["hits"].size());
ASSERT_EQ(5, results["found"].get<size_t>());
results = collection->search("launch", {"title"}, "", {}, sort_fields, 2, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "", 5, "", 10).get();
+ spp::sparse_hash_set<std::string>(), 10, "", 5, "", 10).get();
ASSERT_EQ(7, results["hits"].size());
ASSERT_EQ(7, results["found"].get<size_t>());
@@ -1922,7 +1922,7 @@ TEST_F(CollectionTest, DeletionOfDocumentArrayFields) {
doc["strarray"] = {"Cell Phones", "Cell Phone Accessories", "Cell Phone Cases & Clips"};
doc["int32array"] = {100, 200, 300};
doc["int64array"] = {1582369739000, 1582369739000, 1582369739000};
- doc["floatarray"] = {19.99, 400.999, 500};
+ doc["floatarray"] = {19.99, 400.999};
doc["boolarray"] = {true, false, true};
doc["points"] = 25;
@@ -1931,7 +1931,7 @@ TEST_F(CollectionTest, DeletionOfDocumentArrayFields) {
nlohmann::json res = coll1->search("phone", {"strarray"}, "", {}, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500).get();
+ spp::sparse_hash_set<std::string>(), 10).get();
ASSERT_EQ(1, res["found"]);
@@ -1941,7 +1941,7 @@ TEST_F(CollectionTest, DeletionOfDocumentArrayFields) {
res = coll1->search("phone", {"strarray"}, "", {}, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500).get();
+ spp::sparse_hash_set<std::string>(), 10).get();
ASSERT_EQ(0, res["found"].get<int32_t>());
@@ -2107,7 +2107,7 @@ TEST_F(CollectionTest, SearchHighlightShouldFollowThreshold) {
auto res = coll1->search("lazy", {"title"}, "", {}, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "", 500).get();
+ spp::sparse_hash_set<std::string>(), 10, "").get();
ASSERT_STREQ("The quick brown fox jumped over the <mark>lazy</mark> dog and ran straight to the forest to sleep.",
res["hits"][0]["highlights"][0]["snippet"].get<std::string>().c_str());
@@ -2116,7 +2116,7 @@ TEST_F(CollectionTest, SearchHighlightShouldFollowThreshold) {
res = coll1->search("lazy", {"title"}, "", {}, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "", 5).get();
+ spp::sparse_hash_set<std::string>(), 10, "", 5).get();
ASSERT_STREQ("fox jumped over the <mark>lazy</mark> dog and ran straight",
res["hits"][0]["highlights"][0]["snippet"].get<std::string>().c_str());
@@ -2151,7 +2151,7 @@ TEST_F(CollectionTest, SearchHighlightFieldFully) {
auto res = coll1->search("lazy", {"title"}, "", {}, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "", 5, "title").get();
+ spp::sparse_hash_set<std::string>(), 10, "", 5, "title").get();
ASSERT_EQ(1, res["hits"][0]["highlights"].size());
ASSERT_STREQ("The quick brown fox jumped over the <mark>lazy</mark> dog and ran straight to the forest to sleep.",
@@ -2160,14 +2160,14 @@ TEST_F(CollectionTest, SearchHighlightFieldFully) {
// should not return value key when highlight_full_fields is not specified
res = coll1->search("lazy", {"title"}, "", {}, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "", 5, "").get();
+ spp::sparse_hash_set<std::string>(), 10, "", 5, "").get();
ASSERT_EQ(2, res["hits"][0]["highlights"][0].size());
// query multiple fields
res = coll1->search("lazy", {"title", "tags"}, "", {}, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- spp::sparse_hash_set<std::string>(), 10, 500, "", 5, "title, tags").get();
+ spp::sparse_hash_set<std::string>(), 10, "", 5, "title, tags").get();
ASSERT_EQ(2, res["hits"][0]["highlights"].size());
ASSERT_STREQ("The quick brown fox jumped over the <mark>lazy</mark> dog and ran straight to the forest to sleep.",
@@ -2180,7 +2180,7 @@ TEST_F(CollectionTest, SearchHighlightFieldFully) {
spp::sparse_hash_set<std::string> excluded_fields = {"tags"};
res = coll1->search("lazy", {"title", "tags"}, "", {}, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- excluded_fields, 10, 500, "", 5, "title, tags").get();
+ excluded_fields, 10, "", 5, "title, tags").get();
ASSERT_EQ(1, res["hits"][0]["highlights"].size());
ASSERT_STREQ("The quick brown fox jumped over the <mark>lazy</mark> dog and ran straight to the forest to sleep.",
@@ -2190,7 +2190,7 @@ TEST_F(CollectionTest, SearchHighlightFieldFully) {
excluded_fields = {"tags", "title"};
res = coll1->search("lazy", {"title", "tags"}, "", {}, sort_fields, 0, 10, 1,
token_ordering::FREQUENCY, true, 10, spp::sparse_hash_set<std::string>(),
- excluded_fields, 10, 500, "", 5, "title, tags").get();
+ excluded_fields, 10, "", 5, "title, tags").get();
ASSERT_EQ(0, res["hits"][0]["highlights"].size());
collectionManager.drop_collection("coll1");
@@ -2266,39 +2266,39 @@ TEST_F(CollectionTest, OptionalFields) {
collectionManager.drop_collection("coll1");
}
-TEST_F(CollectionTest, ReturnsResultsBasedOnMaxHitsParam) {
+TEST_F(CollectionTest, ReturnsResultsBasedOnPerPageParam) {
std::vector<std::string> facets;
spp::sparse_hash_set<std::string> empty;
- nlohmann::json results = collection->search("*", query_fields, "", facets, sort_fields, 0, 100, 1,
- FREQUENCY, false, 1000, empty, empty, 10, 12).get();
+ nlohmann::json results = collection->search("*", query_fields, "", facets, sort_fields, 0, 12, 1,
+ FREQUENCY, false, 1000, empty, empty, 10).get();
ASSERT_EQ(12, results["hits"].size());
ASSERT_EQ(25, results["found"].get<int>());
// should match collection size
- results = collection->search("*", query_fields, "", facets, sort_fields, 0, 100, 1,
- FREQUENCY, false, 1000, empty, empty, 10, -1).get();
+ results = collection->search("*", query_fields, "", facets, sort_fields, 0, 100000, 1,
+ FREQUENCY, false, 1000, empty, empty, 10).get();
ASSERT_EQ(25, results["hits"].size());
ASSERT_EQ(25, results["found"].get<int>());
- // should still respect pagination
+ // do pagination
results = collection->search("*", query_fields, "", facets, sort_fields, 0, 10, 1,
- FREQUENCY, false, 1000, empty, empty, 10, -1).get();
+ FREQUENCY, false, 1000, empty, empty, 10).get();
ASSERT_EQ(10, results["hits"].size());
ASSERT_EQ(25, results["found"].get<int>());
results = collection->search("*", query_fields, "", facets, sort_fields, 0, 10, 2,
- FREQUENCY, false, 1000, empty, empty, 10, -1).get();
+ FREQUENCY, false, 1000, empty, empty, 10).get();
ASSERT_EQ(10, results["hits"].size());
ASSERT_EQ(25, results["found"].get<int>());
results = collection->search("*", query_fields, "", facets, sort_fields, 0, 10, 3,
- FREQUENCY, false, 1000, empty, empty, 10, -1).get();
+ FREQUENCY, false, 1000, empty, empty, 10).get();
ASSERT_EQ(5, results["hits"].size());
ASSERT_EQ(25, results["found"].get<int>());