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
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Fix comparator for facet sorting.
kishorenc2dfec1881197
diff --git a/include/collection.h b/include/collection.hindex 04c15526..971527eb 100644--- a/include/collection.h+++ b/include/collection.h@@ -156,7 +156,7 @@ private:static bool facet_count_compare(const std::pair<uint64_t, facet_count_t>& a,const std::pair<uint64_t, facet_count_t>& b) {- return std::tie(a.second.count, a.first) > std::tie(b.second.count, a.first);+ return std::tie(a.second.count, a.first) > std::tie(b.second.count, b.first);}static bool facet_count_str_compare(const facet_value_t& a,diff --git a/test/collection_test.cpp b/test/collection_test.cppindex 6e7b0875..49ad46ba 100644--- a/test/collection_test.cpp+++ b/test/collection_test.cpp@@ -1827,14 +1827,13 @@ TEST_F(CollectionTest, FacetCounts) {ASSERT_EQ(5, results["hits"].size());ASSERT_EQ(1, results["facet_counts"].size());- ASSERT_EQ(2, results["facet_counts"][0].size());- ASSERT_EQ("tags", results["facet_counts"][0]["field_name"]);+ ASSERT_STREQ("tags", results["facet_counts"][0]["field_name"].get<std::string>().c_str());ASSERT_EQ(2, results["facet_counts"][0]["counts"].size());- ASSERT_EQ("gold", results["facet_counts"][0]["counts"][0]["value"]);+ ASSERT_STREQ("silver", results["facet_counts"][0]["counts"][0]["value"].get<std::string>().c_str());ASSERT_EQ(3, (int) results["facet_counts"][0]["counts"][0]["count"]);- ASSERT_EQ("silver", results["facet_counts"][0]["counts"][1]["value"]);+ ASSERT_STREQ("gold", results["facet_counts"][0]["counts"][1]["value"].get<std::string>().c_str());ASSERT_EQ(3, (int) results["facet_counts"][0]["counts"][1]["count"]);// 2 facets, 1 text filter with no filters@@ -1846,11 +1845,11 @@ TEST_F(CollectionTest, FacetCounts) {ASSERT_EQ(5, results["hits"].size());ASSERT_EQ(2, results["facet_counts"].size());- ASSERT_EQ("tags", results["facet_counts"][0]["field_name"]);- ASSERT_EQ("name_facet", results["facet_counts"][1]["field_name"]);+ ASSERT_STREQ("tags", results["facet_counts"][0]["field_name"].get<std::string>().c_str());+ ASSERT_STREQ("name_facet", results["facet_counts"][1]["field_name"].get<std::string>().c_str());// facet value must one that's stored, not indexed (i.e. no tokenization/standardization)- ASSERT_EQ("Jeremy Howard", results["facet_counts"][1]["counts"][0]["value"]);+ ASSERT_STREQ("Jeremy Howard", results["facet_counts"][1]["counts"][0]["value"].get<std::string>().c_str());ASSERT_EQ(5, (int) results["facet_counts"][1]["counts"][0]["count"]);// facet with filters@@ -1861,7 +1860,7 @@ TEST_F(CollectionTest, FacetCounts) {ASSERT_EQ(3, results["hits"].size());ASSERT_EQ(1, results["facet_counts"].size());- ASSERT_EQ("tags", results["facet_counts"][0]["field_name"]);+ ASSERT_STREQ("tags", results["facet_counts"][0]["field_name"].get<std::string>().c_str());ASSERT_EQ(2, (int) results["facet_counts"][0]["counts"][0]["count"]);ASSERT_EQ(1, (int) results["facet_counts"][0]["counts"][1]["count"]);ASSERT_EQ(1, (int) results["facet_counts"][0]["counts"][2]["count"]);@@ -2652,3 +2651,26 @@ TEST_F(CollectionTest, PruneFieldsFromDocument) {Collection::prune_document(document, spp::sparse_hash_set<std::string>(), {"notfound"});ASSERT_EQ(4, document.size());}++TEST_F(CollectionTest, StringArrayFieldShouldNotAllowPlainString) {+ Collection *coll1;++ std::vector<field> fields = {field("categories", field_types::STRING_ARRAY, true),+ field("points", field_types::INT32, false)};++ std::vector<sort_by> sort_fields = {sort_by("points", "DESC")};++ coll1 = collectionManager.get_collection("coll1");+ if (coll1 == nullptr) {+ coll1 = collectionManager.create_collection("coll1", fields, "points").get();+ }++ nlohmann::json doc;+ doc["id"] = "100";+ doc["categories"] = "Should not be allowed!";+ doc["points"] = 25;++ auto add_op = coll1->add(doc.dump());+ ASSERT_FALSE(add_op.ok());+ ASSERT_STREQ("Field `categories` must be a string array.", add_op.error().c_str());+}\ No newline at end of file