class Qa::Authorities::LinkedData::SearchConfig

Attributes

full_config[R]
prefixes[R]
search_config[R]

Public Class Methods

new(config, prefixes = {}, full_config = nil) click to toggle source

@param [Hash] config the search portion of the config @param [Hash<Symbol><String>] prefixes URL map of prefixes to use with ldpaths @param [Qa::Authorities::LinkedData::Config] full_config the full linked data configuration that the passed in search config is part of

# File lib/qa/authorities/linked_data/config/search_config.rb, line 16
def initialize(config, prefixes = {}, full_config = nil)
  @search_config = config
  @prefixes = prefixes
  @full_config = full_config
end

Public Instance Methods

context_map() click to toggle source

Return the context map if it is defined @return [Qa::LinkedData::Config::ContextMap] the context map

# File lib/qa/authorities/linked_data/config/search_config.rb, line 138
def context_map
  return nil unless search_config.key?(:context)
  @context_map ||= Qa::LinkedData::Config::ContextMap.new(search_config.fetch(:context), prefixes)
end
info() click to toggle source
# File lib/qa/authorities/linked_data/config/search_config.rb, line 201
def info
  return [] unless supports_search?
  auth_name = authority_name.downcase.to_s
  language = Qa::LinkedData::LanguageService.preferred_language(authority_language: language).map(&:to_s)
  details = summary_without_subauthority(auth_name, language)
  subauthorities.each_key { |subauth_name| details << summary_with_subauthority(auth_name, subauth_name.downcase.to_s, language) }
  details
end
language() click to toggle source

Return the preferred language for literal value selection for search query. This is the default used for this authority if the user does not pass in a language. Only applies if the authority provides language encoded literals. @return [String] the configured language for search query

# File lib/qa/authorities/linked_data/config/search_config.rb, line 38
def language
  return @language unless @language.nil?
  lang = search_config[:language]
  return nil if lang.nil?
  lang = [lang] if lang.is_a? String
  @language = lang.collect(&:to_sym)
end
qa_replacement_patterns() click to toggle source

Return parameters that are supported directly by QA api (e.g. q, subauth, lang) @return [Hash] the configured search url parameter mappings

# File lib/qa/authorities/linked_data/config/search_config.rb, line 145
def qa_replacement_patterns
  search_config.fetch(:qa_replacement_patterns, {})
end
requested_records_parameter() click to toggle source

@return [String] name of parameter holding number of requested records

# File lib/qa/authorities/linked_data/config/search_config.rb, line 191
def requested_records_parameter
  qa_replacement_patterns.key?(:requested_records) ? qa_replacement_patterns[:requested_records] : nil
end
results() click to toggle source

Return results ldpaths or predicates if specified @return [Hash,NilClass] all the configured ldpaths or predicates to pull out of the results

# File lib/qa/authorities/linked_data/config/search_config.rb, line 48
def results
  search_config[:results]
end
results_altlabel_ldpath() click to toggle source

Return results altlabel_ldpath @return [String] the configured ldpath to use to extract altlabel values from the results

# File lib/qa/authorities/linked_data/config/search_config.rb, line 90
def results_altlabel_ldpath
  Config.config_value(results, :altlabel_ldpath)
end
results_altlabel_predicate() click to toggle source

Return results altlabel_predicate @return [String] the configured predicate to use to extract altlabel values from the results

# File lib/qa/authorities/linked_data/config/search_config.rb, line 96
def results_altlabel_predicate
  Qa.deprecation_warning(
    in_msg: 'Qa::Authorities::LinkedData::SearchConfig',
    msg: "`results_altlabel_predicate` is deprecated; use `results_altlabel_ldpath` by updating linked data " \
         "search config results in authority #{authority_name} to specify as `altlabel_ldpath`"
  )
  Config.predicate_uri(results, :altlabel_predicate)
end
results_id_ldpath() click to toggle source

Return results id_ldpath @return [String] the configured ldpath to use to extract the id from the results

# File lib/qa/authorities/linked_data/config/search_config.rb, line 54
def results_id_ldpath
  Config.config_value(results, :id_ldpath)
end
results_id_predicate() click to toggle source

Return results id_predicate @return [String] the configured predicate to use to extract the id from the results

# File lib/qa/authorities/linked_data/config/search_config.rb, line 60
def results_id_predicate
  Qa.deprecation_warning(
    in_msg: 'Qa::Authorities::LinkedData::SearchConfig',
    msg: "`results_id_predicate` is deprecated; use `results_id_ldpath` by updating linked data search config results " \
         "in authority #{authority_name} to specify as `id_ldpath`"
  )
  Config.predicate_uri(results, :id_predicate)
end
results_label_ldpath() click to toggle source

Return results label_ldpath @return [String] the configured ldpath to use to extract label values from the results

# File lib/qa/authorities/linked_data/config/search_config.rb, line 71
def results_label_ldpath
  Config.config_value(results, :label_ldpath)
end
results_label_predicate(suppress_deprecation_warning: false) click to toggle source

Return results label_predicate @return [String] the configured predicate to use to extract label values from the results

# File lib/qa/authorities/linked_data/config/search_config.rb, line 77
def results_label_predicate(suppress_deprecation_warning: false)
  unless suppress_deprecation_warning
    Qa.deprecation_warning(
      in_msg: 'Qa::Authorities::LinkedData::SearchConfig',
      msg: "`results_label_predicate` is deprecated; use `results_label_ldpath` by updating linked data search config results " \
           "in authority #{authority_name} to specify as `label_ldpath`"
    )
  end
  Config.predicate_uri(results, :label_predicate)
