Class: Karafka::Web::Pro::Ui::Controllers::SearchController

Inherits:
Ui::Controllers::ClusterController show all
Defined in:
lib/karafka/web/pro/ui/controllers/search_controller.rb

Overview

Handles the search requests We present this as a part of explorer scope but we use a separate controller not to mix data exploring with searching.

Constant Summary

Constants inherited from Ui::Controllers::BaseController

Ui::Controllers::BaseController::Models

Instance Method Summary collapse

Methods inherited from Ui::Controllers::ClusterController

#brokers, #replication

Methods inherited from Ui::Controllers::BaseController

#initialize

Constructor Details

This class inherits a constructor from Karafka::Web::Ui::Controllers::BaseController

Instance Method Details

#index(topic_id) ⇒ Object

Note:

In theory search can be used to detect pieces of information within messages. Since we allow for custom search strategies, this is not an issue because users that need to provide only granular search can do so.

Runs the search if search parameters are provided If no parameters provided, displays the search modal and info to provide search data If invalid search parameters provided, modal contains errors

Parameters:

  • topic_id (String)

    topic we’re interested in



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/karafka/web/pro/ui/controllers/search_controller.rb', line 31

def index(topic_id)
  @topic_id = topic_id
  @partitions_count = Models::ClusterInfo.partitions_count(topic_id)
  # Select only matchers that should be available in the context of the current topic
  @matchers = Web.config.ui.search.matchers.select { |match| match.active?(@topic_id) }
  @search_criteria = !@params.current_search.empty?
  @current_search = Lib::Search::Normalizer.call(@params.current_search)
  # Needed when rendering found messages rows. We should always filter the messages
  # details with the visibility filter
  @visibility_filter = ::Karafka::Web.config.ui.policies.messages
  @limits = ::Karafka::Web.config.ui.search.limits.sort

  # If there is search form filled, we validate it to make sure there are no errors
  @errors = if @search_criteria
              Lib::Search::Contracts::Form.new.call(@current_search).errors
            else
              {}
            end

  # If all good we run the search
  if @search_criteria && @errors.empty?
    found, @search_details = Lib::Search::Runner.new(
      @topic_id,
      @partitions_count,
      @current_search
    ).call

    @messages, last_page = Paginators::Arrays.call(
      found,
      @params.current_page
    )

    paginate(@params.current_page, !last_page)
  end

  render
end