class DogBiscuits::TermsService
Public Class Methods
# File lib/dog_biscuits/services/terms_service.rb, line 5 def initialize(_authority = nil) @authority = self end
Public Instance Methods
Returns all items in the authority using preflabel_si to get exact match (string instead of token)
# File lib/dog_biscuits/services/terms_service.rb, line 22 def all sort_order = 'preflabel_si asc' parse_authority_response( ActiveFedora::SolrService.get( "inScheme_ssim:\"#{terms_id}\"", fl: 'id,preflabel_tesim,definition_tesim,broader_ssim', rows: 1000, sort: sort_order ) ) end
Find an authority term by id
@param id [String] for the requested authority term @return [Hash] all info about the authority
# File lib/dog_biscuits/services/terms_service.rb, line 38 def find(id) parse_authority_response( ActiveFedora::SolrService.get( "id:\"#{id}\"", fq: "inScheme_ssim:\"#{terms_id}\"", fl: 'id,preflabel_tesim,definition_tesim,broader_ssim', rows: 1 ) ) end
Find the id for an authority term using preflabel_si to get exact match (string instead of token)
@param term [String] the authority term preflabel @return the term id
# File lib/dog_biscuits/services/terms_service.rb, line 68 def find_id(term) parse_terms_id_response( ActiveFedora::SolrService.get( "preflabel_si:\"#{term}\"", fq: "inScheme_ssim:\"#{terms_id}\"", fl: 'id', rows: 1 ) ) end
Find the id for an authority term using preflabel and alt_label (use preflabel_si to get exact match (string instead of token))
@param term [String] the authority term preflabel or alt_label @return the term id
# File lib/dog_biscuits/services/terms_service.rb, line 83 def find_id_with_alts(term) parse_terms_id_response( ActiveFedora::SolrService.get( "preflabel_si:\"#{term}\" OR altlabel_tesim:\"#{term}\")", fq: "inScheme_ssim:\"#{terms_id}\"", fl: 'id', rows: 1 ) ) end
Find an authority term by id
@param id [String] for the requested authority term @return [String] the preflabel
# File lib/dog_biscuits/services/terms_service.rb, line 98 def find_label_string(id) parse_string( ActiveFedora::SolrService.get( "id:\"#{id}\"", fq: "inScheme_ssim:\"#{terms_id}\"", fl: 'preflabel_tesim', rows: 1 ) ) end
Query an authority for a given word or phrase
@param q [String] search query @return [Hash] search results
# File lib/dog_biscuits/services/terms_service.rb, line 53 def search(q) parse_authority_response( ActiveFedora::SolrService.get( "preflabel_tesim:*#{CGI.escape(q)}*", fq: "inScheme_ssim:\"#{terms_id}\"", fl: 'id,preflabel_tesim,definition_tesim,broader_ssim', rows: 1000 ) ) end
# File lib/dog_biscuits/services/terms_service.rb, line 109 def select_all_options all.map { |e| [e[:label], e[:id]] } end
Returns the ConceptScheme
id for a given Scheme name
@return id of the ConceptScheme
object
# File lib/dog_biscuits/services/terms_service.rb, line 12 def terms_id parse_terms_id_response( ActiveFedora::SolrService.get( "has_model_ssim:\"DogBiscuits::ConceptScheme\" AND preflabel_tesim:\"#{terms_list} \"", {} ) ) end
Private Instance Methods
Parse the preflabel from the solr response
@param response [SolrResponse] for the Solr
query @return [String] preflabel
# File lib/dog_biscuits/services/terms_service.rb, line 154 def parse_string(response) str = '' response['response']['docs'].map do |result| str = result['preflabel_tesim'] end str end
Parse the id from the solr response
@param response [SolrResponse] for the Solr
query @return [String] id
# File lib/dog_biscuits/services/terms_service.rb, line 142 def parse_terms_id_response(response) id = '' response['response']['docs'].map do |result| id = result['id'] end id end