Class: GdsApi::Rummager

Inherits:
Base
  • Object
show all
Defined in:
lib/gds_api/rummager.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#client, #create_client, #get_list, #initialize, #url_for_slug

Constructor Details

This class inherits a constructor from GdsApi::Base

Instance Method Details

#add_document(type, id, document) ⇒ GdsApi::Response

Add a document to the search index.

Parameters:

  • type (String)

    The rummager/elasticsearch document type.

  • id (String)

    The rummager/elasticsearch id. Typically the same as the ‘link` field, but this is not strictly enforced.

  • document (Hash)

    The document to add. Must match the rummager schema matchin the ‘type` parameter and contain a `link` field.

Returns:

  • (GdsApi::Response)

    A status code of 202 indicates the document has been successfully queued.

See Also:



34
35
36
37
38
39
40
41
42
# File 'lib/gds_api/rummager.rb', line 34

def add_document(type, id, document)
  post_json(
    documents_url,
    document.merge(
      _type: type,
      _id: id,
    )
  )
end

#advanced_search(args) ⇒ Object

Deprecated.

Only in use by Whitehall. Use the ‘#search` method.

Advanced search.

Raises:

  • (ArgumentError)


20
21
22
23
24
# File 'lib/gds_api/rummager.rb', line 20

def advanced_search(args)
  raise ArgumentError.new("Args cannot be blank") if args.nil? || args.empty?
  request_path = "#{base_url}/advanced_search?#{Rack::Utils.build_nested_query(args)}"
  get_json(request_path)
end

#delete_content(base_path) ⇒ Object

Delete a content-document from the index by base path.

Content documents are pages on GOV.UK that have a base path and are returned in searches. This excludes best bets, recommended-links, and contacts, which may be deleted with ‘delete_document`.

Parameters:

  • base_path

    Base path of the page on GOV.UK.

See Also:



52
53
54
55
# File 'lib/gds_api/rummager.rb', line 52

def delete_content(base_path)
  request_url = "#{base_url}/content?link=#{base_path}"
  delete_json(request_url)
end

#delete_content!Object



58
59
60
# File 'lib/gds_api/rummager.rb', line 58

def delete_content!(*)
  raise "`Rummager#delete_content!` is deprecated. Use `Rummager#delete_content`"
end

#delete_document(type, id) ⇒ Object

Delete a non-content document from the search index.

For example, best bets, recommended links, or contacts.

Parameters:

  • type (String)

    The rummager/elasticsearch document type.

  • id (String)

    The rummager/elasticsearch id. Typically the same as the ‘link` field.



86
87
88
89
90
91
# File 'lib/gds_api/rummager.rb', line 86

def delete_document(type, id)
  delete_json(
    "#{documents_url}/#{id}",
    _type: type,
  )
end

#get_content(base_path) ⇒ Object

Retrieve a content-document from the index.

Content documents are pages on GOV.UK that have a base path and are returned in searches. This excludes best bets, recommended-links, and contacts.

Parameters:

  • base_path (String)

    Base path of the page on GOV.UK.

See Also:



70
71
72
73
# File 'lib/gds_api/rummager.rb', line 70

def get_content(base_path)
  request_url = "#{base_url}/content?link=#{base_path}"
  get_json(request_url)
end

#get_content!Object



76
77
78
# File 'lib/gds_api/rummager.rb', line 76

def get_content!(*)
  raise "`Rummager#get_content!` is deprecated. Use `Rummager#get_content`"
end

#search(args) ⇒ Object

Perform a search.

Parameters:

  • args (Hash)

    A valid search query. See Rummager documentation for options.

See Also:



12
13
14
15
# File 'lib/gds_api/rummager.rb', line 12

def search(args)
  request_url = "#{base_url}/search.json?#{Rack::Utils.build_nested_query(args)}"
  get_json(request_url)
end