Skip to content

Commit

Permalink
BH_4879: stop search based on max results arg
Browse files Browse the repository at this point in the history
  • Loading branch information
VVS committed Feb 18, 2024
1 parent fd2647e commit d12c807
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion components/core/src/clp_s/clp-s.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ bool search_archive(
archive_dir,
timestamp_dict,
std::move(output_handler),
command_line_arguments.get_ignore_case()
command_line_arguments.get_ignore_case(),
command_line_arguments.get_max_num_results()
);
output.filter();

Expand Down
6 changes: 6 additions & 0 deletions components/core/src/clp_s/search/Output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace clp_s::search {
void Output::filter() {
auto top_level_expr = m_expr;
auto total_matched_results = 0;

for (auto const& archive : ReaderUtils::get_archives(m_archives_dir)) {
std::vector<int32_t> matched_schemas;
Expand Down Expand Up @@ -113,7 +114,12 @@ void Output::filter() {
}
} else {
while (reader.get_next_message(message, this)) {
if (total_matched_results >= m_max_num_results) {

break;
}
m_output_handler->write(message);
total_matched_results = total_matched_results + 1;
}
}

Expand Down
7 changes: 5 additions & 2 deletions components/core/src/clp_s/search/Output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ class Output : public FilterClass {
std::string archives_dir,
std::shared_ptr<TimestampDictionaryReader> timestamp_dict,
std::unique_ptr<OutputHandler> output_handler,
bool ignore_case)
bool ignore_case,
uint64_t max_num_results)
: m_schema_tree(std::move(tree)),
m_schemas(std::move(schemas)),
m_match(match),
m_expr(std::move(expr)),
m_archives_dir(std::move(archives_dir)),
m_timestamp_dict(std::move(timestamp_dict)),
m_output_handler(std::move(output_handler)),
m_ignore_case(ignore_case) {}
m_ignore_case(ignore_case),
m_max_num_results{max_num_results} {}

/**
* Filters messages from all archives
Expand All @@ -52,6 +54,7 @@ class Output : public FilterClass {
std::string m_archives_dir;
std::unique_ptr<OutputHandler> m_output_handler;
bool m_ignore_case;
uint64_t m_max_num_results;

// variables for the current schema being filtered
std::vector<BaseColumnReader*> m_searched_columns;
Expand Down

0 comments on commit d12c807

Please sign in to comment.