mirror of
https://github.com/typesense/typesense.git
synced 2025-05-18 20:52:50 +08:00
Make type definitions less verbose.
Use string[] instead of STRING_ARRAY and so on.
This commit is contained in:
parent
6ab58d1839
commit
901626652a
3
TODO.md
3
TODO.md
@ -62,6 +62,9 @@
|
||||
- Validate before string to int conversion in the http api layer
|
||||
- When field of "id" but not string, what happens?
|
||||
- Typo in prefix search
|
||||
- node score should be int32, no longer uint16 like in document struct
|
||||
- json::parse must be wrapped in try catch
|
||||
- test for num_documents
|
||||
- test for string filter comparison: title < "foo"
|
||||
- test for token ranking on float field
|
||||
- test for float int field deletion during doc deletion
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
|
||||
bool auth_key_matches(std::string auth_key_sent);
|
||||
|
||||
Collection* create_collection(std::string name, const std::vector<field> & search_fields,
|
||||
Option<Collection*> create_collection(std::string name, const std::vector<field> & search_fields,
|
||||
const std::vector<field> & facet_fields,
|
||||
const std::vector<field> & sort_fields,
|
||||
const std::string & token_ranking_field = "");
|
||||
|
@ -6,14 +6,14 @@
|
||||
#include "string_utils.h"
|
||||
|
||||
namespace field_types {
|
||||
static const std::string STRING = "STRING";
|
||||
static const std::string INT32 = "INT32";
|
||||
static const std::string INT64 = "INT64";
|
||||
static const std::string STRING = "string";
|
||||
static const std::string INT32 = "int32";
|
||||
static const std::string INT64 = "int64";
|
||||
static const std::string FLOAT = "FLOAT";
|
||||
static const std::string FLOAT_ARRAY = "FLOAT_ARRAY";
|
||||
static const std::string STRING_ARRAY = "STRING_ARRAY";
|
||||
static const std::string INT32_ARRAY = "INT32_ARRAY";
|
||||
static const std::string INT64_ARRAY = "INT64_ARRAY";
|
||||
static const std::string FLOAT_ARRAY = "float[]";
|
||||
static const std::string STRING_ARRAY = "string[]";
|
||||
static const std::string INT32_ARRAY = "int32[]";
|
||||
static const std::string INT64_ARRAY = "int64[]";
|
||||
}
|
||||
|
||||
namespace fields {
|
||||
|
@ -110,8 +110,8 @@ void post_create_collection(http_req & req, http_res & res) {
|
||||
"[{\"name\": \"<field_name>\", \"type\": \"<field_type>\"}]");
|
||||
}
|
||||
|
||||
if(sort_field_json["type"] != "INT32" && sort_field_json["type"] != "INT64") {
|
||||
return res.send_400("Sort field `" + sort_field_json["name"].get<std::string>() + "` must be a number.");
|
||||
if(sort_field_json["type"] != field_types::INT32 && sort_field_json["type"] != field_types::INT64) {
|
||||
return res.send_400("Sort field `" + sort_field_json["name"].get<std::string>() + "` must be an integer.");
|
||||
}
|
||||
|
||||
sort_fields.push_back(field(sort_field_json["name"], sort_field_json["type"]));
|
||||
@ -122,7 +122,7 @@ void post_create_collection(http_req & req, http_res & res) {
|
||||
|
||||
if(req_json.count(PREFIX_RANKING_FIELD) != 0) {
|
||||
if(!req_json[PREFIX_RANKING_FIELD].is_string()) {
|
||||
return res.send_400(std::string("Wrong format for `") + PREFIX_RANKING_FIELD + "`. It should be the name of an unsigned INT32 field.");
|
||||
return res.send_400(std::string("`") + PREFIX_RANKING_FIELD + "` should be the name of an unsigned integer field.");
|
||||
}
|
||||
|
||||
token_ranking_field = req_json[PREFIX_RANKING_FIELD].get<std::string>();
|
||||
|
@ -66,7 +66,12 @@ void Collection::increment_next_seq_id_field() {
|
||||
}
|
||||
|
||||
Option<std::string> Collection::add(const std::string & json_str) {
|
||||
nlohmann::json document = nlohmann::json::parse(json_str);
|
||||
nlohmann::json document;
|
||||
try {
|
||||
document = nlohmann::json::parse(json_str);
|
||||
} catch(...) {
|
||||
return Option<std::string>(400, "Bad JSON.");
|
||||
}
|
||||
|
||||
uint32_t seq_id = get_next_seq_id();
|
||||
std::string seq_id_str = std::to_string(seq_id);
|
||||
@ -97,12 +102,12 @@ Option<uint32_t> Collection::index_in_memory(const nlohmann::json &document, uin
|
||||
"but is not found in the document.");
|
||||
}
|
||||
|
||||
if(!token_ranking_field.empty() && !document[token_ranking_field].is_number_unsigned()) {
|
||||
return Option<>(400, "Token ranking field `" + token_ranking_field + "` must be an unsigned INT32.");
|
||||
if(!token_ranking_field.empty() && !document[token_ranking_field].is_number_integer()) {
|
||||
return Option<>(400, "Token ranking field `" + token_ranking_field + "` must be an int32.");
|
||||
}
|
||||
|
||||
if(!token_ranking_field.empty() && document[token_ranking_field].get<int64_t>() > INT32_MAX) {
|
||||
return Option<>(400, "Token ranking field `" + token_ranking_field + "` exceeds maximum value of INT32.");
|
||||
return Option<>(400, "Token ranking field `" + token_ranking_field + "` exceeds maximum value of int32.");
|
||||
}
|
||||
|
||||
if(!token_ranking_field.empty() && document[token_ranking_field].get<int64_t>() < 0) {
|
||||
@ -126,75 +131,75 @@ Option<uint32_t> Collection::index_in_memory(const nlohmann::json &document, uin
|
||||
|
||||
if(field_pair.second.type == field_types::STRING) {
|
||||
if(!document[field_name].is_string()) {
|
||||
return Option<>(400, "Search field `" + field_name + "` must be a STRING.");
|
||||
return Option<>(400, "Search field `" + field_name + "` must be a string.");
|
||||
}
|
||||
const std::string & text = document[field_name];
|
||||
index_string_field(text, points, t, seq_id, false);
|
||||
} else if(field_pair.second.type == field_types::INT32) {
|
||||
if(!document[field_name].is_number_integer()) {
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an INT32.");
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an int32.");
|
||||
}
|
||||
|
||||
if(document[field_name].get<int64_t>() > INT32_MAX) {
|
||||
return Option<>(400, "Search field `" + field_name + "` exceeds maximum value of INT32.");
|
||||
return Option<>(400, "Search field `" + field_name + "` exceeds maximum value of int32.");
|
||||
}
|
||||
|
||||
uint32_t value = document[field_name];
|
||||
index_int32_field(value, points, t, seq_id);
|
||||
} else if(field_pair.second.type == field_types::INT64) {
|
||||
if(!document[field_name].is_number_integer()) {
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an INT64.");
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an int64.");
|
||||
}
|
||||
|
||||
uint64_t value = document[field_name];
|
||||
index_int64_field(value, points, t, seq_id);
|
||||
} else if(field_pair.second.type == field_types::FLOAT) {
|
||||
if(!document[field_name].is_number_float()) {
|
||||
return Option<>(400, "Search field `" + field_name + "` must be a FLOAT.");
|
||||
return Option<>(400, "Search field `" + field_name + "` must be a float.");
|
||||
}
|
||||
|
||||
float value = document[field_name];
|
||||
index_float_field(value, points, t, seq_id);
|
||||
} else if(field_pair.second.type == field_types::STRING_ARRAY) {
|
||||
if(!document[field_name].is_array()) {
|
||||
return Option<>(400, "Search field `" + field_name + "` must be a STRING_ARRAY.");
|
||||
return Option<>(400, "Search field `" + field_name + "` must be a string array.");
|
||||
}
|
||||
|
||||
if(document[field_name].size() > 0 && !document[field_name][0].is_string()) {
|
||||
return Option<>(400, "Search field `" + field_name + "` must be a STRING_ARRAY.");
|
||||
return Option<>(400, "Search field `" + field_name + "` must be a string array.");
|
||||
}
|
||||
|
||||
std::vector<std::string> strings = document[field_name];
|
||||
index_string_array_field(strings, points, t, seq_id, false);
|
||||
} else if(field_pair.second.type == field_types::INT32_ARRAY) {
|
||||
if(!document[field_name].is_array()) {
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an INT32_ARRAY.");
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an int32 array.");
|
||||
}
|
||||
|
||||
if(document[field_name].size() > 0 && !document[field_name][0].is_number_integer()) {
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an INT32_ARRAY.");
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an int32 array.");
|
||||
}
|
||||
|
||||
std::vector<int32_t> values = document[field_name];
|
||||
index_int32_array_field(values, points, t, seq_id);
|
||||
} else if(field_pair.second.type == field_types::INT64_ARRAY) {
|
||||
if(!document[field_name].is_array()) {
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an INT64_ARRAY.");
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an int64 array.");
|
||||
}
|
||||
|
||||
if(document[field_name].size() > 0 && !document[field_name][0].is_number_integer()) {
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an INT64_ARRAY.");
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an int64 array.");
|
||||
}
|
||||
|
||||
std::vector<int64_t> values = document[field_name];
|
||||
index_int64_array_field(values, points, t, seq_id);
|
||||
} else if(field_pair.second.type == field_types::FLOAT_ARRAY) {
|
||||
if(!document[field_name].is_array()) {
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an FLOAT_ARRAY.");
|
||||
return Option<>(400, "Search field `" + field_name + "` must be a float array.");
|
||||
}
|
||||
|
||||
if(document[field_name].size() > 0 && !document[field_name][0].is_number_float()) {
|
||||
return Option<>(400, "Search field `" + field_name + "` must be an FLOAT_ARRAY.");
|
||||
return Option<>(400, "Search field `" + field_name + "` must be a float array.");
|
||||
}
|
||||
|
||||
std::vector<float> values = document[field_name];
|
||||
@ -213,17 +218,17 @@ Option<uint32_t> Collection::index_in_memory(const nlohmann::json &document, uin
|
||||
facet_value & fvalue = facet_index.at(field_name);
|
||||
if(field_pair.second.type == field_types::STRING) {
|
||||
if(!document[field_name].is_string()) {
|
||||
return Option<>(400, "Facet field `" + field_name + "` must be a STRING.");
|
||||
return Option<>(400, "Facet field `" + field_name + "` must be a string.");
|
||||
}
|
||||
const std::string & value = document[field_name];
|
||||
fvalue.index_values(seq_id, { value });
|
||||
} else if(field_pair.second.type == field_types::STRING_ARRAY) {
|
||||
if(!document[field_name].is_array()) {
|
||||
return Option<>(400, "Facet field `" + field_name + "` must be a STRING_ARRAY.");
|
||||
return Option<>(400, "Facet field `" + field_name + "` must be a string array.");
|
||||
}
|
||||
|
||||
if(document[field_name].size() > 0 && !document[field_name][0].is_string()) {
|
||||
return Option<>(400, "Facet field `" + field_name + "` must be a STRING_ARRAY.");
|
||||
return Option<>(400, "Facet field `" + field_name + "` must be a string array.");
|
||||
}
|
||||
|
||||
const std::vector<std::string> & values = document[field_name];
|
||||
|
@ -109,12 +109,12 @@ bool CollectionManager::auth_key_matches(std::string auth_key_sent) {
|
||||
return (auth_key == auth_key_sent);
|
||||
}
|
||||
|
||||
Collection* CollectionManager::create_collection(std::string name, const std::vector<field> & search_fields,
|
||||
Option<Collection*> CollectionManager::create_collection(std::string name, const std::vector<field> & search_fields,
|
||||
const std::vector<field> & facet_fields,
|
||||
const std::vector<field> & sort_fields,
|
||||
const std::string & token_ranking_field) {
|
||||
if(store->contains(Collection::get_meta_key(name))) {
|
||||
return nullptr;
|
||||
return Option<Collection*>(409, std::string("A collection with name `") + name + "` already exists.");
|
||||
}
|
||||
|
||||
nlohmann::json collection_meta;
|
||||
|
@ -17,14 +17,14 @@ int main(int argc, char* argv[]) {
|
||||
system("rm -rf /tmp/typesense-data && mkdir -p /tmp/typesense-data");
|
||||
|
||||
std::vector<field> fields_to_index = {field("title", field_types::STRING)};
|
||||
std::vector<field> sort_fields = { field("points", "INT32")};
|
||||
std::vector<field> sort_fields = { field("points", field_types::INT32)};
|
||||
Store *store = new Store("/tmp/typesense-data");
|
||||
CollectionManager & collectionManager = CollectionManager::get_instance();
|
||||
collectionManager.init(store, "abcd");
|
||||
|
||||
Collection *collection = collectionManager.get_collection("hnstories_direct");
|
||||
if(collection == nullptr) {
|
||||
collection = collectionManager.create_collection("hnstories_direct", fields_to_index, {}, sort_fields, "points");
|
||||
collection = collectionManager.create_collection("hnstories_direct", fields_to_index, {}, sort_fields, "points").get();
|
||||
}
|
||||
|
||||
std::ifstream infile("/Users/kishore/Downloads/hnstories_tiny.jsonl");
|
||||
|
@ -39,12 +39,12 @@ int main(int argc, char* argv[]) {
|
||||
};
|
||||
|
||||
std::vector<field> sort_fields = {
|
||||
field("stars", "INT32")
|
||||
field("stars", field_types::INT32)
|
||||
};
|
||||
|
||||
Collection *collection = collectionManager.get_collection("github_top1k");
|
||||
if(collection == nullptr) {
|
||||
collection = collectionManager.create_collection("github_top1k", fields_to_index, facet_fields_index, sort_fields);
|
||||
collection = collectionManager.create_collection("github_top1k", fields_to_index, facet_fields_index, sort_fields).get();
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
|
@ -27,10 +27,10 @@ protected:
|
||||
search_fields = {field("title", field_types::STRING), field("starring", field_types::STRING)};
|
||||
facet_fields = {field("starring", field_types::STRING)};
|
||||
sort_fields = { sort_by("points", "DESC") };
|
||||
sort_fields_index = { field("points", "INT32") };
|
||||
sort_fields_index = { field("points", field_types::INT32) };
|
||||
|
||||
collection1 = collectionManager.create_collection("collection1", search_fields, facet_fields,
|
||||
sort_fields_index, "points");
|
||||
sort_fields_index, "points").get();
|
||||
}
|
||||
|
||||
virtual void SetUp() {
|
||||
@ -79,10 +79,10 @@ TEST_F(CollectionManagerTest, CollectionCreation) {
|
||||
|
||||
ASSERT_EQ(3, num_keys);
|
||||
ASSERT_EQ("1", next_seq_id); // we already call `collection1->get_next_seq_id` above, which is side-effecting
|
||||
ASSERT_EQ("{\"facet_fields\":[{\"name\":\"starring\",\"type\":\"STRING\"}],\"id\":0,\"name\":\"collection1\","
|
||||
"\"search_fields\":[{\"name\":\"title\",\"type\":\"STRING\"},"
|
||||
"{\"name\":\"starring\",\"type\":\"STRING\"}],"
|
||||
"\"sort_fields\":[{\"name\":\"points\",\"type\":\"INT32\"}],"
|
||||
ASSERT_EQ("{\"facet_fields\":[{\"name\":\"starring\",\"type\":\"string\"}],\"id\":0,\"name\":\"collection1\","
|
||||
"\"search_fields\":[{\"name\":\"title\",\"type\":\"string\"},"
|
||||
"{\"name\":\"starring\",\"type\":\"string\"}],"
|
||||
"\"sort_fields\":[{\"name\":\"points\",\"type\":\"int32\"}],"
|
||||
"\"token_ranking_field\":\"points\"}", collection_meta_json);
|
||||
ASSERT_EQ("1", next_collection_id);
|
||||
}
|
||||
|
@ -32,12 +32,12 @@ protected:
|
||||
query_fields = {"title"};
|
||||
facet_fields = { };
|
||||
sort_fields = { sort_by("points", "DESC") };
|
||||
sort_fields_index = { field("points", "INT32") };
|
||||
sort_fields_index = { field("points", field_types::INT32) };
|
||||
|
||||
collection = collectionManager.get_collection("collection");
|
||||
if(collection == nullptr) {
|
||||
collection = collectionManager.create_collection("collection", search_fields, facet_fields,
|
||||
sort_fields_index, "points");
|
||||
sort_fields_index, "points").get();
|
||||
}
|
||||
|
||||
std::string json_line;
|
||||
@ -419,7 +419,7 @@ TEST_F(CollectionTest, MultipleFields) {
|
||||
|
||||
coll_mul_fields = collectionManager.get_collection("coll_mul_fields");
|
||||
if(coll_mul_fields == nullptr) {
|
||||
coll_mul_fields = collectionManager.create_collection("coll_mul_fields", fields, facet_fields, sort_fields_index);
|
||||
coll_mul_fields = collectionManager.create_collection("coll_mul_fields", fields, facet_fields, sort_fields_index).get();
|
||||
}
|
||||
|
||||
std::string json_line;
|
||||
@ -498,11 +498,11 @@ TEST_F(CollectionTest, FilterOnNumericFields) {
|
||||
field("years", field_types::INT32_ARRAY),
|
||||
field("timestamps", field_types::INT64_ARRAY)};
|
||||
std::vector<sort_by> sort_fields = { sort_by("age", "DESC") };
|
||||
std::vector<field> sort_fields_index = { field("age", "INT32") };
|
||||
std::vector<field> sort_fields_index = { field("age", field_types::INT32) };
|
||||
|
||||
coll_array_fields = collectionManager.get_collection("coll_array_fields");
|
||||
if(coll_array_fields == nullptr) {
|
||||
coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, facet_fields, sort_fields_index);
|
||||
coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, facet_fields, sort_fields_index).get();
|
||||
}
|
||||
|
||||
std::string json_line;
|
||||
@ -639,7 +639,7 @@ TEST_F(CollectionTest, FilterOnFloatFields) {
|
||||
|
||||
coll_array_fields = collectionManager.get_collection("coll_array_fields");
|
||||
if(coll_array_fields == nullptr) {
|
||||
coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, facet_fields, sort_fields_index);
|
||||
coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, facet_fields, sort_fields_index).get();
|
||||
}
|
||||
|
||||
std::string json_line;
|
||||
@ -773,7 +773,7 @@ TEST_F(CollectionTest, SortOnFloatFields) {
|
||||
|
||||
coll_float_fields = collectionManager.get_collection("coll_float_fields");
|
||||
if(coll_float_fields == nullptr) {
|
||||
coll_float_fields = collectionManager.create_collection("coll_float_fields", fields, facet_fields, sort_fields_index);
|
||||
coll_float_fields = collectionManager.create_collection("coll_float_fields", fields, facet_fields, sort_fields_index).get();
|
||||
}
|
||||
|
||||
std::string json_line;
|
||||
@ -837,12 +837,12 @@ TEST_F(CollectionTest, FilterOnTextFields) {
|
||||
field("years", field_types::INT32_ARRAY),
|
||||
field("tags", field_types::STRING_ARRAY)};
|
||||
|
||||
std::vector<field> sort_fields_index = { field("age", "INT32") };
|
||||
std::vector<field> sort_fields_index = { field("age", field_types::INT32) };
|
||||
std::vector<sort_by> sort_fields = { sort_by("age", "DESC") };
|
||||
|
||||
coll_array_fields = collectionManager.get_collection("coll_array_fields");
|
||||
if(coll_array_fields == nullptr) {
|
||||
coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, facet_fields, sort_fields_index);
|
||||
coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, facet_fields, sort_fields_index).get();
|
||||
}
|
||||
|
||||
std::string json_line;
|
||||
@ -909,12 +909,12 @@ TEST_F(CollectionTest, HandleBadlyFormedFilterQuery) {
|
||||
field("timestamps", field_types::INT64_ARRAY),
|
||||
field("tags", field_types::STRING_ARRAY)};
|
||||
|
||||
std::vector<field> sort_fields_index = { field("age", "INT32") };
|
||||
std::vector<field> sort_fields_index = { field("age", field_types::INT32) };
|
||||
std::vector<sort_by> sort_fields = { sort_by("age", "DESC") };
|
||||
|
||||
coll_array_fields = collectionManager.get_collection("coll_array_fields");
|
||||
if(coll_array_fields == nullptr) {
|
||||
coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, facet_fields, sort_fields_index);
|
||||
coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, facet_fields, sort_fields_index).get();
|
||||
}
|
||||
|
||||
std::string json_line;
|
||||
@ -970,7 +970,7 @@ TEST_F(CollectionTest, FacetCounts) {
|
||||
|
||||
coll_array_fields = collectionManager.get_collection("coll_array_fields");
|
||||
if(coll_array_fields == nullptr) {
|
||||
coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, facet_fields, sort_fields_index);
|
||||
coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, facet_fields, sort_fields_index).get();
|
||||
}
|
||||
|
||||
std::string json_line;
|
||||
@ -1046,7 +1046,7 @@ TEST_F(CollectionTest, SortingOrder) {
|
||||
|
||||
coll_mul_fields = collectionManager.get_collection("coll_mul_fields");
|
||||
if(coll_mul_fields == nullptr) {
|
||||
coll_mul_fields = collectionManager.create_collection("coll_mul_fields", fields, facet_fields, sort_fields_index);
|
||||
coll_mul_fields = collectionManager.create_collection("coll_mul_fields", fields, facet_fields, sort_fields_index).get();
|
||||
}
|
||||
|
||||
std::string json_line;
|
||||
@ -1134,7 +1134,7 @@ TEST_F(CollectionTest, SearchingWithMissingFields) {
|
||||
|
||||
coll_array_fields = collectionManager.get_collection("coll_array_fields");
|
||||
if(coll_array_fields == nullptr) {
|
||||
coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, facet_fields, sort_fields_index);
|
||||
coll_array_fields = collectionManager.create_collection("coll_array_fields", fields, facet_fields, sort_fields_index).get();
|
||||
}
|
||||
|
||||
std::string json_line;
|
||||
@ -1183,13 +1183,13 @@ TEST_F(CollectionTest, IndexingWithBadData) {
|
||||
std::vector<field> fields = {field("name", field_types::STRING)};
|
||||
facet_fields = {field("tags", field_types::STRING_ARRAY)};
|
||||
|
||||
std::vector<field> sort_fields_index = { field("age", "INT32"), field("average", "INT32") };
|
||||
std::vector<field> sort_fields_index = { field("age", field_types::INT32), field("average", field_types::INT32) };
|
||||
std::vector<sort_by> sort_fields = { sort_by("age", "DESC"), sort_by("average", "DESC") };
|
||||
|
||||
sample_collection = collectionManager.get_collection("sample_collection");
|
||||
if(sample_collection == nullptr) {
|
||||
sample_collection = collectionManager.create_collection("sample_collection", fields, facet_fields,
|
||||
sort_fields_index, "age");
|
||||
sort_fields_index, "age").get();
|
||||
}
|
||||
|
||||
const Option<std::string> & search_fields_missing_op1 = sample_collection->add("{\"namezz\": \"foo\", \"age\": 29}");
|
||||
@ -1218,8 +1218,7 @@ TEST_F(CollectionTest, IndexingWithBadData) {
|
||||
doc_str = "{\"name\": \"foo\", \"age\": 34, \"tags\": 22}";
|
||||
const Option<std::string> & bad_facet_field_op = sample_collection->add(doc_str);
|
||||
ASSERT_FALSE(bad_facet_field_op.ok());
|
||||
ASSERT_STREQ("Facet field `tags` must be a STRING_ARRAY.",
|
||||
bad_facet_field_op.error().c_str());
|
||||
ASSERT_STREQ("Facet field `tags` must be a string array.", bad_facet_field_op.error().c_str());
|
||||
|
||||
doc_str = "{\"name\": \"foo\", \"age\": 34, \"tags\": [], \"average\": 34}";
|
||||
const Option<std::string> & empty_facet_field_op = sample_collection->add(doc_str);
|
||||
@ -1228,12 +1227,12 @@ TEST_F(CollectionTest, IndexingWithBadData) {
|
||||
doc_str = "{\"name\": \"foo\", \"age\": \"34\", \"tags\": [], \"average\": 34 }";
|
||||
const Option<std::string> & bad_token_ranking_field_op1 = sample_collection->add(doc_str);
|
||||
ASSERT_FALSE(bad_token_ranking_field_op1.ok());
|
||||
ASSERT_STREQ("Token ranking field `age` must be an unsigned INT32.", bad_token_ranking_field_op1.error().c_str());
|
||||
ASSERT_STREQ("Token ranking field `age` must be an int32.", bad_token_ranking_field_op1.error().c_str());
|
||||
|
||||
doc_str = "{\"name\": \"foo\", \"age\": 343234324234233234, \"tags\": [], \"average\": 34 }";
|
||||
const Option<std::string> & bad_token_ranking_field_op2 = sample_collection->add(doc_str);
|
||||
ASSERT_FALSE(bad_token_ranking_field_op2.ok());
|
||||
ASSERT_STREQ("Token ranking field `age` exceeds maximum value of INT32.", bad_token_ranking_field_op2.error().c_str());
|
||||
ASSERT_STREQ("Token ranking field `age` exceeds maximum value of int32.", bad_token_ranking_field_op2.error().c_str());
|
||||
|
||||
doc_str = "{\"name\": \"foo\", \"tags\": [], \"average\": 34 }";
|
||||
const Option<std::string> & bad_token_ranking_field_op3 = sample_collection->add(doc_str);
|
||||
@ -1246,10 +1245,10 @@ TEST_F(CollectionTest, IndexingWithBadData) {
|
||||
ASSERT_FALSE(bad_rank_field_op.ok());
|
||||
ASSERT_STREQ("Sort field `average` must be a number.", bad_rank_field_op.error().c_str());
|
||||
|
||||
doc_str = "{\"name\": \"foo\", \"age\": -10, \"tags\": [], \"average\": 34 }";
|
||||
doc_str = "{\"name\": \"foo\", \"age\": asdadasd, \"tags\": [], \"average\": 34 }";
|
||||
const Option<std::string> & bad_token_ranking_field_op4 = sample_collection->add(doc_str);
|
||||
ASSERT_FALSE(bad_token_ranking_field_op4.ok());
|
||||
ASSERT_STREQ("Token ranking field `age` must be an unsigned INT32.", bad_token_ranking_field_op4.error().c_str());
|
||||
ASSERT_STREQ("Bad JSON.", bad_token_ranking_field_op4.error().c_str());
|
||||
|
||||
collectionManager.drop_collection("sample_collection");
|
||||
}
|
||||
@ -1260,12 +1259,12 @@ TEST_F(CollectionTest, EmptyIndexShouldNotCrash) {
|
||||
std::vector<field> fields = {field("name", field_types::STRING)};
|
||||
facet_fields = {field("tags", field_types::STRING_ARRAY)};
|
||||
|
||||
std::vector<field> sort_fields_index = { field("age", "INT32"), field("average", "INT32") };
|
||||
std::vector<field> sort_fields_index = { field("age", field_types::INT32), field("average", field_types::INT32) };
|
||||
std::vector<sort_by> sort_fields = { sort_by("age", "DESC"), sort_by("average", "DESC") };
|
||||
|
||||
empty_coll = collectionManager.get_collection("empty_coll");
|
||||
if(empty_coll == nullptr) {
|
||||
empty_coll = collectionManager.create_collection("empty_coll", fields, facet_fields, sort_fields_index, "age");
|
||||
empty_coll = collectionManager.create_collection("empty_coll", fields, facet_fields, sort_fields_index, "age").get();
|
||||
}
|
||||
|
||||
nlohmann::json results = empty_coll->search("a", {"name"}, "", {}, sort_fields, 0, 10, 1, FREQUENCY, false).get();
|
||||
@ -1279,12 +1278,12 @@ TEST_F(CollectionTest, IdFieldShouldBeAString) {
|
||||
std::vector<field> fields = {field("name", field_types::STRING)};
|
||||
facet_fields = {field("tags", field_types::STRING_ARRAY)};
|
||||
|
||||
std::vector<field> sort_fields_index = { field("age", "INT32"), field("average", "INT32") };
|
||||
std::vector<field> sort_fields_index = { field("age", field_types::INT32), field("average", field_types::INT32) };
|
||||
std::vector<sort_by> sort_fields = { sort_by("age", "DESC"), sort_by("average", "DESC") };
|
||||
|
||||
coll1 = collectionManager.get_collection("coll1");
|
||||
if(coll1 == nullptr) {
|
||||
coll1 = collectionManager.create_collection("coll1", fields, facet_fields, sort_fields_index, "age");
|
||||
coll1 = collectionManager.create_collection("coll1", fields, facet_fields, sort_fields_index, "age").get();
|
||||
}
|
||||
|
||||
nlohmann::json doc;
|
||||
@ -1310,13 +1309,13 @@ TEST_F(CollectionTest, DeletionOfADocument) {
|
||||
std::vector<std::string> query_fields = {"title"};
|
||||
std::vector<field> facet_fields = { };
|
||||
std::vector<sort_by> sort_fields = { sort_by("points", "DESC") };
|
||||
std::vector<field> sort_fields_index = { field("points", "INT32") };
|
||||
std::vector<field> sort_fields_index = { field("points", field_types::INT32) };
|
||||
|
||||
Collection *collection_for_del;
|
||||
collection_for_del = collectionManager.get_collection("collection_for_del");
|
||||
if(collection_for_del == nullptr) {
|
||||
collection_for_del = collectionManager.create_collection("collection_for_del", search_fields, facet_fields,
|
||||
sort_fields_index, "points");
|
||||
sort_fields_index, "points").get();
|
||||
}
|
||||
|
||||
std::string json_line;
|
||||
|
Loading…
x
Reference in New Issue
Block a user