From 2bc67ded17e71548f30792bde257f100d28addbb Mon Sep 17 00:00:00 2001 From: Erik Hatcher Date: Sun, 18 Feb 2007 20:22:10 +0000 Subject: [PATCH] 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 --- client/ruby/flare/Rakefile | 2 + .../ruby/flare/app/controllers/application.rb | 15 ++++++- .../app/controllers/browse_controller.rb | 43 +++++++++++++------ .../app/controllers/simile_controller.rb | 15 ++----- .../ruby/flare/app/views/browse/facet.rhtml | 6 ++- .../ruby/flare/app/views/browse/index.rhtml | 15 +++++-- .../ruby/flare/app/views/simile/timeline.rxml | 2 +- client/ruby/flare/config/environment.rb | 6 ++- client/ruby/flare/config/solr.yml | 8 ++++ 9 files changed, 80 insertions(+), 32 deletions(-) create mode 100755 client/ruby/flare/config/solr.yml diff --git a/client/ruby/flare/Rakefile b/client/ruby/flare/Rakefile index 3bb0e8592a4..ecb7ea3eebd 100644 --- a/client/ruby/flare/Rakefile +++ b/client/ruby/flare/Rakefile @@ -8,3 +8,5 @@ require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails' + +require 'solr/solrtasks' \ No newline at end of file diff --git a/client/ruby/flare/app/controllers/application.rb b/client/ruby/flare/app/controllers/application.rb index 540338459a9..861ddc67355 100644 --- a/client/ruby/flare/app/controllers/application.rb +++ b/client/ruby/flare/app/controllers/application.rb @@ -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 diff --git a/client/ruby/flare/app/controllers/browse_controller.rb b/client/ruby/flare/app/controllers/browse_controller.rb index ab8c14d17c0..98a01dd0922 100644 --- a/client/ruby/flare/app/controllers/browse_controller.rb +++ b/client/ruby/flare/app/controllers/browse_controller.rb @@ -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 diff --git a/client/ruby/flare/app/controllers/simile_controller.rb b/client/ruby/flare/app/controllers/simile_controller.rb index 834f30a7867..be5aa47d1f6 100755 --- a/client/ruby/flare/app/controllers/simile_controller.rb +++ b/client/ruby/flare/app/controllers/simile_controller.rb @@ -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) diff --git a/client/ruby/flare/app/views/browse/facet.rhtml b/client/ruby/flare/app/views/browse/facet.rhtml index 16b53579aee..29979a0737b 100755 --- a/client/ruby/flare/app/views/browse/facet.rhtml +++ b/client/ruby/flare/app/views/browse/facet.rhtml @@ -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%> \ No newline at end of file diff --git a/client/ruby/flare/app/views/browse/index.rhtml b/client/ruby/flare/app/views/browse/index.rhtml index ac7a76f0bed..0fb08a1d534 100644 --- a/client/ruby/flare/app/views/browse/index.rhtml +++ b/client/ruby/flare/app/views/browse/index.rhtml @@ -7,6 +7,7 @@ <% @facet_fields.each do |field|%>

<%=link_to field, :action => 'facet', :field_name => field%>

+