diff --git a/src/art.cpp b/src/art.cpp index 72e06d7f..c37d01d3 100644 --- a/src/art.cpp +++ b/src/art.cpp @@ -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}; diff --git a/test/collection_sorting_test.cpp b/test/collection_sorting_test.cpp index aed04566..8dcb686f 100644 --- a/test/collection_sorting_test.cpp +++ b/test/collection_sorting_test.cpp @@ -237,6 +237,36 @@ TEST_F(CollectionSortingTest, FrequencyOrderedTokensWithoutDefaultSortingField) ASSERT_FALSE(found_end); } +TEST_F(CollectionSortingTest, TokenOrderingOnFloatValue) { + Collection *coll1; + std::vector 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 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()); + ASSERT_EQ("9", results["hits"][1]["document"]["id"].get()); + ASSERT_EQ("8", results["hits"][2]["document"]["id"].get()); +} + TEST_F(CollectionSortingTest, Int64AsDefaultSortingField) { Collection *coll_mul_fields;