class GdsApi::Search

@api documented

def add_document(*args)

Other tags:
    See: https://github.com/alphagov/search-api/blob/master/doc/documents.md -

Returns:
  • (GdsApi::Response) - A status code of 202 indicates the document has been successfully queued.

Parameters:
  • index_name (V2 only) -- Name of the index to be deleted from on
  • document (Hash) -- The document to add. Must match the search-api schema matching the `type` parameter and contain a `link` field.
  • id (String) -- The search-api/elasticsearch id. Typically the same as the `link` field, but this is not strictly enforced.
  • type (String) -- The search-api document type.
def add_document(*args)
  @api.add_document(*args)
end

def base_url

def base_url
  endpoint
end

def batch_search(searches, additional_headers = {})

Parameters:
  • searches (Array) -- An array valid search queries. Maximum of 6. See search-api documentation for options.
def batch_search(searches, additional_headers = {})
  url_friendly_searches = searches.each_with_index.map do |search, index|
    { index => search }
  end
  searches_query = { search: url_friendly_searches }
  request_url = "#{base_url}/batch_search.json?#{Rack::Utils.build_nested_query(searches_query)}"
  get_json(request_url, additional_headers)
end

def delete_content(base_path)

Other tags:
    See: https://github.com/alphagov/search-api/blob/master/doc/content-api.md -

Parameters:
  • base_path () -- Base path of the page on GOV.UK.
def delete_content(base_path)
  request_url = "#{base_url}/content?link=#{base_path}"
  delete_json(request_url)
end

def delete_document(*args)

Parameters:
  • index_name (V2 only) -- Name of the index to be deleted from on
  • id (String) -- The search-api/elasticsearch id. Typically the same as the `link` field.
  • type (String) -- The search-api document type.
def delete_document(*args)
  @api.delete_document(*args)
end

def documents_url

def documents_url
  "#{base_url}/documents"
end

def get_content(base_path)

Other tags:
    See: https://github.com/alphagov/search-api/blob/master/doc/content-api.md -

Parameters:
  • base_path (String) -- Base path of the page on GOV.UK.
def get_content(base_path)
  request_url = "#{base_url}/content?link=#{base_path}"
  get_json(request_url)
end

def initialize(endpoint_url, options = {})

def initialize(endpoint_url, options = {})
  super
  # The API version provides a simple wrapper around this base class so that we
  # can still access the shared methods present in this class.
  version = options.fetch(:api_version, DEFAULT_API_VERSION)
  api_class = API_VERSIONS[version] || raise(UnknownAPIVersion)
  @api = api_class.new(self)
end

def search(args, additional_headers = {})

Other tags:
    See: https://github.com/alphagov/search-api/blob/master/doc/search-api.md -

Parameters:
  • args (Hash) -- A valid search query. See search-api documentation for options.
def search(args, additional_headers = {})
  request_url = "#{base_url}/search.json?#{Rack::Utils.build_nested_query(args)}"
  get_json(request_url, additional_headers)
end

def search_enum(args, page_size: 100, additional_headers: {})

Other tags:
    See: https://github.com/alphagov/search-api/blob/master/doc/search-api.md -

Parameters:
  • page_size (Integer) -- Number of results in each page.
  • args (Hash) -- A valid search query. See search-api documentation for options.
def search_enum(args, page_size: 100, additional_headers: {})
  Enumerator.new do |yielder|
    (0..Float::INFINITY).step(page_size).each do |index|
      search_params = args.merge(start: index.to_i, count: page_size)
      results = search(search_params, additional_headers).to_h.fetch("results", [])
      results.each do |result|
        yielder << result
      end
      if results.count < page_size
        break
      end
    end
  end
end