handy rake addition to list routes

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@504689 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-02-07 20:57:32 +00:00
parent a3775daf45
commit cb0cb9359e
5 changed files with 73 additions and 7 deletions

View File

@ -78,7 +78,7 @@ class BrowseController < ApplicationController
req = Solr::Request::Standard.new(:query => query, req = Solr::Request::Standard.new(:query => query,
:filter_queries => filters, :filter_queries => filters,
:facets => {:fields => [field], :facets => {:fields => [field],
:mincount => 1, :limit => limit, :prefix => prefix :mincount => 1, :limit => limit, :prefix => prefix, :missing => true, :sort => :count
}, },
:rows => 0 :rows => 0
) )

View File

@ -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

View File

@ -1,3 +1,3 @@
<% @facets.each do |value,count| %> <% @facets.each do |f| %>
<%= link_to value, :action => 'add_filter', :field_name => params[:field_name], :value => value %> (<%=count%>) <%= link_to (f.name ? f.name : '#### NO VALUE ###'), :action => 'add_filter', :field_name => params[:field_name], :value => f.name %> (<%=f.value%>)
<% end%> <% end%>

View File

@ -8,13 +8,16 @@
<% @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 |k,v| %> <% @response.field_facets(field).each do |f| %>
<li><%= link_to "#{k} (#{v})", :action => 'add_filter', :field_name=>field, :value=>k%></li> <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 %> <% end %>
</ul> </ul>
<% end %> <% end %>
</div> <%=link_to image_tag("simile-exhibit.png"), :controller => :simile, :action => :exhibit %>
</div> </div></div>
<div> <div>
Queries: Queries:
@ -52,6 +55,7 @@ Filters:
<!-- <h3>index info</h3><%=debug @info %> <!-- <h3>index info</h3><%=debug @info %>
<h3>search/facet response header</h3><%=debug @response.data['responseHeader']%> --> <h3>search/facet response header</h3><%=debug @response.data['responseHeader']%> -->

View File

@ -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