Call the string similarity score as _text_match to reduce ambiguity.

This commit is contained in:
kishorenc 2020-04-05 07:54:10 +05:30
parent 8845917020
commit 559ee3369a
4 changed files with 9 additions and 9 deletions

View File

@ -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 {

View File

@ -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) {

View File

@ -1454,7 +1454,7 @@ void Index::score_results(const std::vector<sort_by> & sort_fields, const uint16
sort_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;
}

View File

@ -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) {