several changes, including warts... almost functional in_place_editor, Solr configuration separation, etc

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@508978 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-02-18 20:22:10 +00:00
parent 4c14e8ed6f
commit 2bc67ded17
9 changed files with 80 additions and 32 deletions

View File

@ -8,3 +8,5 @@ require 'rake/testtask'
require 'rake/rdoctask' require 'rake/rdoctask'
require 'tasks/rails' require 'tasks/rails'
require 'solr/solrtasks'

View File

@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
# Pick a unique cookie name to distinguish our session data from others' # Pick a unique cookie name to distinguish our session data from others'
session :session_key => '_flare_session_id' session :session_key => '_flare_session_id'
private
def query def query
queries = session[:queries] queries = session[:queries]
if queries.nil? || queries.empty? if queries.nil? || queries.empty?
@ -21,7 +21,18 @@ class ApplicationController < ActionController::Base
end end
def filters def filters
session[:filters].collect {|filter| "#{filter[:negative] ? '-' : ''}#{filter[:field]}:\"#{filter[:value]}\""} session[:filters].collect do |filter|
value = filter[:value]
if value != "[* TO *]"
value = "\"#{value}\""
end
"#{filter[:negative] ? '-' : ''}#{filter[:field]}:#{value}"
end
end
def solr(request)
logger.info "---\n#{request.inspect}\n---"
SOLR.send(request)
end end
end end

View File

@ -2,17 +2,31 @@
# License:: Apache Version 2.0 (see http://www.apache.org/licenses/) # License:: Apache Version 2.0 (see http://www.apache.org/licenses/)
class BrowseController < ApplicationController class BrowseController < ApplicationController
before_filter :setup_session before_filter :flare_before
# TODO: use in-place-editor for queries, allowing editing of them (instead of remove and re-add new one)
# def self.flare(options={})
# define_method() do
# end
# end
#
# flare do |f|
# f.facet_fields = []
# end
def index def index
@info = SOLR.send(Solr::Request::IndexInfo.new) # TODO move this call to only have it called when the index may have changed
@facet_fields = @info.field_names.find_all {|v| v =~ /_facet$/}
# TODO Add paging and sorting # TODO Add paging and sorting
request = Solr::Request::Standard.new :query => query, @info = solr(Solr::Request::IndexInfo.new) # TODO move this call to only have it called when the index may have changed
@facet_fields = @info.field_names.find_all {|v| v =~ /_facet$/}
@text_fields = @info.field_names.find_all {|v| v =~ /_text$/}
request = Solr::Request::Standard.new(:query => query,
:filter_queries => filters, :filter_queries => filters,
:facets => {:fields => @facet_fields, :limit => 20 , :mincount => 1, :sort => :count, :debug_query=>true} :facets => {:fields => @facet_fields, :limit => 20 , :mincount => 1, :sort => :count, :debug_query=>true},
@response = SOLR.send(request) :highlighting => {:field_list => @text_fields})
logger.info({:query => query, :filter_queries => filters}.inspect)
@response = solr(request)
#TODO: call response.field_facets(??) - maybe field_facets should be return a higher level? #TODO: call response.field_facets(??) - maybe field_facets should be return a higher level?
end end
@ -28,12 +42,17 @@ class BrowseController < ApplicationController
render :partial => 'suggest' render :partial => 'suggest'
end end
def add_query def add_query
session[:queries] << {:query => params[:search][:query]} session[:queries] << {:query => params[:search][:query]}
redirect_to :action => 'index' redirect_to :action => 'index'
end end
def update_query
logger.debug "update_query: #{params.inspect}"
session[:queries][params[:index].to_i][:query] = params[:value]
render :layout => false, :text => params[:value]
end
def invert_query def invert_query
q = session[:queries][params[:index].to_i] q = session[:queries][params[:index].to_i]
q[:negative] = !q[:negative] q[:negative] = !q[:negative]
@ -57,19 +76,19 @@ class BrowseController < ApplicationController
end end
def add_filter def add_filter
session[:filters] << {:field => params[:field_name], :value => params[:value]} session[:filters] << {:field => params[:field_name], :value => params[:value], :negative => (params[:negative] ? true : false)}
redirect_to :action => 'index' redirect_to :action => 'index'
end end
def clear def clear
session[:queries] = nil session[:queries] = nil
session[:filters] = nil session[:filters] = nil
setup_session flare_before
redirect_to :action => 'index' redirect_to :action => 'index'
end end
private private
def setup_session def flare_before
session[:queries] ||= [] session[:queries] ||= []
session[:filters] ||= [] session[:filters] ||= []
end end

View File

