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

Add test for unindexed regular sorting field.

Kishore Nallana9b730ec3ef9
diff --git a/test/collection_sorting_test.cpp b/test/collection_sorting_test.cpp
index ab6d6584..d8806f3f 100644
--- a/test/collection_sorting_test.cpp
+++ b/test/collection_sorting_test.cpp
@@ -1985,7 +1985,7 @@ TEST_F(CollectionSortingTest, WildcardSearchSequenceIdSort) {
ASSERT_EQ(30, res["found"].get<size_t>());
}
-TEST_F(CollectionSortingTest, DefaultSortingFieldNotIndexed) {
+TEST_F(CollectionSortingTest, DefaultSortingFieldStringNotIndexed) {
nlohmann::json schema = R"({
"name": "coll1",
"fields": [
@@ -2008,6 +2008,29 @@ TEST_F(CollectionSortingTest, DefaultSortingFieldNotIndexed) {
"non-indexed field.", res_op.error());
}
+TEST_F(CollectionSortingTest, SortingFieldNotIndexed) {
+ nlohmann::json schema = R"({
+ "name": "coll1",
+ "fields": [
+ {"name": "category", "type": "int32", "sort": true, "index": false}
+ ]
+ })"_json;
+
+ Collection* coll1 = collectionManager.create_collection(schema).get();
+
+ nlohmann::json doc;
+ doc["category"] = 100;
+ ASSERT_TRUE(coll1->add(doc.dump()).ok());
+
+ std::vector<sort_by> sort_fields = {
+ sort_by("category", "DESC"),
+ };
+
+ auto res_op = coll1->search("*", {}, "", {}, sort_fields, {2}, 10, 1, FREQUENCY, {true}, 0);
+ ASSERT_FALSE(res_op.ok());
+ ASSERT_EQ("Could not find a field named `category` in the schema for sorting.", res_op.error());
+}
+
TEST_F(CollectionSortingTest, OptionalFilteringViaSortingWildcard) {
std::string coll_schema = R"(
{