tkh_search 0.0.4 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1deb55bf8a91af5e08c0bb939f313e295d1548c2
4
- data.tar.gz: f12f386984a887d153a7eb37a7a348f32341af0e
3
+ metadata.gz: bd0571508ddad0d7802c5449bb2a3d5cd1de47b7
4
+ data.tar.gz: 53ac20d7f786dbb2a33fd46f4719418a46e19383
5
5
  SHA512:
6
- metadata.gz: d06d3a2b1a57eb073e9065f41fa72e477cf5815fcf8b714d13137a9bd7b9933f18feeeb3262f1118c68527b978847b673d3b251a7d01d304ff896695edb8d285
7
- data.tar.gz: 577a670348ddab422cac8965e051aaec21629cc142e95e202dbaeb5977e151092433f070bb3ff4a64be4730bb01f79f7358976a3fb9bb76c8d0f1920cf0b4487
6
+ metadata.gz: 907ec49bdefea212c66e917e4ffdedeff0aa9ef6d7f98f3e9bbd3704497925523135a0c49f347241951befce8028137710fd2e09f96c7407afab8a965202a9b5
7
+ data.tar.gz: cb92a62531f43658a032b6810e606eaa6b217bed9c443279fca0f3a354b2e66db5ef38c170e6dc48b26650ed573be6a40e194b9ec170417b172e9f84fd085e45
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
 
4
4
 
5
+ ## 0.1
6
+
7
+ * Every user search is logged in the database
8
+ * Log stats availabble to admins
9
+
10
+
5
11
  ## 0.0.4
6
12
 
7
13
  * Fixed bug when search with multiple word query was crashing when one word had no instances.
@@ -1,7 +1,7 @@
1
1
  class SearchController < ApplicationController
2
2
 
3
3
  def index
4
- @query = params[:query].downcase
4
+ @query = params[:query].downcase.strip
5
5
  @models_to_search = params[:models_to_search].split
6
6
  @results_css_class = params[:results_css_class] || 'js-search-results'
7
7
  token = SecureRandom.base64
@@ -28,6 +28,7 @@ class SearchController < ApplicationController
28
28
  format.html {}
29
29
  format.js {}
30
30
  end
31
+ log_search_event
31
32
  end
32
33
 
33
34
  def index_all_models
@@ -38,4 +39,15 @@ class SearchController < ApplicationController
38
39
  redirect_to root_path, notice: "All searchable models have been indexed."
39
40
  end
40
41
 
42
+ private
43
+
44
+ def log_search_event
45
+ if @query.present?
46
+ search_query = TkhSearchQuery.find_or_create_by( string: @query)
47
+ search_event = TkhSearchEvent.create(
48
+ tkh_search_query_id: search_query.id,
49
+ language: I18n.locale )
50
+ end
51
+ end
52
+
41
53
  end
@@ -0,0 +1,10 @@
1
+ class SearchStatsController < ApplicationController
2
+
3
+ before_filter :authenticate
4
+ before_filter :authenticate_with_admin
5
+
6
+ def index
7
+ switch_to_admin_layout
8
+ end
9
+
10
+ end
@@ -2,4 +2,7 @@ class TkhSearchEvent < ActiveRecord::Base
2
2
 
3
3
  belongs_to :tkh_search_query
4
4
 
5
+ scope :last_24_hours, -> { where("created_at >= ?", Time.zone.now - 24.hours ) }
6
+ scope :last_month, -> { where("created_at >= ?", Time.zone.now - 1.month ) }
7
+
5
8
  end
@@ -0,0 +1,35 @@
1
+ <h1>search statistics</h1>
2
+
3
+ <h3>The index ...</h3>
4
+
5
+ <p>... has <strong><%= TkhSearchTerm.count %></strong> different search terms pointing to <strong><%= TkhSearchInstance.count %></strong> instances.</p>
6
+
7
+ <h3>Total User Searches</h3>
8
+
9
+ <table class='table table-striped'>
10
+ <thead>
11
+ <tr>
12
+ <th>last 24 hours</th>
13
+ <th>last month</th>
14
+ <th>ever</th>
15
+ </tr>
16
+ </thead>
17
+
18
+ <tbody>
19
+ <tr>
20
+ <td><%= TkhSearchEvent.last_24_hours.count %></td>
21
+ <td><%= TkhSearchEvent.last_month.count %></td>
22
+ <td><%= TkhSearchEvent.count %></td>
23
+ </tr>
24
+ </tbody>
25
+ </table>
26
+
27
+ <h3>Most Popular Queries in the Last Month</h3>
28
+
29
+ <ul>
30
+ <% TkhSearchEvent.last_month.group(:tkh_search_query_id).order('COUNT(tkh_search_query_id) desc').limit(50).each do |event| %>
31
+ <li><%= "#{event.tkh_search_query.string} #{TkhSearchEvent.last_month.where(tkh_search_query_id: event.tkh_search_query_id).count}" %></li>
32
+ <% end %>
33
+ </ul>
34
+
35
+ <%= render 'shared/admin_sidebar' %>
data/config/routes.rb CHANGED
@@ -2,5 +2,6 @@ Rails.application.routes.draw do
2
2
  scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
3
3
  post 'search' => 'search#index'
4
4
  get 'index_all_models' => 'search#index_all_models'
5
+ get 'search_stats' => 'search_stats#index'
5
6
  end
6
7
  end
@@ -1,3 +1,3 @@
1
1
  module TkhSearch
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tkh_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: '0.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Swami Atma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-28 00:00:00.000000000 Z
11
+ date: 2014-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -82,6 +82,7 @@ files:
82
82
  - README.md
83
83
  - Rakefile
84
84
  - app/controllers/search_controller.rb
85
+ - app/controllers/search_stats_controller.rb
85
86
  - app/models/tkh_search_event.rb
86
87
  - app/models/tkh_search_instance.rb
87
88
  - app/models/tkh_search_query.rb
@@ -92,6 +93,7 @@ files:
92
93
  - app/views/search/_search_results.html.erb
93
94
  - app/views/search/index.html.erb
94
95
  - app/views/search/index.js.erb
96
+ - app/views/search_stats/index.html.erb
95
97
  - config/routes.rb
96
98
  - lib/generators/tkh_search/create_or_update_migrations/create_or_update_migrations_generator.rb
97
99
  - lib/generators/tkh_search/create_or_update_migrations/templates/create_tkh_search_events.rb