tkh_search 0.0.2 → 0.0.3

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: a9c13ad8f8bddb6d3311a81e0683b7099da3266b
4
- data.tar.gz: e62e6ff23763187aab3bcf9c541a83cb3be30e04
3
+ metadata.gz: f841b1c6de3922288a8b195e26bdf5eae7ff36a1
4
+ data.tar.gz: f6c22d243a74e9ce7d2a9c73f3770e094bd7fa91
5
5
  SHA512:
6
- metadata.gz: e89dfc96b69c2073d471b6dcfe577bf13b105dd33ad5b4bbc1cd5a22585a55eb884f7825b854fa018dd20f8abf62e47eaf2dabdc924b14c254611c8173f23db0
7
- data.tar.gz: 3696b630bc4c8dd5e326f5f0a603e4083b1600d7ed5ba9f896b21c0a75f901cfaa94b3edcdb19bd82c7a483f2f045dacfd75f05a8e4fed0a9a5d53f3737b85eb
6
+ metadata.gz: e7b51e786aeee4008a5b3887a6edc1bf9c7796c3fd773846d1c467840a6edf41e0b1b010e4e76e16002d39c3dd5c1e366e80c660dd33cf958662029faeb3ab2a
7
+ data.tar.gz: 1be653cc71a1ec89da1bf45ed56d1f7a8e43aaaba423ccc61a9c75c1e6d0be00cf463599f003909ebae55fe1768e004ebf30fecb0c9da086727f031aca46db41
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # TKH Search
2
+
3
+
4
+
5
+ ## 0.0.3
6
+
7
+ * Added this changelog file.
8
+ * Did a bit of eager loading during searches but the algorithm is still VERY slow. Serious ptimization is in the works.
9
+ * Search results work when model has title attribute but no name attribute.
10
+ * Improved the readme file a bit.
11
+
12
+
13
+ ## 0.0.2
14
+
15
+ * Changed a model name to debug Constant name conflict
16
+
17
+
18
+ ## 0.0.1
19
+
20
+ * Initial release with basic indexing and search
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TkhSearch
2
2
 
3
- This is a simple Rails gem search engine. It uses the local database for reverse indexing and to log search queries. Multi-model searches are supported.
3
+ This is a simple Rails gem full text search engine. It uses the local database for reverse indexing and to log search queries. Multi-model searches are supported.
4
4
 
5
5
 
6
6
  ## Installation
@@ -19,6 +19,10 @@ Install initializer and migrations:
19
19
 
20
20
  $ rake tkh_search:install
21
21
 
22
+ Or, upon updating the gem:
23
+
24
+ $ rake tkh_search:update
25
+
22
26
  Run the migrations:
23
27
 
24
28
  $ rake db:migrate
@@ -29,8 +33,11 @@ Run the migrations:
29
33
  In any model you want to index and search, copy/paste and customize the following code:
30
34
 
31
35
  ```ruby
32
- tkh_searchable
36
+ tkh_searchable # for after_save re-indexing hooks
33
37
  def self.tkh_search_indexable_fields
38
+ # The key is the attribute name, the value is the desired strength.
39
+ # By the way, your model needs a title or a name attribute. Real or virtual.
40
+ # Necessary to display result links
34
41
  indexable_fields = {
35
42
  title: 8,
36
43
  description: 3,
@@ -47,7 +54,7 @@ To index a model's records, use the _'reverse_indexing'_ class method. Example:
47
54
  ModelName.reverse_indexing
48
55
  ```
49
56
 
50
- Having configured all the models you wish to index in your search engine, you can index them all by first setting up the initializer.
57
+ Having configured all the models you wish to index in your search engine, you can index them all at once by first setting up the initializer.
51
58
 
52
59
  ```ruby
53
60
  TkhSearch::TkhSearchable.indexable_models = %w( Page Post Event WhateverYouWant )
@@ -55,6 +62,10 @@ TkhSearch::TkhSearchable.indexable_models = %w( Page Post Event WhateverYouWant
55
62
 
56
63
  and secondly, by pointing your browser to: /index_all_models
57
64
 
65
+ #### What about new and updated records?
66
+
67
+ Any single record will be indexed upon saving.
68
+
58
69
 
59
70
  ## Searching your site
60
71
 
@@ -7,7 +7,7 @@ class SearchController < ApplicationController
7
7
  token = SecureRandom.base64
8
8
  search_terms = []
9
9
  @query.split.each do |query_word|
10
- search_terms << TkhSearchTerm.find_by( word: query_word )
10
+ search_terms << TkhSearchTerm.includes(:tkh_search_instances).find_by( word: query_word )
11
11
  end
12
12
  if search_terms.any?
13
13
  search_terms.each do |search_term|
@@ -2,9 +2,16 @@
2
2
  <% if search_results.any? %>
3
3
  <% search_results.each do |result| %>
4
4
  <% record = (Kernel.const_get result.model_name).find(result.model_record_id) %>
5
+ <% if defined? record.name %>
6
+ <% link_label = record.name %>
7
+ <% elsif defined? record.title %>
8
+ <% link_label = record.title %>
9
+ <% else %>
10
+ <% link_label = 'no title or name' %>
11
+ <% end %>
5
12
  <%= content_tag :li,
6
13
  "<span class='sr-model-name'>#{result.model_name}</span> -
7
- <span class='sr-model-name'>#{link_to record.name, record}</span> -
14
+ <span class='sr-record-link'>#{link_to link_label, record}</span> -
8
15
  <span class='sr-rating'>#{result.rating}</span>
9
16
  ".html_safe
10
17
  %>
@@ -1,3 +1,3 @@
1
1
  module TkhSearch
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
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.2
4
+ version: 0.0.3
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-07 00:00:00.000000000 Z
11
+ date: 2014-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -76,6 +76,7 @@ extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
78
  - ".ruby-version"
79
+ - CHANGELOG.md
79
80
  - Gemfile
80
81
  - LICENSE.txt
81
82
  - README.md