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

Return request params in the response.

kishorenc6bb6f2f4b8c7
diff --git a/src/collection.cpp b/src/collection.cpp
index 49a97cf6..dc824745 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -876,6 +876,10 @@ Option<nlohmann::json> Collection::search(const std::string & query, const std::
result["facet_counts"].push_back(facet_result);
}
+ result["request_params"] = nlohmann::json::object();;
+ result["request_params"]["per_page"] = per_page;
+ result["request_params"]["q"] = query;
+
//long long int timeMillis = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - begin).count();
//!LOG(INFO) << "Time taken for result calc: " << timeMillis << "us";
//!store->print_memory_usage();
diff --git a/test/collection_faceting_test.cpp b/test/collection_faceting_test.cpp
index d8b69f15..b3767a3e 100644
--- a/test/collection_faceting_test.cpp
+++ b/test/collection_faceting_test.cpp
@@ -253,7 +253,6 @@ TEST_F(CollectionFacetingTest, FacetCounts) {
ASSERT_FLOAT_EQ(9.99899959564209, results["facet_counts"][0]["stats"]["max"].get<double>());
ASSERT_FLOAT_EQ(24.400999426841736, results["facet_counts"][0]["stats"]["sum"].get<double>());
-
// facet query on an array integer field
results = coll_array_fields->search("*", query_fields, "", {"timestamps"}, sort_fields, 0, 10, 1, FREQUENCY,
diff --git a/test/collection_test.cpp b/test/collection_test.cpp
index f7600328..210c90f9 100644
--- a/test/collection_test.cpp
+++ b/test/collection_test.cpp
@@ -85,6 +85,9 @@ TEST_F(CollectionTest, ExactSearchShouldBeStable) {
nlohmann::json results = collection->search("the", query_fields, "", facets, sort_fields, 0, 10).get();
ASSERT_EQ(7, results["hits"].size());
ASSERT_EQ(7, results["found"].get<int>());
+
+ ASSERT_STREQ("the", results["request_params"]["q"].get<std::string>().c_str());
+ ASSERT_EQ(10, results["request_params"]["per_page"].get<size_t>());
// For two documents of the same score, the larger doc_id appears first
std::vector<std::string> ids = {"1", "6", "foo", "13", "10", "8", "16"};
@@ -167,6 +170,8 @@ TEST_F(CollectionTest, ExactPhraseSearch) {
ASSERT_EQ(3, results["hits"].size());
ASSERT_EQ(5, results["found"].get<uint32_t>());
+ ASSERT_EQ(3, results["request_params"]["per_page"].get<size_t>());
+
ids = {"8", "1", "17"};
for(size_t i = 0; i < 3; i++) {