lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject svn commit: r521989 - in /lucene/solr/trunk/client/ruby/flare: app/controllers/application.rb app/views/browse/index.rhtml vendor/plugins/flare/lib/flare/context.rb vendor/plugins/flare/lib/flare/controller_extensions.rb
Date Sat, 24 Mar 2007 07:40:46 GMT
Author: ehatcher
Date: Sat Mar 24 00:40:44 2007
New Revision: 521989

URL: http://svn.apache.org/viewvc?view=rev&rev=521989
Log:
Move the page number out of session scope into the Context.


Modified:
    lucene/solr/trunk/client/ruby/flare/app/controllers/application.rb
    lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml
    lucene/solr/trunk/client/ruby/flare/vendor/plugins/flare/lib/flare/context.rb
    lucene/solr/trunk/client/ruby/flare/vendor/plugins/flare/lib/flare/controller_extensions.rb

Modified: lucene/solr/trunk/client/ruby/flare/app/controllers/application.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/app/controllers/application.rb?view=diff&rev=521989&r1=521988&r2=521989
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/app/controllers/application.rb (original)
+++ lucene/solr/trunk/client/ruby/flare/app/controllers/application.rb Sat Mar 24 00:40:44
2007
@@ -16,16 +16,4 @@
 class ApplicationController < ActionController::Base
   # Pick a unique cookie name to distinguish our session data from others'
   session :session_key => '_flare_session_id'
-  
-  before_filter :flare_before
-  
-
-private
-  def flare_before
-    session[:page] ||= 1
-  
-    session[:flare_context] ||= Flare::Context.new(SOLR_CONFIG)
-    
-    @flare = session[:flare_context]
-  end
 end

Modified: lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml?view=diff&rev=521989&r1=521988&r2=521989
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml (original)
+++ lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml Sat Mar 24 00:40:44 2007
@@ -102,6 +102,6 @@
 </table>
 </div>
 
-<div class="resultsheader"><%=link_to_if session[:page] != 1,  "<<", :page
=> session[:page] - 1%> Results <strong><%=[@start + 1,@response.total_hits].min%>-<%=[@response.total_hits,@results_per_page
+ @start].min%></strong> of <strong><%=@response.total_hits%></strong><%=link_to_if
session[:page] < (@response.total_hits.to_f / @results_per_page).ceil, ">>", :page
=> session[:page] + 1%></div>
+<div class="resultsheader"><%=link_to_if @flare.page != 1,  "<<", :page =>
@flare.page - 1%> Results <strong><%=[@start + 1,@response.total_hits].min%>-<%=[@response.total_hits,@results_per_page
+ @start].min%></strong> of <strong><%=@response.total_hits%></strong><%=link_to_if
@flare.page < (@response.total_hits.to_f / @results_per_page).ceil, ">>", :page =>
@flare.page + 1%></div>
 
 <% end %>

Modified: lucene/solr/trunk/client/ruby/flare/vendor/plugins/flare/lib/flare/context.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/vendor/plugins/flare/lib/flare/context.rb?view=diff&rev=521989&r1=521988&r2=521989
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/vendor/plugins/flare/lib/flare/context.rb (original)
+++ lucene/solr/trunk/client/ruby/flare/vendor/plugins/flare/lib/flare/context.rb Sat Mar
24 00:40:44 2007
@@ -11,11 +11,12 @@
 # limitations under the License.
 
 class Flare::Context
-  attr_accessor :queries, :filters, :facet_queries, :applied_facet_queries
+  attr_accessor :queries, :filters, :facet_queries, :applied_facet_queries, :page
   attr_reader :facet_fields, :text_fields
 
-  def initialize(solr_config)
+  def initialize(solr_config={})
     @solr_config = solr_config
+    
     @connection = Solr::Connection.new(@solr_config[:solr_url])
 
     clear
@@ -27,12 +28,16 @@
     @facet_fields =  @index_info.field_names.find_all {|v| v =~ /_facet$/} - excluded
 
     @text_fields = @index_info.field_names.find_all {|v| v =~ /_text$/}
+    
+    @page = 1
   end
 
   def clear
+    #TODO unify initialize and clear
     @queries = []
     @filters = []
     @applied_facet_queries = []
+    @page = 1
 
     # this is cleared for development purposes - allowing flare to stay running but different
Solr datasets swapping
     @index_info = @connection.send(Solr::Request::IndexInfo.new)

