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
Change structure of hightlight in response to allow sending the matched array index.
Kishore Nallan33552ca627cc
diff --git a/src/collection.cpp b/src/collection.cppindex f8630eac..85ee8d45 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -625,7 +625,12 @@ Option<nlohmann::json> Collection::search(std::string query, const std::vector<s}wrapper_doc["highlight"] = nlohmann::json::object();- wrapper_doc["highlight"][field_name] = snippet_stream.str();+ wrapper_doc["highlight"][field_name] = nlohmann::json::object();+ wrapper_doc["highlight"][field_name]["value"] = snippet_stream.str();++ if(search_field.type == field_types::STRING_ARRAY) {+ wrapper_doc["highlight"][field_name]["index"] = matched_array_index;+ }for (auto it = leaf_to_indices.begin(); it != leaf_to_indices.end(); it++) {delete [] it->second;diff --git a/test/collection_test.cpp b/test/collection_test.cppindex 6c614b8f..f7b1b8d2 100644--- a/test/collection_test.cpp+++ b/test/collection_test.cpp@@ -534,7 +534,9 @@ TEST_F(CollectionTest, ArrayStringFieldHighlight) {ASSERT_STREQ(id.c_str(), result_id.c_str());}- ASSERT_STREQ(results["hits"][0]["highlight"]["tags"].get<std::string>().c_str(), "<mark>truth</mark> <mark>about</mark>");+ ASSERT_STREQ(results["hits"][0]["highlight"]["tags"]["value"].get<std::string>().c_str(),+ "<mark>truth</mark> <mark>about</mark>");+ ASSERT_EQ(results["hits"][0]["highlight"]["tags"]["index"].get<size_t>(), 2);results = coll_array_text->search("forever truth", query_fields, "", facets, sort_fields, 0, 10, 1, FREQUENCY,false, 0).get();@@ -549,7 +551,9 @@ TEST_F(CollectionTest, ArrayStringFieldHighlight) {ASSERT_STREQ(id.c_str(), result_id.c_str());}- ASSERT_STREQ(results["hits"][0]["highlight"]["tags"].get<std::string>().c_str(), "the <mark>truth</mark>");+ ASSERT_STREQ(results["hits"][0]["highlight"]["tags"]["value"].get<std::string>().c_str(),+ "the <mark>truth</mark>");+ ASSERT_EQ(results["hits"][0]["highlight"]["tags"]["index"].get<size_t>(), 0);results = coll_array_text->search("truth", query_fields, "", facets, sort_fields, 0, 10, 1, FREQUENCY,false, 0).get();