Class: SiteSearch::Query::Result

Inherits:
Data
  • Object
show all
Defined in:
app/services/site_search/query.rb

Overview

A whole search response: what was asked, what came back, and where it sits.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query: nil, type: DEFAULT_TYPE, results: [], pagination: Pagination.new, degraded: false) ⇒ Result

Returns a new instance of Result.

Parameters:

  • query (String, nil) (defaults to: nil)

    the term as searched

  • type (String) (defaults to: DEFAULT_TYPE)

    the filter tab

  • results (Array<SiteSearch::ResultItem>) (defaults to: [])
  • pagination (Pagination) (defaults to: Pagination.new)
  • degraded (Boolean) (defaults to: false)

    an engine failed to answer this page



48
49
50
51
# File 'app/services/site_search/query.rb', line 48

def initialize(query: nil, type: DEFAULT_TYPE, results: [], pagination: Pagination.new,
               degraded: false)
  super
end

Instance Attribute Details

#degradedObject (readonly)

Returns the value of attribute degraded

Returns:

  • (Object)

    the current value of degraded



42
43
44
# File 'app/services/site_search/query.rb', line 42

def degraded
  @degraded
end

#paginationObject (readonly)

Returns the value of attribute pagination

Returns:

  • (Object)

    the current value of pagination



42
43
44
# File 'app/services/site_search/query.rb', line 42

def pagination
  @pagination
end

#queryObject (readonly)

Returns the value of attribute query

Returns:

  • (Object)

    the current value of query



42
43
44
# File 'app/services/site_search/query.rb', line 42

def query
  @query
end

#resultsObject (readonly)

Returns the value of attribute results

Returns:

  • (Object)

    the current value of results



42
43
44
# File 'app/services/site_search/query.rb', line 42

def results
  @results
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



42
43
44
# File 'app/services/site_search/query.rb', line 42

def type
  @type
end

Instance Method Details

#as_jsonHash

total and has_more sit alongside pagination because the modal
heading reads a single number and the scroll guard reads a single boolean.

Returns:

  • (Hash)

    the whole search response



57
58
59
60
# File 'app/services/site_search/query.rb', line 57

def as_json(*)
  { query:, type:, total: pagination.count, has_more: pagination.next_page.present?,
    degraded:, pagination: pagination.as_json, results: results.map(&:as_json) }
end