@ -16,12 +16,8 @@ class SimileController < ApplicationController
# TODO this code was copied from BrowseController#index, and is here only as a quick and dirty prototype. # TODO this code was copied from BrowseController#index, and is here only as a quick and dirty prototype.
# TODO figuring out where these calls cleanly belong is the key. # TODO figuring out where these calls cleanly belong is the key.
@info = SOLR.send(Solr::Request::IndexInfo.new) # TODO move this call to only have it called when the index may have changed req = Solr::Request::Standard.new :query => query, :filter_queries => filters
@facet_fields = @info.field_names.find_all {|v| v =~ /_facet$/}
req = Solr::Request::Standard.new :query => query,
:filter_queries => filters,
:facets => {:fields => @facet_fields, :limit => 20 , :mincount => 1, :sort => :count, :debug_query=>true}
@data = SOLR.send(req) @data = SOLR.send(req)
# Exhibit seems to require a label attribute to be happy # Exhibit seems to require a label attribute to be happy
@ -38,11 +34,8 @@ class SimileController < ApplicationController
# TODO figuring out where these calls cleanly belong is the key. # TODO figuring out where these calls cleanly belong is the key.
@info = SOLR.send(Solr::Request::IndexInfo.new) # TODO move this call to only have it called when the index may have changed @info = SOLR.send(Solr::Request::IndexInfo.new) # TODO move this call to only have it called when the index may have changed
@facet_fields = @info.field_names.find_all {|v| v =~ /_facet$/} req = Solr::Request::Standard.new :query => query, :filter_queries => filters
req = Solr::Request::Standard.new :query => query,
:filter_queries => filters,
:facets => {:fields => @facet_fields, :limit => 20 , :mincount => 1, :sort => :count, :debug_query=>true}
@data = SOLR.send(req) @data = SOLR.send(req)

View File

@ -1,3 +1,7 @@
<% @facets.each do |f| %> <% @facets.each do |f| %>
<%= link_to (f.name ? f.name : '#### NO VALUE ###'), :action => 'add_filter', :field_name => params[:field_name], :value => f.name %> (<%=f.value%>) <% if f.name %>
<%= link_to f.name, :action => 'add_filter', :field_name => params[:field_name], :value => f.name %> (<%=f.value%>)
<% else %>
<%= link_to '---- NO VALUE ----', :action => 'add_filter', :field_name => params[:field_name], :value => "[* TO *]", :negative => true %> (<%=f.value%>)
<% end %>
<% end%> <% end%>

View File

@ -7,6 +7,7 @@
<% @facet_fields.each do |field|%> <% @facet_fields.each do |field|%>
<h4><%=link_to field, :action => 'facet', :field_name => field%></h4> <h4><%=link_to field, :action => 'facet', :field_name => field%></h4>
<ul> <ul>
<% @response.field_facets(field).each do |f| %> <% @response.field_facets(field).each do |f| %>
<li> <li>
@ -22,7 +23,10 @@
<div> <div>
Queries: Queries:
<% session[:queries].each_with_index do |q,i| %> <% session[:queries].each_with_index do |q,i| %>
<%=link_to q[:negative] ? "-" : '+', :action => :invert_query, :index => i%> <%=q[:query]%> <%=link_to image_tag("x-close.gif"), :action => :remove_query, :index => i %> <%=link_to q[:negative] ? "-" : '+', :action => :invert_query, :index => i%>
<span id="query_<%=i%>"><%=q[:query]%></span>
<%= in_place_editor "query_#{i}", :url=> url_for(:action=>"update_query", :index=>i) %>
<%=link_to image_tag("x-close.gif"), :action => :remove_query, :index => i %>
<% end %> <% end %>
</div> </div>
<div> <div>
@ -39,12 +43,15 @@ Filters:
<div id="results"><table cellpadding="10"> <div id="results"><table cellpadding="10">
<% display_fields = [:title, :author, :pages, :rating]; @response.each do |doc| %> <% @response.each do |doc| %>
<tr valign="top"> <tr valign="top">
<td> <td>
<table> <table>
<% display_fields.each do |f|%> <tr colspan="2">
<tr><th><%=f.to_s%></th><td><%=doc["#{f.to_s}_text"] %><%=doc["#{f.to_s}_facet"] %></td></tr> <th><%=doc['title_text']%></th>
</tr>
<% doc.each do |k,v|; highlighting = @response.highlighted(doc['id'], k) %>
<tr><td><%=k%>:</td><td><%= highlighting ? "...#{highlighting}..." : v%></td></tr>
<% end %> <% end %>
</table> </table>
</td> </td>

View File

@ -19,7 +19,7 @@ xml.data do
:image => "#{doc['asin_text']}") :image => "#{doc['asin_text']}")
end end
end end
# Amazon images: http://www.betaversion.org/~stefano/linotype/news/66/
# <data> # <data>
# <event # <event
# start="May 28 2006 09:00:00 GMT" # start="May 28 2006 09:00:00 GMT"

View File

@ -57,4 +57,8 @@ end
# $KCODE = 'UTF8' # Rails 1.2 supposedly sets this automatically # $KCODE = 'UTF8' # Rails 1.2 supposedly sets this automatically
require 'solr' require 'solr'
SOLR = Solr::Connection.new("http://localhost:8983/solr") solr_environments = YAML.load_file("#{RAILS_ROOT}/config/solr.yml")
SOLR_ENV = ENV["SOLR_ENV"] || "development"
SOLR_CONFIG = solr_environments[SOLR_ENV]
puts "SOLR_CONFIG = #{SOLR_CONFIG.to_yaml}"
SOLR = Solr::Connection.new("#{SOLR_CONFIG['solr_url']}")

View File

@ -0,0 +1,8 @@
development:
solr_url: http://localhost:8983/solr
delicious:
solr_url: http://localhost:8985/solr
tang:
solr_url: http://localhost:8987/solr