end
results_sort_ldpath() click to toggle source

Return results sort_ldpath @return [String] the configured ldpath to use for sorting results from the query search

# File lib/qa/authorities/linked_data/config/search_config.rb, line 114
def results_sort_ldpath
  Config.config_value(results, :sort_ldpath)
end
results_sort_predicate() click to toggle source

Return results sort_predicate @return [String] the configured predicate to use for sorting results from the query search

# File lib/qa/authorities/linked_data/config/search_config.rb, line 120
def results_sort_predicate
  Qa.deprecation_warning(
    in_msg: 'Qa::Authorities::LinkedData::SearchConfig',
    msg: "`results_sort_predicate` is deprecated; use `results_sort_ldpath` by updating linked data " \
         "search config results in authority #{authority_name} to specify as `sort_ldpath`"
  )
  Config.predicate_uri(results, :sort_predicate)
end
start_record_parameter() click to toggle source

@return [String] name of parameter holding start record number

# File lib/qa/authorities/linked_data/config/search_config.rb, line 186
def start_record_parameter
  qa_replacement_patterns.key?(:start_record) ? qa_replacement_patterns[:start_record] : nil
end
subauthorities() click to toggle source

Return the list of subauthorities for search query @return [Hash] the configurations for search url replacements

# File lib/qa/authorities/linked_data/config/search_config.rb, line 180
def subauthorities
  @subauthorities ||= {} if search_config.nil? || !(search_config.key? :subauthorities)
  @subauthorities ||= search_config.fetch(:subauthorities)
end
subauthorities?() click to toggle source

Are there subauthorities configured for search query? @return [True|False] true if there are subauthorities configured for search query; otherwise, false

# File lib/qa/authorities/linked_data/config/search_config.rb, line 161
def subauthorities?
  subauthority_count.positive?
end
subauthority?(subauth_name) click to toggle source

Is a specific subauthority configured for search query? @return [True|False] true if the specified subauthority is configured for search query; otherwise, false

# File lib/qa/authorities/linked_data/config/search_config.rb, line 167
def subauthority?(subauth_name)
  subauth_name = subauth_name.to_sym if subauth_name.is_a? String
  subauthorities.key? subauth_name
end
subauthority_count() click to toggle source

Return the number of subauthorities defined for search query @return [Integer] the number of subauthorities defined for search query

# File lib/qa/authorities/linked_data/config/search_config.rb, line 174
def subauthority_count
  subauthorities.size
end
supports_context?() click to toggle source

Does this authority configuration support additional context in search results? @return [True|False] true if additional context in search results is supported; otherwise, false

# File lib/qa/authorities/linked_data/config/search_config.rb, line 131
def supports_context?
  return true if context_map.present?
  false
end
supports_language_parameter?() click to toggle source

@return [Boolean] true if supports language parameter; otherwise, false

# File lib/qa/authorities/linked_data/config/search_config.rb, line 155
def supports_language_parameter?
  qa_replacement_patterns.key? :lang
end
supports_search?() click to toggle source

Does this authority configuration have search defined? @return [Boolean] true if search is configured; otherwise, false

# File lib/qa/authorities/linked_data/config/search_config.rb, line 24
def supports_search?
  search_config.present?
end
supports_sort?() click to toggle source

Does this authority configuration support sorting of search results? @return [True|False] true if sorting of search results is supported; otherwise, false

# File lib/qa/authorities/linked_data/config/search_config.rb, line 107
def supports_sort?
  return true unless results_sort_ldpath.present? || !results_sort_predicate.present?
  false
end
supports_subauthorities?() click to toggle source

@return [Boolean] true if supports subauthorities; otherwise, false

# File lib/qa/authorities/linked_data/config/search_config.rb, line 150
def supports_subauthorities?
  qa_replacement_patterns.key?(:subauth) && subauthorities?
end
total_count_ldpath() click to toggle source

@return [String] ldpath of the triple that holds the total number of available records for a search @see service_subject_uri

# File lib/qa/authorities/linked_data/config/search_config.rb, line 197
def total_count_ldpath
  search_config.key?(:total_count_ldpath) ? search_config[:total_count_ldpath] : nil
end
url_config() click to toggle source

Return search url template defined in the configuration for this authority. @return [Qa::IriTemplate::UrlConfig] the configured search url template

# File lib/qa/authorities/linked_data/config/search_config.rb, line 30
def url_config
  @url_config ||= Qa::IriTemplate::UrlConfig.new(search_config[:url]) if supports_search?
end

Private Instance Methods

summary_with_subauthority(auth_name, subauth_name, language) click to toggle source
# File lib/qa/authorities/linked_data/config/search_config.rb, line 224
def summary_with_subauthority(auth_name, subauth_name, language)
  {
    "label" => "#{auth_name} search #{subauth_name} (QA)",
    "uri" => "urn:qa:search:#{auth_name}:#{subauth_name}",
    "authority" => auth_name,
    "subauthority" => subauth_name,
    "action" => "search",
    "language" => language
  }
end
summary_without_subauthority(auth_name, language) click to toggle source
# File lib/qa/authorities/linked_data/config/search_config.rb, line 212
def summary_without_subauthority(auth_name, language)
  [
    {
      "label" => "#{auth_name} search (QA)",
      "uri" => "urn:qa:search:#{auth_name}",
      "authority" => auth_name,
      "action" => "search",
      "language" => language
    }
  ]
end