Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

drilldown versions in search result page.

  • Loading branch information...
commit f6b74c9528da02982964a174abee4e4b6748dca7 1 parent b83d494
@kou kou authored
Showing with 25 additions and 11 deletions.
  1. +22 −9 lib/rurema_search/groonga_searcher.rb
  2. +3 −2 views/search.html.erb
View
31 lib/rurema_search/groonga_searcher.rb
@@ -150,8 +150,9 @@ def a(label, href, attributes={})
tag("a", attributes.merge(:href => href), label)
end
- def link_version_select(select_version)
+ def link_version_select(select_version, options={})
label = h(select_version == :all ? "すべて" : select_version)
+ label << options[:label_suffix] if options[:label_suffix]
if (version == select_version) or
(version.nil? and select_version == :all)
tag("span", {:class => "version-select-text"}, label)
@@ -771,13 +772,20 @@ def process
def process_query
start = Time.now.to_f
_, *parameters = @request.path_info.split(/\//)
- conditions = parse_parameters(parameters)
+ parse_parameters(parameters)
entries = @database.entries
- result = entries.select do |record|
- conditions.collect do |condition|
+ result_without_version_condition = entries.select do |record|
+ create_conditions_without_version.collect do |condition|
condition.call(record)
end.flatten
end
+ if @version_condition
+ result = result_without_version_condition.select do |record|
+ @version_condition.call(record)
+ end
+ else
+ result = result_without_version_condition
+ end
@expression = result.expression
@drilldown_items = drilldown_items(result)
@entries = result.paginate([["_score", :descending],
@@ -786,10 +794,13 @@ def process_query
:size => n_entries_per_page)
@grouped_entries = group_entries(@entries)
@leading_grouped_entries = @grouped_entries[0, 5]
- @versions = @database.versions.sort(["_key"], :limit => -1)
+ @versions = result_without_version_condition.group("version")
+ @versions = @versions.sort(["_key"], :limit => -1)
@version_names = [:all]
+ @version_n_entries = [result_without_version_condition.size]
@versions.each do |version|
@version_names << version["_key"]
+ @version_n_entries << version.n_sub_records
end
prepare_corrections
prepare_suggestions
@@ -812,6 +823,7 @@ def parse_parameters(parameters)
@parameters = {}
@ordered_parameters = []
@instance_method = nil
+ @have_version_condition = false
parameters.each do |parameter|
parameter = parameter.force_encoding("UTF-8")
key, value = parameter.split(/:/, 2)
@@ -824,7 +836,6 @@ def parse_parameters(parameters)
next unless parse_parameter(key, unescaped_value)
@ordered_parameters << [key, unescaped_value]
end
- create_conditions
end
def parse_parameter(key, value)
@@ -894,8 +905,9 @@ def have_scope_parameter?
@parameters["library"]
end
- def create_conditions
+ def create_conditions_without_version
conditions = []
+ @version_condition = nil
@parameters.each do |key, value|
case key
when "query"
@@ -905,8 +917,9 @@ def create_conditions
conditions << equal_condition("type", key)
conditions << equal_condition("name._key", value)
when "version"
- conditions << Proc.new do |record|
- record.version =~ value
+ # don't register version condition.
+ @version_condition = Proc.new do |record|
+ record.version == value
end
when "library"
conditions << Proc.new do |record|
View
5 views/search.html.erb
@@ -1,9 +1,10 @@
<div class="search-header">
<div class="version-select">
<ul>
- <% @version_names.each do |_version| %>
+ <% @version_names.each_with_index do |_version, i| %>
<li class="version-select<%= version == _version ? '-current' : '' %>">
- <%= link_version_select(_version) %>
+ <%= link_version_select(_version,
+ :label_suffix => h("(#{@version_n_entries[i]})")) %>
</li>
<% end %>
</ul>
Please sign in to comment.
Something went wrong with that request. Please try again.