Module: Searchjoy::Track::Query

Defined in:
lib/searchjoy/track.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



25
26
27
28
29
# File 'lib/searchjoy/track.rb', line 25

def execute
  results = super
  track
  results
end

#searchObject



31
32
33
# File 'lib/searchjoy/track.rb', line 31

def search
  @execute.search if @execute
end

#trackObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/searchjoy/track.rb', line 4

def track
  results = @execute

  if options[:track] && !results.search
    attributes = options[:track] == true ? {} : options[:track]

    search_type =
      if klass.respond_to?(:name) && klass.name.present?
        klass.name
      elsif options[:models]
        Array(options[:models]).map(&:to_s).sort.join(" ")
      elsif options[:index_name]
        Array(options[:index_name]).map(&:to_s).sort.join(" ")
      else
        "All Indices"
      end

    results.search = Searchjoy::Search.create({search_type: search_type, query: term, results_count: results.total_count}.merge(attributes))
  end
end