Fix ordering of prefix leaves.

This commit is contained in:
Kishore Nallan 2021-12-30 22:03:15 +05:30
parent 35a2a05709
commit 94f05ee2b3
2 changed files with 31 additions and 1 deletions

View File

@ -432,7 +432,7 @@ static void add_document_to_leaf(art_document *document, art_leaf *leaf) {
static art_leaf* make_leaf(const unsigned char *key, uint32_t key_len, art_document *document) {
art_leaf *l = (art_leaf *) malloc(sizeof(art_leaf) + key_len);
l->key_len = key_len;
l->max_score = 0;
l->max_score = document->score;
uint32_t ids[1] = {document->id};
uint32_t offset_index[1] = {0};

View File

@ -237,6 +237,36 @@ TEST_F(CollectionSortingTest, FrequencyOrderedTokensWithoutDefaultSortingField)
ASSERT_FALSE(found_end);
}
TEST_F(CollectionSortingTest, TokenOrderingOnFloatValue) {
Collection *coll1;
std::vector<field> fields = {field("title", field_types::STRING, false),
field("points", field_types::FLOAT, false)};
coll1 = collectionManager.get_collection("coll1").get();
if(coll1 == nullptr) {
coll1 = collectionManager.create_collection("coll1", 1, fields, "points").get();
}
std::vector<std::string> tokens = {
"enter", "elephant", "enamel", "ercot", "enyzme", "energy",
"epoch", "epyc", "express", "everest", "end"
};
for(size_t i = 0; i < tokens.size(); i++) {
std::string title = tokens[i];
float fpoint = (0.01 * i);
nlohmann::json doc;
doc["title"] = title;
doc["points"] = fpoint;
coll1->add(doc.dump());
}
auto results = coll1->search("e", {"title"}, "", {}, {}, {0}, 3, 1, MAX_SCORE, {true}).get();
ASSERT_EQ("10", results["hits"][0]["document"]["id"].get<std::string>());
ASSERT_EQ("9", results["hits"][1]["document"]["id"].get<std::string>());
ASSERT_EQ("8", results["hits"][2]["document"]["id"].get<std::string>());
}
TEST_F(CollectionSortingTest, Int64AsDefaultSortingField) {
Collection *coll_mul_fields;