Class: Libis::Services::Scope::Search
- Inherits:
-
Object
- Object
- Libis::Services::Scope::Search
show all
- Includes:
- GenericSearch
- Defined in:
- lib/libis/services/scope/search.rb
Instance Attribute Summary collapse
#base, #host, #index, #num_records, #record_pointer, #session_id, #set_number, #term
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Search
Returns a new instance of Search.
14
15
16
|
# File 'lib/libis/services/scope/search.rb', line 14
def initialize
@doc = nil
end
|
Instance Attribute Details
#oracle ⇒ Object
Returns the value of attribute oracle.
12
13
14
|
# File 'lib/libis/services/scope/search.rb', line 12
def oracle
@oracle
end
|
Instance Method Details
#connect(name, password, database = nil) ⇒ Object
18
19
20
21
22
|
# File 'lib/libis/services/scope/search.rb', line 18
def connect(name, password, database = nil)
database ||= 'libis-db-scope.cc.kuleuven.be:1556/SCOPEP.kuleuven.be'
@oracle = OracleClient.new("#{name}/#{password}@#{database}")
self
end
|
#connect_url(url) ⇒ Object
24
25
26
27
|
# File 'lib/libis/services/scope/search.rb', line 24
def connect_url(url)
@oracle = OracleClient.new(url)
self
end
|
#each(_ = {}) {|@doc| ... } ⇒ Object
62
63
64
|
# File 'lib/libis/services/scope/search.rb', line 62
def each(_ = {})
yield @doc
end
|
#find(term, options = {}) ⇒ Object
29
30
31
|
# File 'lib/libis/services/scope/search.rb', line 29
def find(term, options = {})
super
end
|
#next_record(_ = {}) {|@doc| ... } ⇒ Object
66
67
68
|
# File 'lib/libis/services/scope/search.rb', line 66
def next_record(_ = {})
yield @doc
end
|
#query(term, options = {}) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/libis/services/scope/search.rb', line 33
def query(term, options = {})
case options[:type] || 'REPCODE'
when 'REPCODE'
@oracle.call('kul_packages.scope_xml_meta_file_ed', [term.upcase])
when 'ID'
@oracle.call('kul_packages.scope_xml_meta_file_by_id', [term.to_i])
else
raise RuntimeError, "Invalid Scope search type '#{options[:type]}'"
end
term = term.gsub(/[-\/]/, '_')
err_file = "/nas/vol03/oracle/#{options[:dir] || 'SCOPEP'}/#{term}_err.XML"
md_file = "/nas/vol03/oracle/#{options[:dir] || 'SCOPEP'}/#{term}_md.XML"
if File.exist? err_file
doc = Libis::Tools::XmlDocument.open(err_file)
msg = doc['/error/error_msg']
detail = doc['/error/error_']
File.delete(err_file) rescue nil
@doc = nil
raise RuntimeError, "Scope search failed: '#{msg}'. Details: '#{detail}'"
elsif File.exist? md_file
@doc = Libis::Tools::XmlDocument.open(md_file)
File.delete(md_file) rescue nil
@doc
else
raise RuntimeError, 'Scope search did not generate expected result file.'
end
end
|