pulling stuff out of xml for display

This commit is contained in:
Dan Buch 2011-08-31 11:55:10 -04:00
parent 4407d92899
commit d819d87268
2 changed files with 18 additions and 3 deletions

View File

@ -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

View File

@ -5,7 +5,11 @@
<input type="submit" value="Search" />
</form>
<% if @results %>
<% if @results.length %>
<p>Results for &ldquo;<%= @search %>&rdquo;:</p>
<pre><%= h(@results) %></pre>
<ul>
<% @results.each do |result| %>
<li><strong><%= result[:id] %></strong>: <%= result[:description] %></li>
<% end %>
</ul>
<% end %>