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

When infix search does not find highlight, use normal search.

Kishore Nallan3ed925aac610
diff --git a/src/collection.cpp b/src/collection.cpp
index 53447b38..4a7a134f 100644
--- a/src/collection.cpp
+++ b/src/collection.cpp
@@ -3972,7 +3972,9 @@ void Collection::highlight_result(const std::string& raw_query, const field &sea
}
}
- } else {
+ }
+
+ if(!is_infix_search || match_indices.empty()) {
/*std::string qtok_buff;
for(auto it = qtoken_leaves.begin(); it != qtoken_leaves.end(); ++it) {
diff --git a/test/collection_infix_search_test.cpp b/test/collection_infix_search_test.cpp
index 7e15b0a2..52c69195 100644
--- a/test/collection_infix_search_test.cpp
+++ b/test/collection_infix_search_test.cpp
@@ -155,6 +155,34 @@ TEST_F(CollectionInfixSearchTest, InfixOnArray) {
collectionManager.drop_collection("coll1");
}
+TEST_F(CollectionInfixSearchTest, InfixNoMatchButRegularHighlight) {
+ std::vector<field> fields = {field("title", field_types::STRING, false, false, true, "", -1, 1),
+ field("points", field_types::INT32, false),};
+
+ Collection* coll1 = collectionManager.create_collection("coll1", 1, fields, "points").get();
+
+ nlohmann::json doc;
+ doc["id"] = "0";
+ doc["title"] = "White Bread";
+ doc["points"] = 100;
+ ASSERT_TRUE(coll1->add(doc.dump()).ok());
+
+ auto results = coll1->search("brown bread",
+ {"title"}, "", {}, {}, {0}, 3, 1, FREQUENCY, {true}, 5,
+ spp::sparse_hash_set<std::string>(),
+ spp::sparse_hash_set<std::string>(), 10, "", 30, 4, "model_numbers", 20, {}, {}, {}, 0,
+ "<mark>", "</mark>", {}, 1000, true, false, true, "", false, 6000 * 1000, 4, 7, fallback,
+ 4, {always}).get();
+
+ ASSERT_EQ(1, results["found"].get<size_t>());
+ ASSERT_EQ(1, results["hits"].size());
+ ASSERT_STREQ("0", results["hits"][0]["document"]["id"].get<std::string>().c_str());
+
+ ASSERT_EQ(1, results["hits"][0]["highlights"].size());
+ ASSERT_EQ("White <mark>Bread</mark>", results["hits"][0]["highlight"]["title"]["snippet"].get<std::string>());
+ collectionManager.drop_collection("coll1");
+}
+
TEST_F(CollectionInfixSearchTest, InfixWithFiltering) {
std::vector<field> fields = {field("title", field_types::STRING, false, false, true, "", -1, 1),
field("points", field_types::INT32, false),};