You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by eh...@apache.org on 2007/02/07 21:57:32 UTC

svn commit: r504689 - in /lucene/solr/trunk/client/ruby/flare: app/controllers/browse_controller.rb app/controllers/sparklines_controller.rb app/views/browse/facet.rhtml app/views/browse/index.rhtml lib/tasks/routes.rake

Author: ehatcher
Date: Wed Feb  7 12:57:32 2007
New Revision: 504689

URL: http://svn.apache.org/viewvc?view=rev&rev=504689
Log:
handy rake addition to list routes

Added:
    lucene/solr/trunk/client/ruby/flare/app/controllers/sparklines_controller.rb
    lucene/solr/trunk/client/ruby/flare/lib/tasks/routes.rake   (with props)
Modified:
    lucene/solr/trunk/client/ruby/flare/app/controllers/browse_controller.rb
    lucene/solr/trunk/client/ruby/flare/app/views/browse/facet.rhtml
    lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml

Modified: lucene/solr/trunk/client/ruby/flare/app/controllers/browse_controller.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/app/controllers/browse_controller.rb?view=diff&rev=504689&r1=504688&r2=504689
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/app/controllers/browse_controller.rb (original)
+++ lucene/solr/trunk/client/ruby/flare/app/controllers/browse_controller.rb Wed Feb  7 12:57:32 2007
@@ -78,7 +78,7 @@
     req = Solr::Request::Standard.new(:query => query,
        :filter_queries => filters,
        :facets => {:fields => [field],
-                   :mincount => 1, :limit => limit, :prefix => prefix
+                   :mincount => 1, :limit => limit, :prefix => prefix, :missing => true, :sort => :count
                   },
        :rows => 0
     )

Added: lucene/solr/trunk/client/ruby/flare/app/controllers/sparklines_controller.rb
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/app/controllers/sparklines_controller.rb?view=auto&rev=504689
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/app/controllers/sparklines_controller.rb (added)
+++ lucene/solr/trunk/client/ruby/flare/app/controllers/sparklines_controller.rb Wed Feb  7 12:57:32 2007
@@ -0,0 +1,40 @@
+class SparklinesController < ApplicationController
+
+  # Handles requests for sparkline graphs from views.
+  #
+  # Params are generated by the sparkline_tag helper method.
+  #
+	def index
+		# Make array from comma-delimited list of data values
+		ary = []
+		if params.has_key?('results') && !params['results'].nil?
+		  params['results'].split(',').each do |s|
+			  ary << s.to_i
+		  end
+		end
+		
+		send_data( Sparklines.plot( ary, params ), 
+					:disposition => 'inline',
+					:type => 'image/png',
+					:filename => "spark_#{params[:type]}.png" )
+	end
+
+
+  # Use this type of method for sparklines that can be cached. (Doesn't work with the helper.)
+  #
+  # To make caching easier, add a line like this to config/routes.rb:
+  # map.sparklines "sparklines/:action/:id/image.png", :controller => "sparklines"
+  #
+  # Then reference it with the named route:
+  #   image_tag sparklines_url(:action => 'show', :id => 42)
+  def show
+    send_data(Sparklines.plot(
+                [42, 37, 89, 74, 70, 50, 40, 30, 40, 50],
+                :type => 'bar', :above_color => 'orange'
+              ), 
+              :disposition => 'inline', 
+              :type => 'image/png', 
+              :filename => "sparkline.png")
+  end
+
+end

Modified: lucene/solr/trunk/client/ruby/flare/app/views/browse/facet.rhtml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/app/views/browse/facet.rhtml?view=diff&rev=504689&r1=504688&r2=504689
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/app/views/browse/facet.rhtml (original)
+++ lucene/solr/trunk/client/ruby/flare/app/views/browse/facet.rhtml Wed Feb  7 12:57:32 2007
@@ -1,3 +1,3 @@
-<% @facets.each do |value,count| %>
-  <%= link_to value, :action => 'add_filter', :field_name => params[:field_name], :value => value %> (<%=count%>)
+<% @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%>)
 <% 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=504689&r1=504688&r2=504689
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml (original)
+++ lucene/solr/trunk/client/ruby/flare/app/views/browse/index.rhtml Wed Feb  7 12:57:32 2007
@@ -8,13 +8,16 @@
 <% @facet_fields.each do |field|%>
   <h4><%=link_to field, :action => 'facet', :field_name => field%></h4>
   <ul>
-  <% @response.field_facets(field).each do |k,v| %>
-    <li><%= link_to "#{k} (#{v})", :action => 'add_filter', :field_name=>field, :value=>k%></li>
+  <% @response.field_facets(field).each do |f| %>
+    <li>
+      <%= sparkline_tag [(f.value * 100.0 / @response.total_hits).ceil], :type => 'pie', :diameter => 20, :share_color => 'blue'%>
+      <%= link_to "#{f.name} (#{f.value})", :action => 'add_filter', :field_name=>field, :value=>f.name%>
+    </li>
   <% end %>
   </ul>
 <% end %>
-</div>
-</div>
+<%=link_to image_tag("simile-exhibit.png"), :controller => :simile, :action => :exhibit %>
+</div></div>
 
 <div>
 Queries:
@@ -49,6 +52,7 @@
   <% end %>
 </table>
 </div>
+
 
 
 

Added: lucene/solr/trunk/client/ruby/flare/lib/tasks/routes.rake
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/ruby/flare/lib/tasks/routes.rake?view=auto&rev=504689
==============================================================================
--- lucene/solr/trunk/client/ruby/flare/lib/tasks/routes.rake (added)
+++ lucene/solr/trunk/client/ruby/flare/lib/tasks/routes.rake Wed Feb  7 12:57:32 2007
@@ -0,0 +1,22 @@
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Borrowed from <http://pastie.caboo.se/23100>, by Josh Susser
+desc "Print out all the currently defined routes, with names."
+task :routes => :environment do
+  name_col_width = ActionController::Routing::Routes.named_routes.routes.keys.sort {|a,b| a.to_s.size <=> b.to_s.size}.last.to_s.size
+  ActionController::Routing::Routes.routes.each do |route|
+    name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s
+    name = name.ljust(name_col_width + 1)
+    puts "#{name}#{route}"
+  end
+end
\ No newline at end of file

Propchange: lucene/solr/trunk/client/ruby/flare/lib/tasks/routes.rake
------------------------------------------------------------------------------
    svn:executable = *