Class: Dor::SearchService

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/services/search_service.rb

Overview

Used by Argo and dor-services-app

Class Method Summary collapse

Class Method Details

.find_sdr_graveyard_apo_druidObject



51
52
53
54
55
56
57
58
# File 'lib/dor/services/search_service.rb', line 51

def find_sdr_graveyard_apo_druid
  r = Dor::SearchService.query('dc_title_tesim:"SDR Graveyard"', fl: 'id')
  if r['response']['docs'].empty?
    nil
  else
    r['response']['docs'].first[:id]
  end
end

.index_versionObject



10
11
12
# File 'lib/dor/services/search_service.rb', line 10

def index_version
  Dor::VERSION
end

.query(query, args = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/dor/services/search_service.rb', line 14

def query(query, args = {})
  params = args.merge(q: query)
  params[:start] ||= 0
  resp = solr.get 'select', params: params
  return resp unless block_given?

  cont = true
  while cont && resp['response']['docs'].length > 0
    cont = yield(resp)
    params[:rows] ||= resp['response']['docs'].length
    params[:start] += params[:rows]
    resp = solr.get 'select', params: params
  end
end

.query_by_id(id) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dor/services/search_service.rb', line 29

def query_by_id(id)
  case id
  when Hash # Single valued: { :google => 'STANFORD_0123456789' }
    id = id.collect { |*v| v.join(':') }.first
  when Array # Two values: [ 'google', 'STANFORD_0123456789' ]
    id = id.join(':')
  end
  q = "{!term f=#{Solrizer.solr_name 'identifier', :symbol}}#{id}"
  result = []
  query(q, fl: 'id', rows: 1000, defType: 'lucene') do |resp|
    result += resp['response']['docs'].collect { |doc| doc['id'] }
    true
  end
  result
end

.sdr_graveyard_apo_druidObject

Returns String druid of the SDR Graveyard APO nil if APO does not exist in the currently configured environment.

Returns:

  • String druid of the SDR Graveyard APO nil if APO does not exist in the currently configured environment



47
48
49
# File 'lib/dor/services/search_service.rb', line 47

def sdr_graveyard_apo_druid
  @@sdr_graveyard_apo ||= find_sdr_graveyard_apo_druid
end