diff --git a/rails/hamster/app/controllers/solr_controller.rb b/rails/hamster/app/controllers/solr_controller.rb index 080e2f4..b4a6e5d 100644 --- a/rails/hamster/app/controllers/solr_controller.rb +++ b/rails/hamster/app/controllers/solr_controller.rb @@ -1,4 +1,5 @@ require 'open-uri' +require 'rexml/document' class SolrController < ApplicationController @@ -7,7 +8,17 @@ class SolrController < ApplicationController def index @search = request[:q] if @search != nil - @results = open("#{$select_url}?q=#{@search}&indent=on").read + 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 + end end diff --git a/rails/hamster/app/views/solr/index.html.erb b/rails/hamster/app/views/solr/index.html.erb index b3454e8..d47c07e 100644 --- a/rails/hamster/app/views/solr/index.html.erb +++ b/rails/hamster/app/views/solr/index.html.erb @@ -5,7 +5,11 @@ -<% if @results %> +<% if @results.length %>

Results for “<%= @search %>”:

-
<%= h(@results) %>
+ <% end %>