Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(search): improve the response format of FT.SEARCH|SEARCHSQL #2351

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions src/commands/cmd_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "commands/command_parser.h"
#include "search/index_info.h"
#include "search/ir.h"
#include "search/plan_executor.h"
#include "search/redis_query_transformer.h"
#include "search/search_encoding.h"
#include "search/sql_transformer.h"
Expand Down Expand Up @@ -138,6 +139,19 @@ class CommandFTCreate : public Commander {
std::unique_ptr<kqir::IndexInfo> index_info_;
};

static void DumpQueryResult(const std::vector<kqir::ExecutorContext::RowType> &rows, std::string *output) {
output->append(MultiLen(rows.size() * 2 + 1));
output->append(Integer(rows.size()));
for (const auto &[key, fields, _] : rows) {
output->append(redis::BulkString(key));
output->append(MultiLen(fields.size() * 2));
for (const auto &[info, field] : fields) {
output->append(redis::BulkString(info->name));
output->append(redis::BulkString(field));
}
}
}

class CommandFTSearchSQL : public Commander {
Status Execute(Server *srv, Connection *conn, std::string *output) override {
const auto &sql = args_[1];
Expand All @@ -146,15 +160,7 @@ class CommandFTSearchSQL : public Commander {

auto results = GET_OR_RET(srv->index_mgr.Search(std::move(ir), conn->GetNamespace()));

output->append(MultiLen(results.size()));
for (const auto &[key, fields, _] : results) {
output->append(MultiLen(2));
output->append(redis::BulkString(key));
output->append(MultiLen(fields.size()));
for (const auto &[_, field] : fields) {
output->append(redis::BulkString(field));
}
}
DumpQueryResult(results, output);

return Status::OK();
};
Expand Down Expand Up @@ -211,15 +217,7 @@ class CommandFTSearch : public Commander {
CHECK(ir_);
auto results = GET_OR_RET(srv->index_mgr.Search(std::move(ir_), conn->GetNamespace()));

output->append(MultiLen(results.size()));
for (const auto &[key, fields, _] : results) {
output->append(MultiLen(2));
output->append(redis::BulkString(key));
output->append(MultiLen(fields.size()));
for (const auto &[_, field] : fields) {
output->append(redis::BulkString(field));
}
}
DumpQueryResult(results, output);

return Status::OK();
};
Expand Down
2 changes: 1 addition & 1 deletion src/search/index_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ struct IndexManager {
auto plan_ir = kqir::PassManager::Execute(kqir::PassManager::Default(), std::move(ir));
std::unique_ptr<kqir::PlanOperator> plan_op;
if (plan_op = kqir::Node::As<kqir::PlanOperator>(std::move(plan_ir)); !plan_op) {
return {Status::NotOK, "failed to convert the SQL query to plan operators"};
return {Status::NotOK, "failed to convert the query to plan operators"};
}

kqir::ExecutorContext executor_ctx(plan_op.get(), storage);
Expand Down
Loading