2011-08-31 12:19:44 +00:00
|
|
|
module SolrHelper
|
2011-08-31 16:11:37 +00:00
|
|
|
$select_url = 'http://localhost:8983/solr/select/'
|
2011-09-06 00:42:39 +00:00
|
|
|
$redis = '/home/me/repos/redis.git/src/redis-cli'
|
2011-08-31 16:11:37 +00:00
|
|
|
|
|
|
|
def get_results(search)
|
2011-09-06 00:42:39 +00:00
|
|
|
cached = `#{$redis} GET "query:#{search}"`
|
|
|
|
|
|
|
|
if cached.strip().length > 0
|
|
|
|
# puts "cached=#{cached}"
|
|
|
|
xml_results = REXML::Document.new cached
|
|
|
|
else
|
2011-08-31 16:11:37 +00:00
|
|
|
raw_results = open("#{$select_url}?q=#{search}").read
|
2011-09-06 00:42:39 +00:00
|
|
|
# puts "caching '#{raw_results}'"
|
|
|
|
`#{$redis} SET "query:#{search}" '#{raw_results}'`
|
|
|
|
|
2011-08-31 16:11:37 +00:00
|
|
|
xml_results = REXML::Document.new raw_results
|
2011-09-06 00:42:39 +00:00
|
|
|
end
|
2011-08-31 16:11:37 +00:00
|
|
|
|
2011-09-06 00:42:39 +00:00
|
|
|
results = []
|
|
|
|
REXML::XPath.each(xml_results, '//result/doc') do |doc|
|
|
|
|
results.push({
|
|
|
|
:id => doc.elements['./str[@name="id"]'],
|
|
|
|
:description => doc.elements['./str[@name="name"]']
|
|
|
|
})
|
|
|
|
end
|
2011-08-31 16:11:37 +00:00
|
|
|
|
2011-09-06 00:42:39 +00:00
|
|
|
return results
|
2011-08-31 16:11:37 +00:00
|
|
|
end
|
|
|
|
|
2011-08-31 12:19:44 +00:00
|
|
|
end
|