From ee3b391d0c6692b49154775b75af20e014ec7cb9 Mon Sep 17 00:00:00 2001 From: Kouhei Sutou Date: Thu, 22 Dec 2016 14:47:19 +0900 Subject: [PATCH] Support dilldown by tag --- app/controllers/documents_controller.rb | 11 +++++++++-- app/views/documents/index.html.erb | 17 +++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index cb8944a..6f8f00c 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -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 diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb index fe779cb..a5eb335 100644 --- a/app/views/documents/index.html.erb +++ b/app/views/documents/index.html.erb @@ -5,10 +5,21 @@

<%= @result_set.n_hits %> records

<%= form_tag(documents_path, method: "get") do %> + <%= hidden_field_tag "tag", @tag %> <%= search_field_tag "query", @query %> <%= submit_tag "Search" %> <% end %> + + @@ -27,8 +38,10 @@
<%= document.content %>
    - <% document.tags.each do |tag| %> -
  • <%= tag.name %>
  • + <% record.tags.each do |tag| %> +
  • <%= link_to_unless @tag == tag, + tag, + url_for(query: @query, tag: tag) %>
  • <% end %>