Class: Qa::Authorities::LinkedData::SearchConfig

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

Overview

rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, prefixes = {}, full_config = nil) ⇒ SearchConfig

Returns a new instance of SearchConfig.

Parameters:

  • config (Hash)

    the search portion of the config

  • prefixes (Hash<Symbol><String>) (defaults to: {})

    URL map of prefixes to use with ldpaths

  • full_config (Qa::Authorities::LinkedData::Config) (defaults to: nil)

    the full linked data configuration that the passed in search config is part of



16
17
18
19
20
# 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

Instance Attribute Details

#prefixesObject (readonly)

Returns the value of attribute prefixes.



8
9
10
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 8

def prefixes
  @prefixes
end

Instance Method Details

#context_mapQa::LinkedData::Config::ContextMap

Return the context map if it is defined

Returns:



132
133
134
135
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 132

def context_map
  return nil unless search_config.key?(:context)
  @context_map ||= Qa::LinkedData::Config::ContextMap.new(search_config.fetch(:context), prefixes)
end

#infoObject



179
180
181
182
183
184
185
186
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 179

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

#languageString

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.

Returns:

  • (String)

    the configured language for search query



38
39
40
41
42
43
44
# 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_patternsHash

Return parameters that are supported directly by QA api (e.g. q, subauth, lang)

Returns:

  • (Hash)

    the configured search url parameter mappings



139
140
141
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 139

def qa_replacement_patterns
  search_config.fetch(:qa_replacement_patterns, {})
end

#resultsHash, NilClass

Return results ldpaths or predicates if specified

Returns:

  • (Hash, NilClass)

    all the configured ldpaths or predicates to pull out of the results



48
49
50
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 48

def results
  search_config[:results]
end

#results_altlabel_ldpathString

Return results altlabel_ldpath

Returns:

  • (String)

    the configured ldpath to use to extract altlabel values from the results



86
87
88
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 86

def results_altlabel_ldpath
  Config.config_value(results, :altlabel_ldpath)
end

#results_altlabel_predicateString

Return results altlabel_predicate

Returns:

  • (String)

    the configured predicate to use to extract altlabel values from the results



92
93
94
95
96
97
98
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 92

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 to specify as `altlabel_ldpath`"
  )
  Config.predicate_uri(results, :altlabel_predicate)
end

#results_id_ldpathString

Return results id_ldpath

Returns:

  • (String)

    the configured ldpath to use to extract the id from the results



54
55
56
# 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_predicateString

Return results id_predicate

Returns:

  • (String)

    the configured predicate to use to extract the id from the results



60
61
62
63
64
65
66
# 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 to specify as `id_ldpath`"
  )
  Config.predicate_uri(results, :id_predicate)
end

#results_label_ldpathString

Return results label_ldpath

Returns:

  • (String)

    the configured ldpath to use to extract label values from the results



70
71
72
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 70

def results_label_ldpath
  Config.config_value(results, :label_ldpath)
end

#results_label_predicateString

Return results label_predicate

Returns:

  • (String)

    the configured predicate to use to extract label values from the results



76
77
78
79
80
81
82
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 76

def results_label_predicate
  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 to specify as `label_ldpath`"
  )
  Config.predicate_uri(results, :label_predicate)
end

#results_sort_ldpathString

Return results sort_ldpath

Returns:

  • (String)

    the configured ldpath to use for sorting results from the query search



109
110
111
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 109

def results_sort_ldpath
  Config.config_value(results, :sort_ldpath)
end

#results_sort_predicateString

Return results sort_predicate

Returns:

  • (String)

    the configured predicate to use for sorting results from the query search



115
116
117
118
119
120
121
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 115

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 to specify as `sort_ldpath`"
  )
  Config.predicate_uri(results, :sort_predicate)
end

#subauthoritiesHash

Return the list of subauthorities for search query

Returns:

  • (Hash)

    the configurations for search url replacements



174
175
176
177
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 174

def subauthorities
  @subauthorities ||= {} if search_config.nil? || !(search_config.key? :subauthorities)
  @subauthorities ||= search_config.fetch(:subauthorities)
end

#subauthorities?True|False

Are there subauthorities configured for search query?

Returns:

  • (True|False)

    true if there are subauthorities configured for search query; otherwise, false



155
156
157
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 155

def subauthorities?
  subauthority_count.positive?
end

#subauthority?(subauth_name) ⇒ True|False

Is a specific subauthority configured for search query?

Returns:

  • (True|False)

    true if the specified subauthority is configured for search query; otherwise, false



161
162
163
164
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 161

def subauthority?(subauth_name)
  subauth_name = subauth_name.to_sym if subauth_name.is_a? String
  subauthorities.key? subauth_name
end

#subauthority_countInteger

Return the number of subauthorities defined for search query

Returns:

  • (Integer)

    the number of subauthorities defined for search query



168
169
170
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 168

def subauthority_count
  subauthorities.size
end

#supports_context?True|False

Does this authority configuration support additional context in search results?

Returns:

  • (True|False)

    true if additional context in search results is supported; otherwise, false



125
126
127
128
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 125

def supports_context?
  return true if context_map.present?
  false
end

#supports_language_parameter?Boolean

Returns true if supports language parameter; otherwise, false.

Returns:

  • (Boolean)

    true if supports language parameter; otherwise, false



149
150
151
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 149

def supports_language_parameter?
  qa_replacement_patterns.key? :lang
end

#supports_search?Boolean

Does this authority configuration have search defined?

Returns:

  • (Boolean)

    true if search is configured; otherwise, false



24
25
26
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 24

def supports_search?
  search_config.present?
end

#supports_sort?True|False

Does this authority configuration support sorting of search results?

Returns:

  • (True|False)

    true if sorting of search results is supported; otherwise, false



102
103
104
105
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 102

def supports_sort?
  return true unless results_sort_ldpath.present? || !results_sort_predicate.present?
  false
end

#supports_subauthorities?Boolean

Returns true if supports language parameter; otherwise, false.

Returns:

  • (Boolean)

    true if supports language parameter; otherwise, false



144
145
146
# File 'lib/qa/authorities/linked_data/config/search_config.rb', line 144

def supports_subauthorities?
  qa_replacement_patterns.key?(:subauth) && subauthorities?
end

#url_configQa::IriTemplate::UrlConfig

Return search url template defined in the configuration for this authority.

Returns:



30
31
32
# 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