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
Call the string similarity score as _text_match to reduce ambiguity.
kishorenc559ee3369a90
diff --git a/include/field.h b/include/field.hindex 04f0ad49..95c1fcbe 100644--- a/include/field.h+++ b/include/field.h@@ -121,7 +121,7 @@ namespace sort_field_const {static const std::string order = "order";static const std::string asc = "ASC";static const std::string desc = "DESC";- static const std::string match_score = "_match_score";+ static const std::string text_match = "_text_match";}struct sort_by {diff --git a/src/collection.cpp b/src/collection.cppindex 58cc49e6..e833c9fb 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -515,7 +515,7 @@ Option<nlohmann::json> Collection::search(const std::string & query, const std::std::vector<sort_by> sort_fields_std;for(const sort_by & _sort_field: sort_fields) {- if(_sort_field.name != sort_field_const::match_score && sort_schema.count(_sort_field.name) == 0) {+ if(_sort_field.name != sort_field_const::text_match && sort_schema.count(_sort_field.name) == 0) {std::string error = "Could not find a field named `" + _sort_field.name + "` in the schema for sorting.";return Option<nlohmann::json>(404, error);}@@ -543,20 +543,20 @@ Option<nlohmann::json> Collection::search(const std::string & query, const std::4. THREE: do nothing*/if(sort_fields_std.empty()) {- sort_fields_std.emplace_back(sort_field_const::match_score, sort_field_const::desc);+ sort_fields_std.emplace_back(sort_field_const::text_match, sort_field_const::desc);sort_fields_std.emplace_back(default_sorting_field, sort_field_const::desc);}bool found_match_score = false;for(const auto & sort_field : sort_fields) {- if(sort_field.name == sort_field_const::match_score) {+ if(sort_field.name == sort_field_const::text_match) {found_match_score = true;break;}}if(!found_match_score && sort_fields.size() < 3) {- sort_fields_std.emplace_back(sort_field_const::match_score, sort_field_const::desc);+ sort_fields_std.emplace_back(sort_field_const::text_match, sort_field_const::desc);}if(sort_fields_std.size() > 3) {diff --git a/src/index.cpp b/src/index.cppindex 60a9e3d2..71dd092b 100644--- a/src/index.cpp+++ b/src/index.cpp@@ -1454,7 +1454,7 @@ void Index::score_results(const std::vector<sort_by> & sort_fields, const uint16sort_order[i] = -1;}- field_values[i] = (sort_fields[i].name != sort_field_const::match_score) ?+ field_values[i] = (sort_fields[i].name != sort_field_const::text_match) ?sort_index.at(sort_fields[i].name) :nullptr;}diff --git a/test/collection_test.cpp b/test/collection_test.cppindex 5c0be7dc..bc7fd114 100644--- a/test/collection_test.cpp+++ b/test/collection_test.cpp@@ -30,7 +30,7 @@ protected:};query_fields = {"title"};- sort_fields = { sort_by("_match_score", "DESC"), sort_by("points", "DESC") };+ sort_fields = { sort_by(sort_field_const::text_match, "DESC"), sort_by("points", "DESC") };collection = collectionManager.get_collection("collection");if(collection == nullptr) {@@ -152,7 +152,7 @@ TEST_F(CollectionTest, ExactPhraseSearch) {"What is the power requirement of a <mark>rocket</mark> <mark>launch</mark> these days?");// Check ASC sort order- std::vector<sort_by> sort_fields_asc = { sort_by("_match_score", "DESC"), sort_by("points", "ASC") };+ std::vector<sort_by> sort_fields_asc = { sort_by(sort_field_const::text_match, "DESC"), sort_by("points", "ASC") };results = collection->search("rocket launch", query_fields, "", facets, sort_fields_asc, 0, 10).get();ASSERT_EQ(5, results["hits"].size());ASSERT_EQ(5, results["found"].get<uint32_t>());@@ -1980,7 +1980,7 @@ TEST_F(CollectionTest, SearchLargeTextField) {field("age", field_types::INT32, false),};- std::vector<sort_by> sort_fields = { sort_by("_match_score", "DESC"), sort_by("age", "DESC") };+ std::vector<sort_by> sort_fields = { sort_by(sort_field_const::text_match, "DESC"), sort_by("age", "DESC") };coll_large_text = collectionManager.get_collection("coll_large_text");if(coll_large_text == nullptr) {