pulling stuff out of xml for display
This commit is contained in:
parent
4407d92899
commit
d819d87268
@ -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
|
||||
|
||||
|
@ -5,7 +5,11 @@
|
||||
<input type="submit" value="Search" />
|
||||
</form>
|
||||
|
||||
<% if @results %>
|
||||
<% if @results.length %>
|
||||
<p>Results for “<%= @search %>”:</p>
|
||||
<pre><%= h(@results) %></pre>
|
||||
<ul>
|
||||
<% @results.each do |result| %>
|
||||
<li><strong><%= result[:id] %></strong>: <%= result[:description] %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
Loading…
Reference in New Issue
Block a user