mirror of https://github.com/apache/lucene.git
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:
parent
4c14e8ed6f
commit
2bc67ded17
|
@ -8,3 +8,5 @@ require 'rake/testtask'
|
|||
require 'rake/rdoctask'
|
||||
|
||||
require 'tasks/rails'
|
||||
|
||||
require 'solr/solrtasks'
|
|
@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
|
|||
# Pick a unique cookie name to distinguish our session data from others'
|
||||
session :session_key => '_flare_session_id'
|
||||
|
||||
|
||||
private
|
||||
def query
|
||||
queries = session[:queries]
|
||||
if queries.nil? || queries.empty?
|
||||
|
@ -21,7 +21,18 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
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
|
||||
|
|
|
@ -2,17 +2,31 @@
|
|||
# License:: Apache Version 2.0 (see http://www.apache.org/licenses/)
|
||||
|
||||
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
|
||||
@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
|
||||
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,
|
||||
:facets => {:fields => @facet_fields, :limit => 20 , :mincount => 1, :sort => :count, :debug_query=>true}
|
||||
@response = SOLR.send(request)
|
||||
:facets => {:fields => @facet_fields, :limit => 20 , :mincount => 1, :sort => :count, :debug_query=>true},
|
||||
: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?
|
||||
end
|
||||
|
@ -28,12 +42,17 @@ class BrowseController < ApplicationController
|
|||
render :partial => 'suggest'
|
||||
end
|
||||
|
||||
|
||||
def add_query
|
||||
session[:queries] << {:query => params[:search][:query]}
|
||||
redirect_to :action => 'index'
|
||||
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
|
||||
q = session[:queries][params[:index].to_i]
|
||||
q[:negative] = !q[:negative]
|
||||
|
@ -57,19 +76,19 @@ class BrowseController < ApplicationController
|
|||
end
|
||||
|
||||
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'
|
||||
end
|
||||
|
||||
def clear
|
||||
session[:queries] = nil
|
||||
session[:filters] = nil
|
||||
setup_session
|
||||
flare_before
|
||||
redirect_to :action => 'index'
|
||||
end
|
||||
|
||||
private
|
||||
def setup_session
|
||||
def flare_before
|
||||
session[:queries] ||= []
|
||||
session[:filters] ||= []
|
||||
end
|
||||
|
|
|
@ -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 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
|
||||
@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}
|
||||
req = Solr::Request::Standard.new :query => query, :filter_queries => filters
|
||||
|
||||
@data = SOLR.send(req)
|
||||
|
||||
# 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.
|
||||
|
||||
@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,
|
||||
:facets => {:fields => @facet_fields, :limit => 20 , :mincount => 1, :sort => :count, :debug_query=>true}
|
||||
req = Solr::Request::Standard.new :query => query, :filter_queries => filters
|
||||
|
||||
@data = SOLR.send(req)
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
<% @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%>
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
<% @facet_fields.each do |field|%>
|
||||
<h4><%=link_to field, :action => 'facet', :field_name => field%></h4>
|
||||
|
||||
<ul>
|
||||
<% @response.field_facets(field).each do |f| %>
|
||||
<li>
|
||||
|
@ -22,7 +23,10 @@
|
|||
<div>
|
||||
Queries:
|
||||
<% 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 %>
|
||||
</div>
|
||||
<div>
|
||||
|
@ -39,12 +43,15 @@ Filters:
|
|||
|
||||
|
||||
<div id="results"><table cellpadding="10">
|
||||
<% display_fields = [:title, :author, :pages, :rating]; @response.each do |doc| %>
|
||||
<% @response.each do |doc| %>
|
||||
<tr valign="top">
|
||||
<td>
|
||||
<table>
|
||||
<% display_fields.each do |f|%>
|
||||
<tr><th><%=f.to_s%></th><td><%=doc["#{f.to_s}_text"] %><%=doc["#{f.to_s}_facet"] %></td></tr>
|
||||
<tr colspan="2">
|
||||
<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 %>
|
||||
</table>
|
||||
</td>
|
||||
|
|
|
@ -19,7 +19,7 @@ xml.data do
|
|||
:image => "#{doc['asin_text']}")
|
||||
end
|
||||
end
|
||||
|
||||
# Amazon images: http://www.betaversion.org/~stefano/linotype/news/66/
|
||||
# <data>
|
||||
# <event
|
||||
# start="May 28 2006 09:00:00 GMT"
|
||||
|
|
|
@ -57,4 +57,8 @@ end
|
|||
# $KCODE = 'UTF8' # Rails 1.2 supposedly sets this automatically
|
||||
|
||||
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']}")
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue