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, language: nil, replacements: {}, subauth: nil, context: false, performance_data: false) ⇒ String

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:

  • language (Symbol) (defaults to: nil)

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

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

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

  • subauth (String) (defaults to: nil)

    (optional) the subauthority to query

  • context (Boolean) (defaults to: false)

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

  • performance_data (Boolean) (defaults to: false)

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

Returns:

  • (String)

    json results

Raises:



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

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