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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Reset `filter_result_iterator` in `Index::do_infix_search`.
Harpreet Sangarcdcec4e08df2
diff --git a/src/index.cpp b/src/index.cppindex 6494bc09..f6b7da72 100644--- a/src/index.cpp+++ b/src/index.cpp@@ -5128,6 +5128,7 @@ Option<bool> Index::do_infix_search(const size_t num_search_fields, const std::v}filtered_infix_ids = std::move(result);+ filter_result_iterator->reset();}bool field_is_array = search_schema.at(the_fields[field_id].name).is_array();diff --git a/test/collection_infix_search_test.cpp b/test/collection_infix_search_test.cppindex bdf67e27..618d024b 100644--- a/test/collection_infix_search_test.cpp+++ b/test/collection_infix_search_test.cpp@@ -190,6 +190,86 @@ TEST_F(CollectionInfixSearchTest, InfixWithFiltering) {ASSERT_EQ(1, results["hits"].size());ASSERT_STREQ("1", results["hits"][0]["document"]["id"].get<std::string>().c_str());+ auto schema_json =+ R"({+ "name": "Foods",+ "fields": [+ {"name": "title", "type": "string"},+ {"name": "summary", "type": "string"},+ {"name": "rating", "type": "int32"}+ ]+ })"_json;+ std::vector<nlohmann::json> documents = {+ R"({+ "title": "Spicy Chicken Tacos",+ "summary": "These are tacos made with spicy chicken fillings.",+ "rating": 2+ })"_json,+ R"({+ "title": "Salad With Taco Toppings",+ "summary": "Healthy salad with taco seasoning topping.",+ "rating": 3+ })"_json,+ R"({+ "title": "Beef Street Tacos",+ "summary": "Just like eating in Mexico!",+ "rating": 1+ })"_json,+ R"({+ "title": "Bean Burritos",+ "summary": "Home made beans wrapped in a tortilla.",+ "rating": 3+ })"_json,+ R"({+ "title": "Cheese Enchiladas",+ "summary": "Fresh cheese tortilla wrapped and baked.",+ "rating": 2+ })"_json,+ R"({+ "title": "Green Sauce Tacoquitos",+ "summary": "Deep fried tacos covered in green sauce.",+ "rating": 5+ })"_json,+ R"({+ "title": "Susan's SuperTacosSupereme",+ "summary": "The famous chef Susan Pancakey's taco supreme.",+ "rating": 1+ })"_json,+ };+ auto collection_create_op = collectionManager.create_collection(schema_json);+ ASSERT_TRUE(collection_create_op.ok());+ for (auto const &json: documents) {+ auto add_op = collection_create_op.get()->add(json.dump());+ if (!add_op.ok()) {+ LOG(INFO) << add_op.error();+ }+ ASSERT_TRUE(add_op.ok());+ }++ std::map<std::string, std::string> req_params = {+ {"collection", "Foods"},+ {"q", "taco"},+ {"query_by", "title,summary"},+ {"infix", "always,always"},+ {"filter_by", "rating:>=2 && rating:<=4"},+ };+ nlohmann::json embedded_params;+ std::string json_res;+ auto now_ts = std::chrono::duration_cast<std::chrono::microseconds>(+ std::chrono::system_clock::now().time_since_epoch()).count();++ auto search_op = collectionManager.do_search(req_params, embedded_params, json_res, now_ts);+ nlohmann::json result = nlohmann::json::parse(json_res);++ ASSERT_EQ(2, result["found"].get<size_t>());+ ASSERT_EQ(2, result["hits"].size());+ ASSERT_EQ("1", result["hits"][0]["document"]["id"].get<std::string>());+ ASSERT_EQ(3, result["hits"][0]["document"]["rating"].get<std::int32_t>());+ ASSERT_EQ("Salad With Taco Toppings", result["hits"][0]["document"]["title"].get<std::string>());+ ASSERT_EQ("0", result["hits"][1]["document"]["id"].get<std::string>());+ ASSERT_EQ(2, result["hits"][1]["document"]["rating"].get<std::int32_t>());+ ASSERT_EQ("Spicy Chicken Tacos", result["hits"][1]["document"]["title"].get<std::string>());+collectionManager.drop_collection("coll1");}