mirror of
https://github.com/typesense/typesense.git
synced 2025-05-21 06:02:26 +08:00
Merge branch 'master' into distinct-grouping
This commit is contained in:
commit
2c22f9b2e1
@ -37,7 +37,7 @@ Here's a quick example showcasing how you can create a collection, index a docum
|
||||
Let's begin by starting the Typesense server via Docker:
|
||||
|
||||
```
|
||||
docker run -p 8108:8108 -v/tmp/data:/data typesense/typesense:0.12.0 --data-dir /data --api-key=Hu52dwsas2AdxdE
|
||||
docker run -p 8108:8108 -v/tmp/data:/data typesense/typesense:0.13.0 --data-dir /data --api-key=Hu52dwsas2AdxdE
|
||||
```
|
||||
|
||||
Install the Python client for Typesense (we have [clients](https://typesense.org/api/#api-clients) for other languages too):
|
||||
|
@ -267,6 +267,8 @@ public:
|
||||
|
||||
enum {MAX_ARRAY_MATCHES = 5};
|
||||
|
||||
const size_t PER_PAGE_MAX = 250;
|
||||
|
||||
// Using a $ prefix so that these meta keys stay above record entries in a lexicographically ordered KV store
|
||||
static constexpr const char* COLLECTION_META_PREFIX = "$CM";
|
||||
static constexpr const char* COLLECTION_NEXT_SEQ_PREFIX = "$CS";
|
||||
|
@ -12,6 +12,9 @@ private:
|
||||
|
||||
std::string api_key;
|
||||
|
||||
// @deprecated
|
||||
std::string search_only_api_key;
|
||||
|
||||
std::string api_address;
|
||||
uint32_t api_port;
|
||||
|
||||
@ -55,6 +58,11 @@ public:
|
||||
this->api_key = api_key;
|
||||
}
|
||||
|
||||
// @deprecated
|
||||
void set_search_only_api_key(const std::string & search_only_api_key) {
|
||||
this->search_only_api_key = search_only_api_key;
|
||||
}
|
||||
|
||||
void set_listen_address(const std::string & listen_address) {
|
||||
this->api_address = listen_address;
|
||||
}
|
||||
@ -97,6 +105,11 @@ public:
|
||||
return this->api_key;
|
||||
}
|
||||
|
||||
// @deprecated
|
||||
std::string get_search_only_api_key() const {
|
||||
return this->search_only_api_key;
|
||||
}
|
||||
|
||||
std::string get_api_address() const {
|
||||
return this->api_address;
|
||||
}
|
||||
@ -156,6 +169,9 @@ public:
|
||||
this->log_dir = get_env("TYPESENSE_LOG_DIR");
|
||||
this->api_key = get_env("TYPESENSE_API_KEY");
|
||||
|
||||
// @deprecated
|
||||
this->search_only_api_key = get_env("TYPESENSE_SEARCH_ONLY_API_KEY");
|
||||
|
||||
if(!get_env("TYPESENSE_LISTEN_ADDRESS").empty()) {
|
||||
this->api_address = get_env("TYPESENSE_LISTEN_ADDRESS");
|
||||
}
|
||||
@ -222,6 +238,11 @@ public:
|
||||
this->api_key = reader.Get("server", "api-key", "");
|
||||
}
|
||||
|
||||
// @deprecated
|
||||
if(reader.Exists("server", "search-only-api-key")) {
|
||||
this->search_only_api_key = reader.Get("server", "search-only-api-key", "");
|
||||
}
|
||||
|
||||
if(reader.Exists("server", "listen-address")) {
|
||||
this->api_address = reader.Get("server", "listen-address", "");
|
||||
}
|
||||
@ -280,6 +301,11 @@ public:
|
||||
this->api_key = options.get<std::string>("api-key");
|
||||
}
|
||||
|
||||
// @deprecated
|
||||
if(options.exist("search-only-api-key")) {
|
||||
this->search_only_api_key = options.get<std::string>("search-only-api-key");
|
||||
}
|
||||
|
||||
if(options.exist("listen-address")) {
|
||||
this->api_address = options.get<std::string>("listen-address");
|
||||
}
|
||||
|
@ -599,7 +599,13 @@ Option<nlohmann::json> Collection::search(const std::string & query, const std::
|
||||
return Option<nlohmann::json>(422, message);
|
||||
}
|
||||
|
||||
const size_t max_hits = (page * per_page);
|
||||
if(per_page > PER_PAGE_MAX) {
|
||||
std::string message = "Only upto " + std::to_string(PER_PAGE_MAX) + " hits can be fetched per page.";
|
||||
return Option<nlohmann::json>(422, message);
|
||||
}
|
||||
|
||||
// ensure that (page * per_page) never exceeds number of documents in collection
|
||||
const size_t max_hits = std::min((page * per_page), get_num_documents());
|
||||
|
||||
std::vector<std::vector<art_leaf*>> searched_queries; // search queries used for generating the results
|
||||
std::vector<KV> raw_result_kvs;
|
||||
|
@ -952,7 +952,7 @@ bool del_key(http_req &req, http_res &res) {
|
||||
}
|
||||
|
||||
nlohmann::json res_json;
|
||||
res_json["id"] = req.params["id"];
|
||||
res_json["id"] = del_op.get().id;
|
||||
|
||||
res.set_200(res_json.dump());
|
||||
return true;
|
||||
|
@ -101,6 +101,7 @@ void init_cmdline_options(cmdline::parser & options, int argc, char **argv) {
|
||||
|
||||
options.add<std::string>("data-dir", 'd', "Directory where data will be stored.", true);
|
||||
options.add<std::string>("api-key", 'a', "API key that allows all operations.", true);
|
||||
options.add<std::string>("search-only-api-key", 's', "[DEPRECATED: use API key management end-point] API key that allows only searches.", false);
|
||||
|
||||
options.add<std::string>("api-address", '\0', "Address to which Typesense API service binds.", false, "0.0.0.0");
|
||||
options.add<uint32_t>("api-port", '\0', "Port on which Typesense API service listens.", false, 8108);
|
||||
@ -290,6 +291,12 @@ int run_server(const Config & config, const std::string & version, void (*master
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!config.get_search_only_api_key().empty()) {
|
||||
LOG(WARNING) << "!!!! WARNING !!!!";
|
||||
LOG(WARNING) << "The --search-only-api-key has been deprecated. "
|
||||
"The API key generation end-point should be used for generating keys with specific ACL.";
|
||||
}
|
||||
|
||||
std::string data_dir = config.get_data_dir();
|
||||
std::string db_dir = config.get_data_dir() + "/db";
|
||||
std::string state_dir = config.get_data_dir() + "/state";
|
||||
|
@ -2276,13 +2276,26 @@ TEST_F(CollectionTest, ReturnsResultsBasedOnPerPageParam) {
|
||||
ASSERT_EQ(25, results["found"].get<int>());
|
||||
|
||||
// should match collection size
|
||||
|
||||
results = collection->search("*", query_fields, "", facets, sort_fields, 0, 100000, 1,
|
||||
results = collection->search("*", query_fields, "", facets, sort_fields, 0, 100, 1,
|
||||
FREQUENCY, false, 1000, empty, empty, 10).get();
|
||||
|
||||
ASSERT_EQ(25, results["hits"].size());
|
||||
ASSERT_EQ(25, results["found"].get<int>());
|
||||
|
||||
// cannot fetch more than in-built limit of 250
|
||||
auto res_op = collection->search("*", query_fields, "", facets, sort_fields, 0, 251, 1,
|
||||
FREQUENCY, false, 1000, empty, empty, 10);
|
||||
ASSERT_FALSE(res_op.ok());
|
||||
ASSERT_EQ(422, res_op.code());
|
||||
ASSERT_STREQ("Only upto 250 hits can be fetched per page.", res_op.error().c_str());
|
||||
|
||||
// when page number is not valid
|
||||
res_op = collection->search("*", query_fields, "", facets, sort_fields, 0, 10, 0,
|
||||
FREQUENCY, false, 1000, empty, empty, 10);
|
||||
ASSERT_FALSE(res_op.ok());
|
||||
ASSERT_EQ(422, res_op.code());
|
||||
ASSERT_STREQ("Page must be an integer of value greater than 0.", res_op.error().c_str());
|
||||
|
||||
// do pagination
|
||||
|
||||
results = collection->search("*", query_fields, "", facets, sort_fields, 0, 10, 1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user