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

Fix test.

Kishore Nallan4395e3d81e6d
diff --git a/src/typesense_server_utils.cpp b/src/typesense_server_utils.cpp
index 1800dc4a..c362f60c 100644
--- a/src/typesense_server_utils.cpp
+++ b/src/typesense_server_utils.cpp
@@ -100,6 +100,7 @@ void init_cmdline_options(cmdline::parser & options, int argc, char **argv) {
options.add<bool>("reset-peers-on-error", '\0', "Reset node's peers on clustering error. Default: false.", false, false);
options.add<int>("log-slow-searches-time-ms", '\0', "When >= 0, searches that take longer than this duration are logged.", false, 30*1000);
+ options.add<int>("cache-num-entries", '\0', "Number of entries to cache.", false, 1000);
// DEPRECATED
options.add<std::string>("listen-address", 'h', "[DEPRECATED: use `api-address`] Address to which Typesense API service binds.", false, "0.0.0.0");
diff --git a/test/collection_operations_test.cpp b/test/collection_operations_test.cpp
index e736b226..aaf22c46 100644
--- a/test/collection_operations_test.cpp
+++ b/test/collection_operations_test.cpp
@@ -53,6 +53,7 @@ TEST_F(CollectionOperationsTest, IncrementInt32Value) {
ASSERT_TRUE(coll->add(doc.dump()).ok());
// increment by 1
+ doc.erase("points");
doc["id"] = "0";
doc["$operations"] = R"({"increment": {"points": 1}})"_json;
ASSERT_TRUE(coll->add(doc.dump(), UPDATE).ok());
@@ -73,6 +74,9 @@ TEST_F(CollectionOperationsTest, IncrementInt32Value) {
res = coll->search("*", {"title"}, "points:111", {}, {}, {0}, 3, 1, FREQUENCY, {false}).get();
ASSERT_EQ(1, res["hits"].size());
ASSERT_EQ(3, res["hits"][0]["document"].size());
+ ASSERT_EQ("0", res["hits"][0]["document"]["id"].get<std::string>());
+ ASSERT_EQ("Sherlock Holmes", res["hits"][0]["document"]["title"].get<std::string>());
+ ASSERT_EQ(111, res["hits"][0]["document"]["points"].get<size_t>());
// decrement by 10 using negative number
doc["id"] = "0";
@@ -82,12 +86,19 @@ TEST_F(CollectionOperationsTest, IncrementInt32Value) {
res = coll->search("*", {"title"}, "points:101", {}, {}, {0}, 3, 1, FREQUENCY, {false}).get();
ASSERT_EQ(1, res["hits"].size());
ASSERT_EQ(3, res["hits"][0]["document"].size());
+ ASSERT_EQ("0", res["hits"][0]["document"]["id"].get<std::string>());
+ ASSERT_EQ("Sherlock Holmes", res["hits"][0]["document"]["title"].get<std::string>());
+ ASSERT_EQ(101, res["hits"][0]["document"]["points"].get<size_t>());
- // bad field - should not change anything
+ // bad field - should not increment but title field should be updated
doc["id"] = "0";
+ doc["title"] = "The Sherlock Holmes";
doc["$operations"] = R"({"increment": {"pointsx": -10}})"_json;
ASSERT_TRUE(coll->add(doc.dump(), UPDATE).ok());
- res = coll->search("*", {"title"}, "points:101", {}, {}, {0}, 3, 1, FREQUENCY, {false}).get();
+ res = coll->search("*", {"title"}, "", {}, {}, {0}, 3, 1, FREQUENCY, {false}).get();
ASSERT_EQ(1, res["hits"].size());
ASSERT_EQ(3, res["hits"][0]["document"].size());
+ ASSERT_EQ("0", res["hits"][0]["document"]["id"].get<std::string>());
+ ASSERT_EQ("The Sherlock Holmes", res["hits"][0]["document"]["title"].get<std::string>());
+ ASSERT_EQ(101, res["hits"][0]["document"]["points"].get<size_t>());
}
\ No newline at end of file