mongoid-searchable 0.1.3 → 0.2.0
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.
- data/README.md +13 -9
- data/lib/mongoid/searchable.rb +1 -2
- data/lib/mongoid/searchable/version.rb +1 -1
- metadata +14 -14
data/README.md
CHANGED
@@ -4,6 +4,10 @@ Mongoid Searchable provides simple field search for your Mongoid models using th
|
|
4
4
|
|
5
5
|
[](http://travis-ci.org/jcoene/mongoid-searchable)
|
6
6
|
|
7
|
+
## 0.1.x Compatibility
|
8
|
+
|
9
|
+
Please note that version **0.2.0 has renamed the *search* method to *text_search* to avoid naming issues**. Sorry for the inconvenience but given the issues this can cause and limited alternative solutions, I figured that it would be prudent to make this change sooner rather than later.
|
10
|
+
|
7
11
|
## Getting Started
|
8
12
|
|
9
13
|
First, add mongoid-searchable to your Gemfile:
|
@@ -40,30 +44,30 @@ City.create :name => 'Rochester, NY', :population => 1_098_201,
|
|
40
44
|
City.create :name => 'Rochester, MN', :population => 186_011,
|
41
45
|
:officials => { 'Mayor' => 'Ardell Brede', 'Governor' => 'Mark Dayton' }
|
42
46
|
|
43
|
-
City.
|
44
|
-
City.
|
45
|
-
City.
|
47
|
+
City.text_search('ny') # => 2 records
|
48
|
+
City.text_search('rochester') # => 2 records
|
49
|
+
City.text_search('manhattan') # => 1 record
|
46
50
|
```
|
47
51
|
|
48
52
|
You can also choose to match all or any tokens. The default is to match **all** terms:
|
49
53
|
|
50
54
|
```ruby
|
51
|
-
City.
|
52
|
-
City.
|
55
|
+
City.text_search('rochester ny') # => 1 record (defaults to all)
|
56
|
+
City.text_search('rochester ny', :match => :any) # => 3 records
|
53
57
|
```
|
54
58
|
|
55
59
|
We can match partial or exact words as well. The default is to match **partial** words:
|
56
60
|
|
57
61
|
```ruby
|
58
|
-
City.
|
59
|
-
City.
|
62
|
+
City.text_search('roch') # => 2 records
|
63
|
+
City.text_search('roch', :exact => true) # => 0 records
|
60
64
|
```
|
61
65
|
|
62
66
|
You can chain other criteria on to your search, as per Mongoid convention:
|
63
67
|
|
64
68
|
```ruby
|
65
|
-
City.
|
66
|
-
City.
|
69
|
+
City.text_search('ny').where(:population.gt => 2_000_000) # => 1 record
|
70
|
+
City.text_search('rochester').where(:population.lt => 500_000) # => 1 record
|
67
71
|
```
|
68
72
|
|
69
73
|
## Customization
|
data/lib/mongoid/searchable.rb
CHANGED
@@ -43,7 +43,6 @@ module Mongoid
|
|
43
43
|
index :keywords if options[:index]
|
44
44
|
|
45
45
|
before_save :build_keywords
|
46
|
-
|
47
46
|
end
|
48
47
|
|
49
48
|
# Search for documents matching your query, given the previously
|
@@ -59,7 +58,7 @@ module Mongoid
|
|
59
58
|
# :exact - Boolean, require exact word match (or not).
|
60
59
|
#
|
61
60
|
# Returns Mongoid::Criteria.
|
62
|
-
def
|
61
|
+
def text_search(query, options={})
|
63
62
|
keywords = clean_keywords(query)
|
64
63
|
options[:match] ||= :all
|
65
64
|
options[:exact] ||= false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-searchable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-10-01 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
16
|
-
requirement: &
|
16
|
+
requirement: &70234421977540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70234421977540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bson_ext
|
27
|
-
requirement: &
|
27
|
+
requirement: &70234421977040 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.3'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70234421977040
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: growl
|
38
|
-
requirement: &
|
38
|
+
requirement: &70234421976660 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70234421976660
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &70234421976100 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.9.2
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70234421976100
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &70234421975600 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '2.6'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70234421975600
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: guard-rspec
|
71
|
-
requirement: &
|
71
|
+
requirement: &70234421975120 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: 0.4.3
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70234421975120
|
80
80
|
description: Mongoid Searchable allows you to easily perform full-text search your
|
81
81
|
Mongoid models.
|
82
82
|
email:
|