moving the solr-accessing stuff into helper module, which probably isn't the right place but it's better than having it in the controller, right?
This commit is contained in:
parent
d819d87268
commit
b47a145ef6
@ -3,22 +3,13 @@ require 'rexml/document'
|
||||
|
||||
|
||||
class SolrController < ApplicationController
|
||||
$select_url = 'http://localhost:8983/solr/select/'
|
||||
include SolrHelper
|
||||
|
||||
def index
|
||||
@search = request[:q]
|
||||
@results = []
|
||||
if @search != nil
|
||||
raw_results = open("#{$select_url}?q=#{@search}&indent=on").read
|
||||
xml_results = REXML::Document.new raw_results
|
||||
|
||||
@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
|
||||
|
||||
@results = get_results(@search)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,2 +1,19 @@
|
||||
module SolrHelper
|
||||
$select_url = 'http://localhost:8983/solr/select/'
|
||||
|
||||
def get_results(search)
|
||||
raw_results = open("#{$select_url}?q=#{search}").read
|
||||
xml_results = REXML::Document.new raw_results
|
||||
|
||||
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
|
||||
|
||||
return results
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user