From d819d872686dfdc99f7d5435d3f942787d82e74a Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 31 Aug 2011 11:55:10 -0400 Subject: [PATCH] pulling stuff out of xml for display --- rails/hamster/app/controllers/solr_controller.rb | 13 ++++++++++++- rails/hamster/app/views/solr/index.html.erb | 8 ++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) 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 %>