mongoid_fulltext 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +18 -0
- data/VERSION +1 -1
- data/lib/mongoid_fulltext.rb +9 -0
- data/mongoid_fulltext.gemspec +2 -2
- data/spec/mongoid/fulltext_spec.rb +78 -0
- metadata +13 -13
data/README.md
CHANGED
@@ -217,6 +217,12 @@ Additional indexing/query options can be used as parameters to `fulltext_search_
|
|
217
217
|
URL, for instance we might have "%C3%A9" which is how an "e-accute" ("é") gets passed
|
218
218
|
through a web-browser. These are then changed to their UTF-8 equivalents (via the `CGI` gem)
|
219
219
|
and then finally stripped, as before.
|
220
|
+
* `update_if`: controls whether or not the index will be updated. This can be set to a symbol,
|
221
|
+
string, or proc. If the result of evaluating the value is true, the index will be updated.
|
222
|
+
** When set to a symbol, the symbol is sent to the document.
|
223
|
+
** When set to a string, the string is evaluated within the document's instance.
|
224
|
+
** When set to a proc, the proc is called, and the document is given to the proc as the first arg.
|
225
|
+
** When set to any other type of object, the document's index will not be updated.
|
220
226
|
|
221
227
|
Array filters
|
222
228
|
-------------
|
@@ -267,6 +273,18 @@ method:
|
|
267
273
|
The methods on the model level perform bulk removal operations and are therefore faster that
|
268
274
|
updating or removing records individually.
|
269
275
|
|
276
|
+
If you need to control when the index is updated, provide the `update_if` option to
|
277
|
+
`fulltext_search_in`, and set it to a symbol, string, or proc. Eg:
|
278
|
+
|
279
|
+
# Only update the "age" index if the "age" field has changed.
|
280
|
+
fulltext_search_in :age, :update_if => :age_changed?
|
281
|
+
|
282
|
+
# Only update the "names" index if the "firstname" or "lastname" field has changed.
|
283
|
+
fulltext_search_in :names, :update_if => "firstname_changed? || lastname_changed?"
|
284
|
+
|
285
|
+
# Only update the "email" index if the "email" field ends with "gmail.com".
|
286
|
+
fulltext_search_in :email, :update_if => Proc.new { |doc| doc.email.match /gmail.com\Z/ }
|
287
|
+
|
270
288
|
Mongo Database Indexes
|
271
289
|
----------------------
|
272
290
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.5
|
data/lib/mongoid_fulltext.rb
CHANGED
@@ -235,6 +235,15 @@ module Mongoid::FullTextSearch
|
|
235
235
|
|
236
236
|
def update_ngram_index
|
237
237
|
self.mongoid_fulltext_config.each_pair do |index_name, fulltext_config|
|
238
|
+
if condition = fulltext_config[:update_if]
|
239
|
+
case condition
|
240
|
+
when Symbol; next unless self.send condition
|
241
|
+
when String; next unless instance_eval condition
|
242
|
+
when Proc; next unless condition.call self
|
243
|
+
else; next
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
238
247
|
# remove existing ngrams from external index
|
239
248
|
coll = collection.db.collection(index_name)
|
240
249
|
coll.remove({'document_id' => self._id})
|
data/mongoid_fulltext.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongoid_fulltext}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aaron Windsor"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-10-05}
|
13
13
|
s.description = %q{Full-text search for the Mongoid ORM, using n-grams extracted from text}
|
14
14
|
s.email = %q{aaron.windsor@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -429,6 +429,84 @@ module Mongoid
|
|
429
429
|
let!(:flowers1) { BasicArtwork.create(:title => 'Flowers 1') }
|
430
430
|
let!(:flowers2) { BasicArtwork.create(:title => 'Flowers 2') }
|
431
431
|
|
432
|
+
context "when config[:update_if] exists" do
|
433
|
+
|
434
|
+
let(:painting) { BasicArtwork.new :title => 'Painting' }
|
435
|
+
let(:conditional_index) { BasicArtwork.mongoid_fulltext_config["mongoid_fulltext.index_conditional"] }
|
436
|
+
|
437
|
+
before(:all) do
|
438
|
+
BasicArtwork.class_eval do
|
439
|
+
fulltext_search_in :title, :index_name => "mongoid_fulltext.index_conditional"
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
after(:all) do
|
444
|
+
Mongoid.master["mongoid_fulltext.index_conditional"].remove
|
445
|
+
BasicArtwork.mongoid_fulltext_config.delete "mongoid_fulltext.index_conditional"
|
446
|
+
end
|
447
|
+
|
448
|
+
context "and is a symbol" do
|
449
|
+
|
450
|
+
before(:all) do
|
451
|
+
conditional_index[:update_if] = :persisted?
|
452
|
+
end
|
453
|
+
|
454
|
+
context "when sending the symbol to the document evaluates to false" do
|
455
|
+
|
456
|
+
it "doesn't update the index for the document" do
|
457
|
+
painting.update_ngram_index
|
458
|
+
BasicArtwork.fulltext_search('painting', :index => "mongoid_fulltext.index_conditional").length.should be 0
|
459
|
+
end
|
460
|
+
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
context "and is a string" do
|
465
|
+
|
466
|
+
before(:all) do
|
467
|
+
conditional_index[:update_if] = 'false'
|
468
|
+
end
|
469
|
+
|
470
|
+
context "when evaluating the string within the document's instance evaluates to false" do
|
471
|
+
|
472
|
+
it "doesn't update the index for the document" do
|
473
|
+
painting.update_ngram_index
|
474
|
+
BasicArtwork.fulltext_search('painting', :index => "mongoid_fulltext.index_conditional").length.should be 0
|
475
|
+
end
|
476
|
+
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
480
|
+
context "and is a proc" do
|
481
|
+
|
482
|
+
before(:all) do
|
483
|
+
conditional_index[:update_if] = Proc.new { false }
|
484
|
+
end
|
485
|
+
|
486
|
+
context "when evaluating the string within the document's instance evaluates to false" do
|
487
|
+
|
488
|
+
it "doesn't update the index for the document" do
|
489
|
+
painting.update_ngram_index
|
490
|
+
BasicArtwork.fulltext_search('painting', :index => "mongoid_fulltext.index_conditional").length.should be 0
|
491
|
+
end
|
492
|
+
|
493
|
+
end
|
494
|
+
end
|
495
|
+
|
496
|
+
context "and is not a symbol, string, or proc" do
|
497
|
+
|
498
|
+
before(:all) do
|
499
|
+
conditional_index[:update_if] = %w(this isn't a symbol, string, or proc)
|
500
|
+
end
|
501
|
+
|
502
|
+
it "doesn't update the index for the document" do
|
503
|
+
painting.update_ngram_index
|
504
|
+
BasicArtwork.fulltext_search('painting', :index => "mongoid_fulltext.index_conditional").length.should be 0
|
505
|
+
end
|
506
|
+
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
432
510
|
context "from scratch" do
|
433
511
|
|
434
512
|
before(:each) do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_fulltext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-05 00:00:00.000000000 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: unicode_utils
|
17
|
-
requirement: &
|
17
|
+
requirement: &83773400 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: 1.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *83773400
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: mongoid
|
28
|
-
requirement: &
|
28
|
+
requirement: &83773150 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 2.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *83773150
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bson_ext
|
39
|
-
requirement: &
|
39
|
+
requirement: &83772860 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.3.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *83772860
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rspec
|
50
|
-
requirement: &
|
50
|
+
requirement: &83772590 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: 2.5.0
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *83772590
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: jeweler
|
61
|
-
requirement: &
|
61
|
+
requirement: &83772310 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: 1.5.2
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *83772310
|
70
70
|
description: Full-text search for the Mongoid ORM, using n-grams extracted from text
|
71
71
|
email: aaron.windsor@gmail.com
|
72
72
|
executables: []
|
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
segments:
|
120
120
|
- 0
|
121
|
-
hash:
|
121
|
+
hash: 700135439
|
122
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
123
|
none: false
|
124
124
|
requirements:
|