Skip to content

Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences

Float fields used as sort field should accept integers.

kishorenc412efbb500ef
diff --git a/src/index.cpp b/src/index.cpp
index a3554df6..c7e5ca32 100644
--- a/src/index.cpp
+++ b/src/index.cpp
@@ -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>());
}
}
diff --git a/test/collection_test.cpp b/test/collection_test.cpp
index 92bf3dd2..3a8405af 100644
--- a/test/collection_test.cpp
+++ b/test/collection_test.cpp
@@ -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) {
diff --git a/test/float_documents.jsonl b/test/float_documents.jsonl
index 65de0262..9ae520f7 100644
--- a/test/float_documents.jsonl
+++ b/test/float_documents.jsonl
@@ -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 }
\ No newline at end of file