Skip to content

Commit

Permalink
Support dilldown by tag
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Dec 22, 2016
1 parent 3021950 commit ee3b391
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 9 additions & 2 deletions app/controllers/documents_controller.rb
Expand Up @@ -5,9 +5,16 @@ class DocumentsController < ApplicationController
# GET /documents.json
def index
@query = params[:query]
@tag = params[:tag]

searcher = DocumentsSearcher.new
@result_set = searcher.search.
query(@query).
request = searcher.search.query(@query)
if @tag.present?
request = request.filter("tags @ %{tag}", tag: @tag)
end
@result_set = request.
drilldowns("tag").keys("tags").
drilldowns("tag").sort_keys("-_nsubrecs").
result_set
end

Expand Down
17 changes: 15 additions & 2 deletions app/views/documents/index.html.erb
Expand Up @@ -5,10 +5,21 @@
<p><%= @result_set.n_hits %> records</p>

<%= form_tag(documents_path, method: "get") do %>
<%= hidden_field_tag "tag", @tag %>
<%= search_field_tag "query", @query %>
<%= submit_tag "Search" %>
<% end %>

<nav>
<% @result_set.drilldowns["tag"].records.each do |record| %>
<%= link_to_unless @tag == record._key,
"#{record._key} (#{record._nsubrecs})",
url_for(query: @query, tag: record._key) %>
<% end %>
<%= link_to "タグ絞り込み解除",
url_for(query: @query) %>
</nav>

<table>
<thead>
<tr>
Expand All @@ -27,8 +38,10 @@
<td><%= document.content %></td>
<td>
<ul>
<% document.tags.each do |tag| %>
<li><%= tag.name %></li>
<% record.tags.each do |tag| %>
<li><%= link_to_unless @tag == tag,
tag,
url_for(query: @query, tag: tag) %></li>
<% end %>
</ul>
</td>
Expand Down

0 comments on commit ee3b391

Please sign in to comment.