tkh_search 0.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd0571508ddad0d7802c5449bb2a3d5cd1de47b7
4
- data.tar.gz: 53ac20d7f786dbb2a33fd46f4719418a46e19383
3
+ metadata.gz: 1ec2548d73c8962999cf9eb77004b5ab2da38126
4
+ data.tar.gz: 03f8807ddfca834983c47a36e9012777ec1eda0e
5
5
  SHA512:
6
- metadata.gz: 907ec49bdefea212c66e917e4ffdedeff0aa9ef6d7f98f3e9bbd3704497925523135a0c49f347241951befce8028137710fd2e09f96c7407afab8a965202a9b5
7
- data.tar.gz: cb92a62531f43658a032b6810e606eaa6b217bed9c443279fca0f3a354b2e66db5ef38c170e6dc48b26650ed573be6a40e194b9ec170417b172e9f84fd085e45
6
+ metadata.gz: 36f41316f96bf10a0ee22e4f088228665031774f6f624d199178207f924802ad98800d20f13d616d3d41f633d7709b1be4124c48c18bb85b9640ce77c4e6f09f
7
+ data.tar.gz: 7012552fcf9027737a3e89c4b674214ce8e437140a76d40de9da8a9a13bf6be2a759a6e1fb306aa638a264c5eb5ecc5616fa9c9c3f7b18408801126f2a688e99
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.1.5
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
 
4
4
 
5
+ ## 0.2
6
+
7
+ * Added search stats section to readme.
8
+ * Debugged the dangerous attributes created by model_name in two models.
9
+
10
+
5
11
  ## 0.1
6
12
 
7
13
  * Every user search is logged in the database
data/README.md CHANGED
@@ -118,6 +118,11 @@ This can also be used for the sake of localization
118
118
  <%= render 'search/search_form', models_to_search: 'Event', submit_label: 'find an awesome event' %>
119
119
  ```
120
120
 
121
+ ## Search Stats
122
+
123
+ Administrators can see the indexing and searching stats at
124
+
125
+ /search_stats
121
126
 
122
127
  ## Missing Features
123
128
 
@@ -12,10 +12,10 @@ class SearchController < ApplicationController
12
12
  search_terms.each do |search_term|
13
13
  if search_term.tkh_search_instances.any?
14
14
  search_term.tkh_search_instances.each do |search_instance|
15
- if @models_to_search.include? search_instance.model_name
15
+ if @models_to_search.include? search_instance.host_model_name
16
16
  search_result = TkhSearchResult.find_or_create_by(
17
17
  token: token,
18
- model_name: search_instance.model_name,
18
+ host_model_name: search_instance.host_model_name,
19
19
  model_record_id: search_instance.model_record_id)
20
20
  search_result.rating += search_instance.rating
21
21
  search_result.save
@@ -6,7 +6,7 @@ class TkhSearchInstance < ActiveRecord::Base
6
6
  scope :by_top_rating, -> { order('rating desc') }
7
7
 
8
8
  def unique_record_name
9
- "#{model_name}-#{model_record_id}"
9
+ "#{host_model_name}-#{model_record_id}"
10
10
  end
11
11
 
12
12
  end
@@ -1,7 +1,7 @@
1
1
  <ul class="search-results">
2
2
  <% if search_results.any? %>
3
3
  <% search_results.each do |result| %>
4
- <% record = (Kernel.const_get result.model_name).find(result.model_record_id) %>
4
+ <% record = (Kernel.const_get result.host_model_name).find(result.model_record_id) %>
5
5
  <% if defined? record.name %>
6
6
  <% link_label = record.name %>
7
7
  <% elsif defined? record.title %>
@@ -10,7 +10,7 @@
10
10
  <% link_label = 'no title or name' %>
11
11
  <% end %>
12
12
  <%= content_tag :li,
13
- "<span class='sr-model-name'>#{result.model_name}</span> -
13
+ "<span class='sr-model-name'>#{result.host_model_name}</span> -
14
14
  <span class='sr-record-link'>#{link_to link_label, record}</span> -
15
15
  <span class='sr-rating'>#{result.rating}</span>
16
16
  ".html_safe
@@ -22,6 +22,7 @@ module TkhSearch
22
22
  migration_template "create_tkh_search_queries.rb", "db/migrate/create_tkh_search_queries.rb"
23
23
  migration_template "create_tkh_search_events.rb", "db/migrate/create_tkh_search_events.rb"
24
24
  migration_template "create_tkh_search_results.rb", "db/migrate/create_tkh_search_results.rb"
25
+ migration_template "fix_dangerous_attributes.rb", "db/migrate/fix_dangerous_attributes.rb"
25
26
  end
26
27
 
27
28
  end
@@ -0,0 +1,16 @@
1
+ class FixDangerousAttributes < ActiveRecord::Migration
2
+
3
+ # ActiveRecord raises an exception if some model attributes
4
+ # use the same word as some AR methods or attributes.
5
+
6
+ def self.up
7
+ rename_column :tkh_search_instances, :model_name, :host_model_name
8
+ rename_column :tkh_search_results, :model_name, :host_model_name
9
+ end
10
+
11
+ def self.down
12
+ rename_column :tkh_search_instances, :host_model_name, :model_name
13
+ rename_column :tkh_search_results, :host_model_name, :model_name
14
+ end
15
+
16
+ end
@@ -53,7 +53,7 @@ module TkhSearch
53
53
  words.each do |word,strength|
54
54
  term = TkhSearchTerm.find_or_create_by( word: word )
55
55
  instance = TkhSearchInstance.find_or_create_by(
56
- model_name: self.name,
56
+ host_model_name: self.name,
57
57
  model_record_id: record.id,
58
58
  tkh_search_term_id: term.id )
59
59
  instance.rating = strength
@@ -75,7 +75,7 @@ module TkhSearch
75
75
  def remove_obsolete_instances
76
76
  # after an individual record save and the record has been reindexed
77
77
  # we need to remove indexed instances for words which have been deleted
78
- obsolete_instances = TkhSearchInstance.where( 'model_name = ? and model_record_id = ?', self.class.name, self.id ).a_bit_old
78
+ obsolete_instances = TkhSearchInstance.where( 'host_model_name = ? and model_record_id = ?', self.class.name, self.id ).a_bit_old
79
79
  obsolete_instances.each do |instance|
80
80
  instance.destroy!
81
81
  end
@@ -1,3 +1,3 @@
1
1
  module TkhSearch
2
- VERSION = "0.1"
2
+ VERSION = "0.2"
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.1'
4
+ version: '0.2'
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-10-12 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -101,6 +101,7 @@ files:
101
101
  - lib/generators/tkh_search/create_or_update_migrations/templates/create_tkh_search_queries.rb
102
102
  - lib/generators/tkh_search/create_or_update_migrations/templates/create_tkh_search_results.rb
103
103
  - lib/generators/tkh_search/create_or_update_migrations/templates/create_tkh_search_terms.rb
104
+ - lib/generators/tkh_search/create_or_update_migrations/templates/fix_dangerous_attributes.rb
104
105
  - lib/generators/tkh_search/install_initializer/install_initializer_generator.rb
105
106
  - lib/generators/tkh_search/install_initializer/templates/tkh_search.rb
106
107
  - lib/tasks/tkh_search_tasks.rake
@@ -128,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
129
  version: '0'
129
130
  requirements: []
130
131
  rubyforge_project:
131
- rubygems_version: 2.2.2
132
+ rubygems_version: 2.4.4
132
133
  signing_key:
133
134
  specification_version: 4
134
135
  summary: Lightweigh Rails search engine