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
If no `sort_by` fields are provided, sort descending on `default_sorting_field`.
Kishore Nallane43a101c5085
diff --git a/src/api.cpp b/src/api.cppindex 3b9ceeef..0fb89d31 100644--- a/src/api.cpp+++ b/src/api.cpp@@ -242,7 +242,7 @@ void get_search(http_req & req, http_res & res) {bool prefix = (req.params[PREFIX] == "true");if(req.params.count(RANK_TOKENS_BY) == 0) {- if(prefix && !collection->get_default_sorting_field().empty()) {+ if(prefix) {req.params[RANK_TOKENS_BY] = "DEFAULT_SORTING_FIELD";} else {req.params[RANK_TOKENS_BY] = "TERM_FREQUENCY";diff --git a/src/collection.cpp b/src/collection.cppindex 6a374316..a9d1df12 100644--- a/src/collection.cpp+++ b/src/collection.cpp@@ -405,6 +405,10 @@ Option<nlohmann::json> Collection::search(std::string query, const std::vector<ssort_fields_std.push_back({_sort_field.name, sort_order});}+ if(sort_fields_std.empty()) {+ sort_fields_std.push_back({default_sorting_field, sort_field_const::desc});+ }+// check for valid paginationif(page < 1) {std::string message = "Page must be an integer of value greater than 0.";diff --git a/test/collection_test.cpp b/test/collection_test.cppindex 5788a69b..91008b72 100644--- a/test/collection_test.cpp+++ b/test/collection_test.cpp@@ -1334,12 +1334,12 @@ TEST_F(CollectionTest, SortingOrder) {}// With empty list of sort_by fields:- // should be ordered desc on the seq_id, since the match score will be the same for all records.+ // should be ordered desc on the default sorting field, since the match score will be the same for all records.sort_fields = { };- results = coll_mul_fields->search("the", query_fields, "", facets, sort_fields, 0, 15, 1, FREQUENCY, false).get();- ASSERT_EQ(10, results["hits"].size());+ results = coll_mul_fields->search("of", query_fields, "", facets, sort_fields, 0, 10, 1, FREQUENCY, false).get();+ ASSERT_EQ(5, results["hits"].size());- ids = {"17", "16", "13", "11", "10", "8", "6", "4", "1", "0"};+ ids = {"11", "12", "5", "4", "17"};for(size_t i = 0; i < results["hits"].size(); i++) {nlohmann::json result = results["hits"].at(i);