Re-namespacing a bit to clear out some fairly old stuff from the top level
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
# Filters added to this controller apply to all controllers in the application.
|
||||
# Likewise, all the methods added will be available for all controllers.
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
helper :all # include all helpers, all the time
|
||||
protect_from_forgery # See ActionController::RequestForgeryProtection for details
|
||||
|
||||
# Scrub sensitive parameters from your log
|
||||
# filter_parameter_logging :password
|
||||
end
|
@@ -0,0 +1,18 @@
|
||||
require 'open-uri'
|
||||
require 'rexml/document'
|
||||
|
||||
|
||||
class SolrController < ApplicationController
|
||||
include SolrHelper
|
||||
|
||||
def simple_query
|
||||
@search = request[:q]
|
||||
@results = []
|
||||
if @search != nil
|
||||
@results = get_results(@search)
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
end
|
||||
end
|
@@ -0,0 +1,3 @@
|
||||
# Methods added to this helper will be available to all templates in the application.
|
||||
module ApplicationHelper
|
||||
end
|
30
oldstuff/RubyFun/rails/hamster/app/helpers/solr_helper.rb
Normal file
30
oldstuff/RubyFun/rails/hamster/app/helpers/solr_helper.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
module SolrHelper
|
||||
$select_url = 'http://localhost:8983/solr/select/'
|
||||
$redis = '/home/me/repos/redis.git/src/redis-cli'
|
||||
|
||||
def get_results(search)
|
||||
cached = `#{$redis} GET "query:#{search}"`
|
||||
|
||||
if cached.strip().length > 0
|
||||
# puts "cached=#{cached}"
|
||||
xml_results = REXML::Document.new cached
|
||||
else
|
||||
raw_results = open("#{$select_url}?q=#{search}").read
|
||||
# puts "caching '#{raw_results}'"
|
||||
`#{$redis} SET "query:#{search}" '#{raw_results}'`
|
||||
|
||||
xml_results = REXML::Document.new raw_results
|
||||
end
|
||||
|
||||
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
|
@@ -0,0 +1 @@
|
||||
<h1>Index</h1>
|
@@ -0,0 +1,16 @@
|
||||
|
||||
<h1>Find Stuff!</h1>
|
||||
|
||||
<form action="" method="get" name="query">
|
||||
<input type="text" name="q" value="<%= @search || "" %>"/>
|
||||
<input type="submit" value="Search" />
|
||||
</form>
|
||||
|
||||
<% if @results.length %>
|
||||
<p>Results for “<%= @search %>”:</p>
|
||||
<ul>
|
||||
<% @results.each do |result| %>
|
||||
<li><strong><%= result[:id] %></strong>: <%= result[:description] %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
Reference in New Issue
Block a user