Modified: lucene/solr/trunk/client/ruby/flare/vendor/plugins/flare/lib/flare/controller_extensions.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/vendor/plugins/flare/lib/flare/controller_extensions.rb?view=diff&rev=521989&r1=521988&r2=521989
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/vendor/plugins/flare/lib/flare/controller_extensions.rb
(original)
+++ lucene/solr/trunk/client/ruby/flare/vendor/plugins/flare/lib/flare/controller_extensions.rb
Sat Mar 24 00:40:44 2007
@@ -20,26 +20,25 @@
     module ClassMethods
       def flare(options={})
         include Flare::ActionControllerExtensions::InstanceMethods
+        before_filter :flare_before
       end
     end
     
     module InstanceMethods
-      
-      # Assumes @flare is set by a before_filter
-      
       def index
-        session[:page] = params[:page].to_i if params[:page]
-        session[:page] = 1 if session[:page] <= 0
-
         @results_per_page = 25
+        
+        if params[:page]
+          @flare.page = params[:page].to_i
+        end
 
-        @start = (session[:page] - 1) * @results_per_page
+        @start = (@flare.page - 1) * @results_per_page
 
         @response = @flare.search(@start, @results_per_page)
       end
 
       def facet
-        puts "---- facet: #{params[:field]}"
+        logger.debug "---- facet: #{params[:field]}"
         @facets = @flare.retrieve_field_facets(params[:field])
       end
 
@@ -53,14 +52,14 @@
 
       def add_query
         @flare.queries << {:query => params[:search][:query]}
-        session[:page] = 1
+        @flare.page = 1
         redirect_to :action => 'index'
       end
 
       def update_query
         logger.debug "update_query: #{params.inspect}"
         @flare.queries[params[:index].to_i][:query] = params[:value]
-        session[:page] = 1
+        @flare.page = 1 # TODO: let the context adjust this automatically when its state
changes
         render :update do |page|
           page.redirect_to '/browse'
         end
@@ -69,32 +68,32 @@
       def invert_query
         q = @flare.queries[params[:index].to_i]
         q[:negative] = !q[:negative]
-        session[:page] = 1
+        @flare.page = 1 # TODO: let the context adjust this automatically when its state
changes
         redirect_to :action => 'index'
       end
 
       def remove_query
         @flare.queries.delete_at(params[:index].to_i)
-        session[:page] = 1
+        @flare.page = 1 # TODO: let the context adjust this automatically when its state
changes
         redirect_to :action => 'index'
       end
 
       def invert_filter
         f = @flare.filters[params[:index].to_i]
         f[:negative] = !f[:negative]
-        session[:page] = 1
+        @flare.page = 1 # TODO: let the context adjust this automatically when its state
changes
         redirect_to :action => 'index'
       end
 
       def remove_filter
         @flare.filters.delete_at(params[:index].to_i)
-        session[:page] = 1
+        @flare.page = 1 # TODO: let the context adjust this automatically when its state
changes
         redirect_to :action => 'index'
       end
 
       def add_filter
         @flare.filters << {:field => params[:field], :value => params[:value],
:negative => (params[:negative] ? true : false)} 
-        session[:page] = 1
+        @flare.page = 1 # TODO: let the context adjust this automatically when its state
changes
         redirect_to :action => 'index'
       end
 
@@ -105,7 +104,7 @@
 
       def remove_saved_constraint
         @flare.applied_facet_queries.delete_at(params[:index].to_i)
-        session[:page] = 1
+        @flare.page = 1 # TODO: let the context adjust this automatically when its state
changes
         redirect_to :action => 'index'
       end
 
@@ -131,16 +130,24 @@
         @flare.facet_queries.delete(params[:name])
         @flare.applied_facet_queries.delete_if {|f| params[:name] == f[:name]}
         puts "---- AFTER", @flare.to_s
-        session[:page] = 1
+        @flare.page = 1 # TODO: let the context adjust this automatically when its state
changes
         redirect_to :action => 'index'
       end
 
       def invert_saved_constraint
         f = @flare.applied_facet_queries[params[:index].to_i]
         f[:negative] = !f[:negative]
-        session[:page] = 1
+        @flare.page = 1 # TODO: let the context adjust this automatically when its state
changes
         redirect_to :action => 'index'
       end
+
+      private
+        def flare_before
+          # TODO: allow source of context to be configurable.
+          session[:flare_context] ||= Flare::Context.new(SOLR_CONFIG)
+
+          @flare = session[:flare_context]
+        end
     end
     
   end



Mime
View raw message