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
Return error for `filter_by` on non-indexed field.
Harpreet Sangarae857b5dcd3c
diff --git a/src/filter_result_iterator.cpp b/src/filter_result_iterator.cppindex a85721bb..bf826ae4 100644--- a/src/filter_result_iterator.cpp+++ b/src/filter_result_iterator.cpp@@ -654,6 +654,7 @@ void filter_result_iterator_t::init() {}if (!index->field_is_indexed(a_filter.field_name)) {+ status = Option<bool>(400, "Cannot filter on non-indexed field `" + a_filter.field_name + "`.");is_valid = false;return;}diff --git a/test/collection_filtering_test.cpp b/test/collection_filtering_test.cppindex 159989c9..e82d083a 100644--- a/test/collection_filtering_test.cpp+++ b/test/collection_filtering_test.cpp@@ -2236,3 +2236,33 @@ TEST_F(CollectionFilteringTest, LargeFilterToken) {results = coll->search("*", query_fields, "uri:" + token, {}, sort_fields, {0}, 10, 1, FREQUENCY, {false}).get();ASSERT_EQ(0, results["hits"].size());}++TEST_F(CollectionFilteringTest, NonIndexedFiltering) {+ nlohmann::json json =+ R"({+ "name": "NonIndexedCollection",+ "fields": [+ {"name": "uri", "type": "string"},+ {"name": "non_index", "type": "string", "index": false, "optional": true}+ ]+ })"_json;++ auto op = collectionManager.create_collection(json);+ ASSERT_TRUE(op.ok());+ auto coll = op.get();++ json.clear();+ json = R"({+ "uri": "token",+ "non_index": "foo"+ })"_json;+ auto add_op = coll->add(json.dump());+ ASSERT_TRUE(add_op.ok());++ auto search_op = coll->search("*", {}, "", {}, sort_fields, {0}, 10, 1, FREQUENCY, {false});+ ASSERT_EQ(1, search_op.get()["hits"].size());++ search_op = coll->search("*", {}, "non_index:= bar", {}, sort_fields, {0}, 10, 1, FREQUENCY, {false});+ ASSERT_FALSE(search_op.ok());+ ASSERT_EQ("Cannot filter on non-indexed field `non_index`.", search_op.error());+}