Class: Qa::Authorities::LinkedData::SearchQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/qa/authorities/linked_data/search_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_config) ⇒ SearchQuery

Returns a new instance of SearchQuery.

Parameters:

  • search_config (SearchConfig)

    The search portion of the config



14
15
16
# File 'lib/qa/authorities/linked_data/search_query.rb', line 14

def initialize(search_config)
  @search_config = search_config
end

Instance Attribute Details

#search_configObject (readonly)

Returns the value of attribute search_config.



18
19
20
# File 'lib/qa/authorities/linked_data/search_query.rb', line 18

def search_config
  @search_config
end

Instance Method Details

#search(query, request_header: {}, language: nil, replacements: {}, subauth: nil, context: false, performance_data: false) ⇒ String

Note:

All parameters after request_header are deprecated and will be removed in the next major release.

Search a linked data authority

Examples:

Json Results for Linked Data Search

[ {"uri":"http://id.worldcat.org/fast/5140","id":"5140","label":"Cornell, Joseph"},
  {"uri":"http://id.worldcat.org/fast/72456","id":"72456","label":"Cornell, Sarah Maria, 1802-1832"},
  {"uri":"http://id.worldcat.org/fast/409667","id":"409667","label":"Cornell, Ezra, 1807-1874"} ]

Parameters:

  • request_header (Hash) (defaults to: {})

    optional attributes that can be appended to the generated URL

  • language (Hash) (defaults to: nil)

    a customizable set of options

  • replacements (Hash) (defaults to: {})

    a customizable set of options

  • subauthority (Hash)

    a customizable set of options

  • context (Hash) (defaults to: false)

    a customizable set of options

  • performance_data (Hash) (defaults to: false)

    a customizable set of options

Options Hash (language:):

  • language (Symbol)

    used to select literals when multi-language is supported (e.g. :en, :fr, etc.)

Options Hash (replacements:):

  • replacement (Hash)

    values with { pattern_name (defined in YAML config) => value }

Options Hash (context:):

  • true (Boolean)

    if context should be returned with the results; otherwise, false (default: false)

Options Hash (performance_data:):

  • true (Boolean)

    if include_performance_data should be returned with the results; otherwise, false (default: false)

Returns:

  • (String)

    json results

Raises:



37
38
39
40
41
42
43
44
45
# File 'lib/qa/authorities/linked_data/search_query.rb', line 37

def search(query, request_header: {}, language: nil, replacements: {}, subauth: nil, context: false, performance_data: false) # rubocop:disable Metrics/ParameterLists
  request_header = build_request_header(language: language, replacements: replacements, subauth: subauth, context: context, performance_data: performance_data) if request_header.empty?
  unpack_request_header(request_header)
  raise Qa::InvalidLinkedDataAuthority, "Unable to initialize linked data search sub-authority #{subauthority}" unless subauthority.nil? || subauthority?(subauthority)
  url = authority_service.build_url(action_config: search_config, action: :search, action_request: query, request_header: request_header)
  Rails.logger.info "QA Linked Data search url: #{url}"
  load_graph(url: url)
  normalize_results
end