mirror of
https://github.com/typesense/typesense.git
synced 2025-05-16 03:12:32 +08:00
Float fields used as sort field should accept integers.
This commit is contained in:
parent
9cbc90f2b7
commit
412efbb500
@ -130,11 +130,11 @@ Option<uint32_t> Index::index_in_memory(const nlohmann::json &document, uint32_t
|
||||
field_pair.second.type == field_types::FLOAT || field_pair.second.type == field_types::BOOL) {
|
||||
spp::sparse_hash_map<uint32_t, number_t> *doc_to_score = sort_index.at(field_pair.first);
|
||||
|
||||
if(document[field_pair.first].is_number_integer()) {
|
||||
if(field_pair.second.is_integer() ) {
|
||||
doc_to_score->emplace(seq_id, document[field_pair.first].get<int64_t>());
|
||||
} else if(document[field_pair.first].is_number_float()) {
|
||||
} else if(field_pair.second.is_float()) {
|
||||
doc_to_score->emplace(seq_id, document[field_pair.first].get<float>());
|
||||
} else if(document[field_pair.first].is_boolean()) {
|
||||
} else if(field_pair.second.is_bool()) {
|
||||
doc_to_score->emplace(seq_id, (int64_t) document[field_pair.first].get<bool>());
|
||||
}
|
||||
}
|
||||
|
@ -435,6 +435,21 @@ TEST_F(CollectionTest, WildcardQuery) {
|
||||
ASSERT_TRUE(results_op.ok());
|
||||
ASSERT_EQ(3, results["hits"].size());
|
||||
ASSERT_EQ(25, results["found"].get<uint32_t>());
|
||||
|
||||
// wildcard query with no filters and ASC sort
|
||||
std::vector<sort_by> sort_fields = { sort_by("points", "ASC") };
|
||||
results = collection->search("*", query_fields, "", {}, sort_fields, 0, 3, 1, FREQUENCY, false).get();
|
||||
ASSERT_EQ(3, results["hits"].size());
|
||||
ASSERT_EQ(25, results["found"].get<uint32_t>());
|
||||
|
||||
std::vector<std::string> ids = {"21", "24", "17"};
|
||||
|
||||
for(size_t i = 0; i < results["hits"].size(); i++) {
|
||||
nlohmann::json result = results["hits"].at(i);
|
||||
std::string result_id = result["document"]["id"];
|
||||
std::string id = ids.at(i);
|
||||
ASSERT_STREQ(id.c_str(), result_id.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(CollectionTest, PrefixSearching) {
|
||||
|
@ -3,5 +3,5 @@
|
||||
{"title": "Jeremy Howard", "score": 7.812, "average": 0.001 }
|
||||
{"title": "Jeremy Howard", "score": 0.0, "average": 11.533 }
|
||||
{"title": "Jeremy Howard", "score": -9.999, "average": -11.38 }
|
||||
{"title": "Jeremy Howard", "score": -9.999, "average": 19.38 }
|
||||
{"title": "Jeremy Howard", "score": -9.999, "average": 300 }
|
||||
{"title": "Jeremy Howard", "score": -9.999, "average": -21.38 }
|
Loading…
x
Reference in New Issue
Block a user