From 26fbad2c66a875f21c680640d31d1e6f5928d5d4 Mon Sep 17 00:00:00 2001 From: Kishore Nallan Date: Tue, 12 Oct 2021 16:10:37 +0530 Subject: [PATCH] Return token separators and symbols to index in API. --- src/collection.cpp | 10 ++++++++++ test/collection_specific_test.cpp | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/collection.cpp b/src/collection.cpp index 1b09044a..5dace57b 100644 --- a/src/collection.cpp +++ b/src/collection.cpp @@ -148,6 +148,16 @@ nlohmann::json Collection::get_summary_json() const { json_response["name"] = name; json_response["num_documents"] = num_documents.load(); json_response["created_at"] = created_at.load(); + json_response["token_separators"] = nlohmann::json::array(); + json_response["symbols_to_index"] = nlohmann::json::array(); + + for(auto c: symbols_to_index) { + json_response["symbols_to_index"].push_back(std::string(1, c)); + } + + for(auto c: token_separators) { + json_response["token_separators"].push_back(std::string(1, c)); + } nlohmann::json fields_arr; diff --git a/test/collection_specific_test.cpp b/test/collection_specific_test.cpp index ccc01647..fb9cd523 100644 --- a/test/collection_specific_test.cpp +++ b/test/collection_specific_test.cpp @@ -1032,6 +1032,12 @@ TEST_F(CollectionSpecificTest, CustomSymbolsForIndexing) { "coll1", 1, fields, "points", 0, "", {"+"}, {} ).get(); + nlohmann::json coll_summary = coll1->get_summary_json(); + ASSERT_EQ(1, coll_summary["symbols_to_index"].size()); + ASSERT_EQ(0, coll_summary["token_separators"].size()); + + ASSERT_EQ("+", coll_summary["symbols_to_index"][0].get()); + nlohmann::json doc1; doc1["id"] = "0"; doc1["name"] = "Yes, C++ is great!"; @@ -1115,6 +1121,16 @@ TEST_F(CollectionSpecificTest, CustomSeparatorsHandleQueryVariations) { "coll1", 1, fields, "points", 0, "", {}, {"-", ".", "*", "&", "/"} ).get(); + nlohmann::json coll_summary = coll1->get_summary_json(); + ASSERT_EQ(0, coll_summary["symbols_to_index"].size()); + ASSERT_EQ(5, coll_summary["token_separators"].size()); + + ASSERT_EQ("-", coll_summary["token_separators"][0].get()); + ASSERT_EQ(".", coll_summary["token_separators"][1].get()); + ASSERT_EQ("*", coll_summary["token_separators"][2].get()); + ASSERT_EQ("&", coll_summary["token_separators"][3].get()); + ASSERT_EQ("/", coll_summary["token_separators"][4].get()); + nlohmann::json doc1; doc1["id"] = "0"; doc1["name"] = "1&1 Internet Limited";