mirror of
https://github.com/typesense/typesense.git
synced 2025-05-19 21:22:25 +08:00
Store foo_sequence_id
in collection's meta-data.
This commit is contained in:
parent
0fb5e0d2a2
commit
e27cc6e34c
@ -11,7 +11,6 @@
|
||||
#include <tsl/htrie_map.h>
|
||||
#include "json.hpp"
|
||||
#include "text_embedder_manager.h"
|
||||
#include <regex>
|
||||
|
||||
namespace field_types {
|
||||
// first field value indexed will determine the type
|
||||
@ -285,17 +284,11 @@ struct field {
|
||||
const std::string & default_sorting_field,
|
||||
nlohmann::json& fields_json) {
|
||||
bool found_default_sorting_field = false;
|
||||
const std::regex sequence_id_pattern(".*_sequence_id$");
|
||||
|
||||
// Check for duplicates in field names
|
||||
std::map<std::string, std::vector<const field*>> unique_fields;
|
||||
|
||||
for(const field & field: fields) {
|
||||
if (std::regex_match(field.name, sequence_id_pattern)) {
|
||||
// Don't add foo_sequence_id field.
|
||||
continue;
|
||||
}
|
||||
|
||||
unique_fields[field.name].push_back(&field);
|
||||
|
||||
if(field.name == "id") {
|
||||
|
@ -89,10 +89,6 @@ Collection* CollectionManager::init_collection(const nlohmann::json & collection
|
||||
}
|
||||
|
||||
fields.push_back(f);
|
||||
|
||||
if (!f.reference.empty()) {
|
||||
fields.emplace_back(field(f.name + "_sequence_id", "string", false, f.optional, true));
|
||||
}
|
||||
}
|
||||
|
||||
std::string default_sorting_field = collection_meta[Collection::COLLECTION_DEFAULT_SORTING_FIELD_KEY].get<std::string>();
|
||||
|
@ -227,6 +227,17 @@ TEST_F(CollectionManagerTest, CollectionCreation) {
|
||||
"sort":false,
|
||||
"type":"string",
|
||||
"reference":"Products.product_id"
|
||||
},
|
||||
{
|
||||
"facet":false,
|
||||
"index":true,
|
||||
"infix":false,
|
||||
"locale":"",
|
||||
"name":"product_id_sequence_id",
|
||||
"nested":false,
|
||||
"optional":true,
|
||||
"sort":true,
|
||||
"type":"int64"
|
||||
}
|
||||
],
|
||||
"id":0,
|
||||
@ -464,9 +475,11 @@ TEST_F(CollectionManagerTest, RestoreRecordsOnRestart) {
|
||||
ASSERT_EQ(0, collection1->get_collection_id());
|
||||
ASSERT_EQ(18, collection1->get_next_seq_id());
|
||||
ASSERT_EQ(facet_fields_expected, collection1->get_facet_fields());
|
||||
ASSERT_EQ(2, collection1->get_sort_fields().size());
|
||||
// product_id_sequence_id is also included
|
||||
ASSERT_EQ(3, collection1->get_sort_fields().size());
|
||||
ASSERT_EQ("location", collection1->get_sort_fields()[0].name);
|
||||
ASSERT_EQ("points", collection1->get_sort_fields()[1].name);
|
||||
ASSERT_EQ("product_id_sequence_id", collection1->get_sort_fields()[1].name);
|
||||
ASSERT_EQ("points", collection1->get_sort_fields()[2].name);
|
||||
ASSERT_EQ(schema.size(), collection1->get_schema().size());
|
||||
ASSERT_EQ("points", collection1->get_default_sorting_field());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user