Class: SiteSearch::Query

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

Overview

One site search across every engine, for Www::SearchController#index.

The browser used to do this itself: POST to api.swiftype.com, GET our
publications endpoint, interleave the two, normalize the types and tally the
counts. All of that lives here now, so the client asks one URL for one answer
and the engines behind it can change without a bundle release. Replacing
Swiftype with in-house search (doc/tasks/202512141800_SWIFTYPE_REPLACEMENT.md)
means writing one more adapter and editing #fetch, nothing else.

Defined Under Namespace

Classes: Pagination, Result

Constant Summary collapse

TYPES =

Filter tabs the UI offers. Anything else is rejected by the controller.

%w[All FAQ Product Blog Video Support Publication].freeze
DEFAULT_TYPE =

The tab an unrecognised or absent filter falls back to.

'All'
SWIFTYPE_PER_PUBLICATION =

Publications are ours and Swiftype has never indexed them, so a blended
page mixes them in at one per three rather than letting either bury the
other.

3

Instance Method Summary collapse

Methods included from Service

#attributes_used, #build_result, call, #logger

Methods included from Service::Initializer

#initialize

Instance Method Details

#callResult

Returns one ranked page across every engine this filter uses.

Returns:

  • (Result)

    one ranked page across every engine this filter uses



64
65
66
67
68
69
70
71
# File 'app/services/site_search/query.rb', line 64

def call
  return empty_result if query.blank?

  results, adapters = fetch
  Result.new(query:, type: effective_type, results:,
             pagination: combine(adapters.map(&:pagy)),
             degraded: adapters.any?(&:degraded))
end