-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patht.rb
56 lines (46 loc) · 1.33 KB
/
t.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require "pry"
require "simple_solr_client"
require "mlibrary_search_parser"
require "erb"
@config_file = "./spec/data/00-catalog.yml"
@config = YAML.load(ERB.new(File.read(@config_file)).result)
# Your solr port (local) or full URL (remote)
portOrURL = "http://julep-1.umdl.umich.edu:8023/solr"
# portOrURL = 9639
client = SimpleSolrClient::Client.new(portOrURL)
@core = client.core(client.cores.first)
# Other solr params
#
@solr_params = {
fl: "score,id,title,mainauthor",
rows: 10
}
# Index a document, translating title to title_common and
# setting a random id if needed and the allfields
def index(h)
h[:allfields] = h.values.join(" ")
h[:id] ||= Random.rand(100000)
h[:title_common] = h[:title] if h.has_key? :title
@core.add_docs(h).commit
end
# build a search object
def search(str)
MLibrarySearchParser::Search.new(str, @config)
end
# build a local_params object
def lp(s)
MLibrarySearchParser::Transformer::Solr::LocalParams.new(s)
end
# Make the solr call with the localparams and get the docs
# Override solr parms in kwargs
def get(str, **kwargs)
resp = get_response(str, **kwargs)
resp["response"]["docs"]
end
# In case we need to look at the whole response
def get_response(str, **kwargs)
s = search(str)
params = lp(s).params.merge(@solr_params).merge(kwargs)
@core.get("select", params)
end
puts "Goodbye"