Add td_api::searchStringsByPrefix.
This commit is contained in:
parent
a554e9bb4e
commit
a1b08e2907
@ -5346,6 +5346,10 @@ topChatCategoryCalls = TopChatCategory;
|
|||||||
topChatCategoryForwardChats = TopChatCategory;
|
topChatCategoryForwardChats = TopChatCategory;
|
||||||
|
|
||||||
|
|
||||||
|
//@description Contains 0-based positions of matched objects @total_count Total number of matched objects @positions The positions of the matched objects
|
||||||
|
foundPositions total_count:int32 positions:vector<int32> = FoundPositions;
|
||||||
|
|
||||||
|
|
||||||
//@class TMeUrlType @description Describes the type of a URL linking to an internal Telegram entity
|
//@class TMeUrlType @description Describes the type of a URL linking to an internal Telegram entity
|
||||||
|
|
||||||
//@description A URL linking to a user @user_id Identifier of the user
|
//@description A URL linking to a user @user_id Identifier of the user
|
||||||
@ -8800,6 +8804,14 @@ assignGooglePlayTransaction package_name:string store_product_id:string purchase
|
|||||||
acceptTermsOfService terms_of_service_id:string = Ok;
|
acceptTermsOfService terms_of_service_id:string = Ok;
|
||||||
|
|
||||||
|
|
||||||
|
//@description Searches specified query by word prefixes in the provided strings. Returns 0-based positions of strings that matched. Can be called synchronously
|
||||||
|
//@strings The strings to search in for the query
|
||||||
|
//@query Query to search for
|
||||||
|
//@limit The maximum number of objects to return
|
||||||
|
//@return_none_for_empty_query Pass true to receive no results for an empty query
|
||||||
|
searchStringsByPrefix strings:vector<string> query:string limit:int32 return_none_for_empty_query:Bool = FoundPositions;
|
||||||
|
|
||||||
|
|
||||||
//@description Sends a custom request; for bots only @method The method name @parameters JSON-serialized method parameters
|
//@description Sends a custom request; for bots only @method The method name @parameters JSON-serialized method parameters
|
||||||
sendCustomRequest method:string parameters:string = CustomRequestResult;
|
sendCustomRequest method:string parameters:string = CustomRequestResult;
|
||||||
|
|
||||||
|
@ -2794,6 +2794,7 @@ bool Td::is_synchronous_request(const td_api::Function *function) {
|
|||||||
case td_api::parseTextEntities::ID:
|
case td_api::parseTextEntities::ID:
|
||||||
case td_api::parseMarkdown::ID:
|
case td_api::parseMarkdown::ID:
|
||||||
case td_api::getMarkdownText::ID:
|
case td_api::getMarkdownText::ID:
|
||||||
|
case td_api::searchStringsByPrefix::ID:
|
||||||
case td_api::getFileMimeType::ID:
|
case td_api::getFileMimeType::ID:
|
||||||
case td_api::getFileExtension::ID:
|
case td_api::getFileExtension::ID:
|
||||||
case td_api::cleanFileName::ID:
|
case td_api::cleanFileName::ID:
|
||||||
@ -3033,6 +3034,7 @@ td_api::object_ptr<td_api::Object> Td::static_request(td_api::object_ptr<td_api:
|
|||||||
case td_api::parseTextEntities::ID:
|
case td_api::parseTextEntities::ID:
|
||||||
case td_api::parseMarkdown::ID:
|
case td_api::parseMarkdown::ID:
|
||||||
case td_api::getMarkdownText::ID:
|
case td_api::getMarkdownText::ID:
|
||||||
|
case td_api::searchStringsByPrefix::ID:
|
||||||
case td_api::getFileMimeType::ID:
|
case td_api::getFileMimeType::ID:
|
||||||
case td_api::getFileExtension::ID:
|
case td_api::getFileExtension::ID:
|
||||||
case td_api::cleanFileName::ID:
|
case td_api::cleanFileName::ID:
|
||||||
@ -8829,6 +8831,10 @@ void Td::on_request(uint64 id, const td_api::getMarkdownText &request) {
|
|||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Td::on_request(uint64 id, const td_api::searchStringsByPrefix &request) {
|
||||||
|
UNREACHABLE();
|
||||||
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::getFileMimeType &request) {
|
void Td::on_request(uint64 id, const td_api::getFileMimeType &request) {
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
}
|
}
|
||||||
@ -8994,6 +9000,21 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::getMarkdownText
|
|||||||
std::numeric_limits<int32>::max());
|
std::numeric_limits<int32>::max());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
td_api::object_ptr<td_api::Object> Td::do_static_request(td_api::searchStringsByPrefix &request) {
|
||||||
|
if (!check_utf8(request.query_)) {
|
||||||
|
return make_error(400, "Strings must be encoded in UTF-8");
|
||||||
|
}
|
||||||
|
for (auto &str : request.strings_) {
|
||||||
|
if (!check_utf8(str)) {
|
||||||
|
return make_error(400, "Strings must be encoded in UTF-8");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int32 total_count = 0;
|
||||||
|
auto result = search_strings_by_prefix(std::move(request.strings_), std::move(request.query_), request.limit_,
|
||||||
|
!request.return_none_for_empty_query_, total_count);
|
||||||
|
return td_api::make_object<td_api::foundPositions>(total_count, std::move(result));
|
||||||
|
}
|
||||||
|
|
||||||
td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getFileMimeType &request) {
|
td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getFileMimeType &request) {
|
||||||
// don't check file name UTF-8 correctness
|
// don't check file name UTF-8 correctness
|
||||||
return make_tl_object<td_api::text>(MimeType::from_extension(PathView(request.file_name_).extension()));
|
return make_tl_object<td_api::text>(MimeType::from_extension(PathView(request.file_name_).extension()));
|
||||||
|
@ -1621,6 +1621,8 @@ class Td final : public Actor {
|
|||||||
|
|
||||||
void on_request(uint64 id, const td_api::getMarkdownText &request);
|
void on_request(uint64 id, const td_api::getMarkdownText &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, const td_api::searchStringsByPrefix &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::getFileMimeType &request);
|
void on_request(uint64 id, const td_api::getFileMimeType &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::getFileExtension &request);
|
void on_request(uint64 id, const td_api::getFileExtension &request);
|
||||||
@ -1681,6 +1683,7 @@ class Td final : public Actor {
|
|||||||
static td_api::object_ptr<td_api::Object> do_static_request(td_api::parseTextEntities &request);
|
static td_api::object_ptr<td_api::Object> do_static_request(td_api::parseTextEntities &request);
|
||||||
static td_api::object_ptr<td_api::Object> do_static_request(td_api::parseMarkdown &request);
|
static td_api::object_ptr<td_api::Object> do_static_request(td_api::parseMarkdown &request);
|
||||||
static td_api::object_ptr<td_api::Object> do_static_request(td_api::getMarkdownText &request);
|
static td_api::object_ptr<td_api::Object> do_static_request(td_api::getMarkdownText &request);
|
||||||
|
static td_api::object_ptr<td_api::Object> do_static_request(td_api::searchStringsByPrefix &request);
|
||||||
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getFileMimeType &request);
|
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getFileMimeType &request);
|
||||||
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getFileExtension &request);
|
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getFileExtension &request);
|
||||||
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::cleanFileName &request);
|
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::cleanFileName &request);
|
||||||
|
@ -3944,6 +3944,14 @@ class CliClient final : public Actor {
|
|||||||
td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeMarkdown>(2)));
|
td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeMarkdown>(2)));
|
||||||
} else if (op == "ptehs") {
|
} else if (op == "ptehs") {
|
||||||
execute(td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeHTML>()));
|
execute(td_api::make_object<td_api::parseTextEntities>(args, td_api::make_object<td_api::textParseModeHTML>()));
|
||||||
|
} else if (op == "ssbp") {
|
||||||
|
string strings;
|
||||||
|
string query;
|
||||||
|
string limit;
|
||||||
|
bool return_none_for_empty_query;
|
||||||
|
get_args(args, strings, query, limit, return_none_for_empty_query);
|
||||||
|
execute(td_api::make_object<td_api::searchStringsByPrefix>(autosplit_str(strings), query, as_limit(limit),
|
||||||
|
return_none_for_empty_query));
|
||||||
} else if (op == "gfmt") {
|
} else if (op == "gfmt") {
|
||||||
execute(td_api::make_object<td_api::getFileMimeType>(trim(args)));
|
execute(td_api::make_object<td_api::getFileMimeType>(trim(args)));
|
||||||
} else if (op == "gfe") {
|
} else if (op == "gfe") {
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "td/utils/algorithm.h"
|
#include "td/utils/algorithm.h"
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/Hints.h"
|
||||||
#include "td/utils/misc.h"
|
#include "td/utils/misc.h"
|
||||||
#include "td/utils/Slice.h"
|
#include "td/utils/Slice.h"
|
||||||
#include "td/utils/utf8.h"
|
#include "td/utils/utf8.h"
|
||||||
@ -351,4 +352,17 @@ Status validate_bot_language_code(const string &language_code) {
|
|||||||
return Status::Error(400, "Invalid language code specified");
|
return Status::Error(400, "Invalid language code specified");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<int32> search_strings_by_prefix(const vector<string> &strings, const string &query, int32 limit,
|
||||||
|
bool return_all_for_empty_query, int32 &total_count) {
|
||||||
|
Hints hints;
|
||||||
|
for (size_t i = 0; i < strings.size(); i++) {
|
||||||
|
const auto &str = strings[i];
|
||||||
|
hints.add(i, str.empty() ? Slice(" ") : Slice(str));
|
||||||
|
hints.set_rating(i, i);
|
||||||
|
}
|
||||||
|
auto result = hints.search(query, limit, return_all_for_empty_query);
|
||||||
|
total_count = result.first;
|
||||||
|
return transform(result.second, [](int64 key) { return narrow_cast<int32>(key); });
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -48,4 +48,8 @@ bool check_currency_amount(int64 amount);
|
|||||||
// checks whether language code is valid for bot settings
|
// checks whether language code is valid for bot settings
|
||||||
Status validate_bot_language_code(const string &language_code);
|
Status validate_bot_language_code(const string &language_code);
|
||||||
|
|
||||||
|
// returns 0-based indexes of strings matching the query by prefixes
|
||||||
|
vector<int32> search_strings_by_prefix(const vector<string> &strings, const string &query, int32 limit,
|
||||||
|
bool return_all_for_empty_query, int32 &total_count);
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
Loading…
x
Reference in New Issue
Block a user