fuzzily 0.3.2 → 0.3.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: d04543358e6ec800df190db5551d6c0b1d54c724
4
- data.tar.gz: 444c4b642b6adbb9e7cae708e8499d3e4649583a
3
+ metadata.gz: c37ee71c17d18b2b0a83263b030b99d006e1fcb6
4
+ data.tar.gz: d0c4d04349af32e8703bbc12f2b8e01806f39f18
5
5
  SHA512:
6
- metadata.gz: 49349a79e620091a9284072812e6b4f335eceece513751146af68f004a1fabe4b901afd7811a5de2adc4c494adb5b1339529fa641daca382011a111c8382f3de
7
- data.tar.gz: e975d27be885f3d98c64c11c6e7e2eaf036402b5a2301c2cd6ff2dffda9ae9bf8d7d14dd2c3b52ae78e1dc747b69fb5385198bc7aad33e0687953aa8981aeb7b
6
+ metadata.gz: 2e78e76c739b9cd65ebccb6f9aef1e5e1e9a4f5fdcd4c0dcd93daa83d14d4c3e52dee40627a4bf2a8a6474ae503d0380ece47c47f772b2b7d2940a37622af141
7
+ data.tar.gz: fc3ee743aa1daafb48040732a4ad5f4dd6c25929d2967365eca67a940e8ba70dd92ba5d6aec86a45f36f751c4d8179dafe12ddfd6511caa900ef064988db44e6
@@ -1 +1 @@
1
- 2.0.0-p353
1
+ 2.0.0-p451
@@ -1,8 +1,8 @@
1
1
  rvm:
2
2
  - "1.8.7"
3
- - "1.9.2"
4
3
  - "1.9.3"
5
4
  - "2.0.0"
5
+ - "2.1.0"
6
6
  gemfile:
7
7
  - gemfiles/rails23.gemfile
8
8
  - gemfiles/rails30.gemfile
@@ -20,12 +20,12 @@ after_script:
20
20
  - ./rebund/run upload
21
21
  matrix:
22
22
  exclude:
23
+ - rvm: 2.1.0
24
+ gemfile: gemfiles/rails23.gemfile
23
25
  - rvm: 2.0.0
24
26
  gemfile: gemfiles/rails23.gemfile
25
27
  - rvm: 1.8.7
26
28
  gemfile: gemfiles/rails40.gemfile
27
- - rvm: 1.9.2
28
- gemfile: gemfiles/rails40.gemfile
29
29
  before_script:
30
30
  - psql -c 'create database fuzzily_test;' -U postgres
31
31
  - mysql -e 'create database fuzzily_test;'
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fuzzily (0.3.2)
4
+ fuzzily (0.3.3)
5
5
  activerecord (>= 2.3.17)
6
6
 
7
7
  GEM
8
- remote: http://yarp.dev/
8
+ remote: https://rubygems.org/
9
9
  specs:
10
10
  activemodel (3.2.14)
11
11
  activesupport (= 3.2.14)
data/README.md CHANGED
@@ -15,7 +15,7 @@ Fuzzily finds misspelled, prefix, or partial needles in a haystack of
15
15
  strings. It's a fast, [trigram](http://en.wikipedia.org/wiki/N-gram)-based, database-backed [fuzzy](http://en.wikipedia.org/wiki/Approximate_string_matching) string search/match engine for Rails.
16
16
  Loosely inspired from an [old blog post](http://unirec.blogspot.co.uk/2007/12/live-fuzzy-search-using-n-grams-in.html).
17
17
 
18
- Tested with ActiveRecord (2.3, 3.0, 3.1, 3.2, 4.0) on various Rubies (1.8.7, 1.9.2, 1.9.3, 2.0.0) and the most common adapters (SQLite3, MySQL, and PostgreSQL).
18
+ Tested with ActiveRecord (2.3, 3.0, 3.1, 3.2, 4.0) on various Rubies (1.8.7, 1.9.3, 2.0.0, 2.1.0) and the most common adapters (SQLite3, MySQL, and PostgreSQL).
19
19
 
20
20
  If your dateset is big, if you need yet more speed, or do not use ActiveRecord,
21
21
  check out [blurrily](http://github.com/mezis/blurrily), another gem (backed with a C extension)
@@ -166,7 +166,16 @@ class Employee < ActiveRecord::Base
166
166
  end
167
167
  ```
168
168
 
169
+ ## Update Trigram index using `sidekiq-delay`
169
170
 
171
+ For larger text, it takes time to build the index. Thus it can be moved into delay task using `sidekiq` + `sidekiq-delay` or `delayed_job` gem, both of them provide the method `delay` to move the execution to background thread by adding option `async`:
172
+
173
+ ```ruby
174
+ class Employee < ActiveRecord::Base
175
+ fuzzily_searchable :name, async: true
176
+
177
+ end
178
+ ```
170
179
 
171
180
  ## License
172
181
 
@@ -40,7 +40,7 @@ module Fuzzily
40
40
  private
41
41
 
42
42
  def _find_by_fuzzy(_o, pattern, options={})
43
- options[:limit] ||= 10
43
+ options[:limit] ||= 10 unless options.has_key? :limit
44
44
  options[:offset] ||= 0
45
45
 
46
46
  trigrams = _o.trigram_class_name.constantize.
@@ -112,7 +112,8 @@ module Fuzzily
112
112
  :field => field,
113
113
  :trigram_class_name => options.fetch(:class_name, 'Trigram'),
114
114
  :trigram_association => "trigrams_for_#{field}".to_sym,
115
- :update_trigrams_method => "update_fuzzy_#{field}!".to_sym
115
+ :update_trigrams_method => "update_fuzzy_#{field}!".to_sym,
116
+ :async => options.fetch(:async, false)
116
117
  )
117
118
 
118
119
  _add_trigram_association(_o)
@@ -126,11 +127,16 @@ module Fuzzily
126
127
  end
127
128
 
128
129
  define_method _o.update_trigrams_method do
129
- _update_fuzzy!(_o)
130
+ if _o.async && self.respond_to?(:delay)
131
+ self.delay._update_fuzzy!(_o)
132
+ else
133
+ _update_fuzzy!(_o)
134
+ end
130
135
  end
131
136
 
132
137
  after_save do |record|
133
138
  next unless record.send("#{field}_changed?".to_sym)
139
+
134
140
  record.send(_o.update_trigrams_method)
135
141
  end
136
142
 
@@ -1,3 +1,3 @@
1
1
  module Fuzzily
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -154,6 +154,18 @@ describe Fuzzily::Searchable do
154
154
  subject.find_by_fuzzy_name('Paris', :limit => 2).length.should == 2
155
155
  end
156
156
 
157
+ it 'limits results to 10 if limit option is not given' do
158
+ subject.fuzzily_searchable :name
159
+ 30.times { subject.create!(:name => 'Paris') }
160
+ subject.find_by_fuzzy_name('Paris').length.should == 10
161
+ end
162
+
163
+ it 'does not limit results it limit option is present and is nil' do
164
+ subject.fuzzily_searchable :name
165
+ 30.times { subject.create!(:name => 'Paris') }
166
+ subject.find_by_fuzzy_name('Paris', :limit => nil).length.should == 30
167
+ end
168
+
157
169
  it 'honours offset option' do
158
170
  subject.fuzzily_searchable :name
159
171
  3.times { subject.create!(:name => 'Paris') }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fuzzily
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Letessier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-01 00:00:00.000000000 Z
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord