Merge branch 'v0.24-changes' into v0.24-nested

This commit is contained in:
Kishore Nallan 2022-08-17 10:23:11 +05:30
commit 848e2138f2
4 changed files with 50 additions and 5 deletions

View File

@ -8,7 +8,7 @@
struct KV {
uint8_t field_id{};
uint8_t match_score_index{};
int8_t match_score_index{};
uint16_t query_index{};
uint16_t array_index{};
uint32_t token_bits{};

View File

@ -33,6 +33,20 @@ struct sort_fields_guard_t {
}
};
struct sort_fields_guard_t {
std::vector<sort_by> sort_fields_std;
~sort_fields_guard_t() {
for(auto& sort_by_clause: sort_fields_std) {
if(sort_by_clause.eval.ids) {
delete [] sort_by_clause.eval.ids;
sort_by_clause.eval.ids = nullptr;
sort_by_clause.eval.size = 0;
}
}
}
};
Collection::Collection(const std::string& name, const uint32_t collection_id, const uint64_t created_at,
const uint32_t next_seq_id, Store *store, const std::vector<field> &fields,
const std::string& default_sorting_field,
@ -1522,7 +1536,7 @@ Option<nlohmann::json> Collection::search(const std::string & raw_query,
if(field_order_kv->match_score_index == CURATED_RECORD_IDENTIFIER) {
wrapper_doc["curated"] = true;
} else {
} else if(field_order_kv->match_score_index >= 0) {
wrapper_doc["text_match"] = field_order_kv->scores[field_order_kv->match_score_index];
wrapper_doc["text_match_info"] = nlohmann::json::object();

View File

@ -3521,7 +3521,7 @@ void Index::compute_sort_scores(const std::vector<sort_by>& sort_fields, const i
filter_index = found_index;
}
scores[0] = int64_t(found);
scores[2] = int64_t(found);
} else {
auto it = field_values[2]->find(seq_id);
scores[2] = (it == field_values[2]->end()) ? default_score : it->second;
@ -3739,7 +3739,7 @@ void Index::do_infix_search(const size_t num_search_fields, const std::vector<se
0, match_score, seq_id, sort_order, false, false, false, 1, -1, {});
int64_t scores[3] = {0};
int64_t match_score_index = 0;
int64_t match_score_index = -1;
compute_sort_scores(sort_fields, sort_order, field_values, geopoint_indices, seq_id, filter_index,
100, scores, match_score_index);
@ -4070,7 +4070,7 @@ void Index::search_wildcard(const std::vector<filter>& filters,
match_score, seq_id, sort_order, false, false, false, 1, -1, plists);
int64_t scores[3] = {0};
int64_t match_score_index = 0;
int64_t match_score_index = -1;
compute_sort_scores(sort_fields, sort_order, field_values, geopoint_indices, seq_id, filter_index,
100, scores, match_score_index);

View File

@ -1737,6 +1737,37 @@ TEST_F(CollectionSortingTest, RepeatingTokenRanking) {
collectionManager.drop_collection("coll1");
}
TEST_F(CollectionSortingTest, SortingDoesNotHaveTextMatchComponent) {
// text_match_score field should not be present in response
std::vector<field> fields = {field("title", field_types::STRING, false),
field("points", field_types::INT32, false),};
Collection* coll1 = collectionManager.create_collection("coll1", 1, fields, "points").get();
nlohmann::json doc1;
doc1["id"] = "0";
doc1["title"] = "Test Title";
doc1["points"] = 100;
ASSERT_TRUE(coll1->add(doc1.dump()).ok());
sort_fields = {
sort_by("points", "DESC"),
sort_by("points", "DESC"),
sort_by("points", "DESC"),
};
auto results = coll1->search("test", {"title"}, "", {}, sort_fields, {2}, 10, 1, FREQUENCY, {true}).get();
ASSERT_EQ(1, results["hits"].size());
ASSERT_EQ(0, results["hits"][0].count("text_match"));
results = coll1->search("*", {}, "", {}, sort_fields, {2}, 10, 1, FREQUENCY, {true}).get();
ASSERT_EQ(1, results["hits"].size());
ASSERT_EQ(0, results["hits"][0].count("text_match"));
collectionManager.drop_collection("coll1");
}
TEST_F(CollectionSortingTest, IntegerFloatAndBoolShouldDefaultSortTrue) {
std::string coll_schema = R"(
{