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
Phrase search highlight.
Kishore Nallan9e00f3a73fd6
diff --git a/src/collection.cpp b/src/collection.cppindex 4adbe23b..1d38de7f 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -1101,7 +1101,14 @@ Option<nlohmann::json> Collection::search(const std::string & raw_query, const sfor(size_t i = 0; i < fields_highlighted_vec.size(); i++) {const std::string& field_name = fields_highlighted_vec[i];- const std::vector<std::string>& q_tokens = field_query_tokens[fields_highlighted_indices[i]].q_include_tokens;+ std::vector<std::string> q_tokens = field_query_tokens[fields_highlighted_indices[i]].q_include_tokens;++ // we will also add phrase search tokens to the list+ for(auto& phrase: field_query_tokens[fields_highlighted_indices[i]].q_phrases) {+ for(auto& token: phrase) {+ q_tokens.push_back(token);+ }+ }if(search_schema.count(field_name) == 0) {continue;diff --git a/test/collection_specific_test.cpp b/test/collection_specific_test.cppindex 528485ea..6f140825 100644--- a/test/collection_specific_test.cpp+++ b/test/collection_specific_test.cpp@@ -2079,17 +2079,21 @@ TEST_F(CollectionSpecificTest, PhraseSearch) {results = coll1->search(R"("down there by")", {"title"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}, 10).get();ASSERT_EQ(1, results["hits"].size());ASSERT_EQ("1", results["hits"][0]["document"]["id"].get<std::string>());+ ASSERT_EQ("<mark>Down</mark> <mark>There</mark> <mark>by</mark> the Train", results["hits"][0]["highlights"][0]["snippet"].get<std::string>());// phrase search with exclusionresults = coll1->search(R"("by the" -train)", {"title"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}, 10).get();ASSERT_EQ(1, results["hits"].size());ASSERT_EQ("0", results["hits"][0]["document"]["id"].get<std::string>());+ ASSERT_EQ("<mark>Then</mark> and <mark>there</mark> <mark>by</mark> <mark>the</mark> down", results["hits"][0]["highlights"][0]["snippet"].get<std::string>());// exclusion of an entire phraseresults = coll1->search(R"(-"by the down")", {"title"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}, 10).get();ASSERT_EQ(2, results["hits"].size());ASSERT_EQ("2", results["hits"][0]["document"]["id"].get<std::string>());ASSERT_EQ("1", results["hits"][1]["document"]["id"].get<std::string>());+ ASSERT_EQ(0, results["hits"][0]["highlights"].size());+ ASSERT_EQ(0, results["hits"][1]["highlights"].size());results = coll1->search(R"(-"by the")", {"title"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}, 10).get();ASSERT_EQ(1, results["hits"].size());@@ -2125,6 +2129,7 @@ TEST_F(CollectionSpecificTest, PhraseSearch) {results = coll1->search(R"("by the" "then and")", {"title"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}, 10).get();ASSERT_EQ(1, results["hits"].size());ASSERT_EQ("0", results["hits"][0]["document"]["id"].get<std::string>());+ ASSERT_EQ("<mark>Then</mark> <mark>and</mark> there <mark>by</mark> <mark>the</mark> down", results["hits"][0]["highlights"][0]["snippet"].get<std::string>());results = coll1->search(R"("by the" "there by")", {"title"}, "", {}, {}, {0}, 10, 1, FREQUENCY, {false}, 10).get();ASSERT_EQ(2, results["hits"].size());