search_magic 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +13 -11
- data/README.textile +9 -9
- data/lib/search_magic/full_text_search.rb +1 -1
- data/lib/search_magic/version.rb +1 -1
- data/lib/search_magic.rb +5 -0
- data/search_magic.gemspec +1 -0
- data/spec/fabricators/asset_fabricator.rb +6 -0
- data/spec/fabricators/simple_inclusion_model_fabricator.rb +4 -0
- data/spec/models/simple_inclusion_model.rb +8 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/search_magic/fields_spec.rb +2 -2
- data/spec/unit/search_magic/search_pattern_syntax_spec.rb +19 -0
- data/spec/unit/search_magic/simple_inclusion_model_spec.rb +22 -0
- metadata +23 -2
data/Gemfile.lock
CHANGED
@@ -1,28 +1,29 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
search_magic (0.1.
|
4
|
+
search_magic (0.1.1)
|
5
5
|
mongoid (>= 2.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (3.0.
|
11
|
-
activesupport (= 3.0.
|
10
|
+
activemodel (3.0.6)
|
11
|
+
activesupport (= 3.0.6)
|
12
12
|
builder (~> 2.1.2)
|
13
|
-
i18n (~> 0.
|
14
|
-
activesupport (3.0.
|
15
|
-
bson (1.
|
16
|
-
bson_ext (1.
|
13
|
+
i18n (~> 0.5.0)
|
14
|
+
activesupport (3.0.6)
|
15
|
+
bson (1.3.0)
|
16
|
+
bson_ext (1.3.0)
|
17
17
|
builder (2.1.2)
|
18
18
|
database_cleaner (0.6.4)
|
19
19
|
diff-lcs (1.1.2)
|
20
|
+
fabrication (0.9.5)
|
20
21
|
i18n (0.5.0)
|
21
|
-
mongo (1.
|
22
|
-
bson (>= 1.
|
23
|
-
mongoid (2.0.
|
22
|
+
mongo (1.3.0)
|
23
|
+
bson (>= 1.3.0)
|
24
|
+
mongoid (2.0.1)
|
24
25
|
activemodel (~> 3.0)
|
25
|
-
mongo (~> 1.
|
26
|
+
mongo (~> 1.3)
|
26
27
|
tzinfo (~> 0.3.22)
|
27
28
|
will_paginate (~> 3.0.pre)
|
28
29
|
rspec (2.5.0)
|
@@ -42,5 +43,6 @@ PLATFORMS
|
|
42
43
|
DEPENDENCIES
|
43
44
|
bson_ext
|
44
45
|
database_cleaner
|
46
|
+
fabrication
|
45
47
|
rspec
|
46
48
|
search_magic!
|
data/README.textile
CHANGED
@@ -4,7 +4,7 @@ SearchMagic provides full-text search capabilities to "mongoid":http://github.co
|
|
4
4
|
|
5
5
|
h2. Installation
|
6
6
|
|
7
|
-
SearchMagic is built on top of
|
7
|
+
SearchMagic is built on top of mongoid; in all likelihood, it will only work with versions greater than or equal to _2.0.0_. The project can be installed as a gem on a target system:
|
8
8
|
|
9
9
|
bc. gem install search_magic
|
10
10
|
|
@@ -20,7 +20,7 @@ Adding FullTextSearch is as simple as including the appropriate module into a mo
|
|
20
20
|
|
21
21
|
bc.. class Address
|
22
22
|
include Mongoid::Document
|
23
|
-
include SearchMagic
|
23
|
+
include SearchMagic
|
24
24
|
field :street
|
25
25
|
field :city
|
26
26
|
field :state
|
@@ -51,7 +51,7 @@ The example in the previous section showcased using :search_on on basic *Mongoid
|
|
51
51
|
|
52
52
|
bc.. class Person
|
53
53
|
include Mongoid::Document
|
54
|
-
include SearchMagic
|
54
|
+
include SearchMagic
|
55
55
|
field :name
|
56
56
|
embeds_one :address
|
57
57
|
|
@@ -78,7 +78,7 @@ Values added to *:searchable_values* automatically are split on whitespace and h
|
|
78
78
|
|
79
79
|
bc.. class Asset
|
80
80
|
include Mongoid::Document
|
81
|
-
include SearchMagic
|
81
|
+
include SearchMagic
|
82
82
|
field :tags, :type => Array
|
83
83
|
|
84
84
|
search_on :tags, :keep_punctuation => true
|
@@ -90,7 +90,7 @@ Two documents may search on each other's fields; doing so will cause each docume
|
|
90
90
|
|
91
91
|
bc.. class Foo
|
92
92
|
include Mongoid::Document
|
93
|
-
include SearchMagic
|
93
|
+
include SearchMagic
|
94
94
|
field :name
|
95
95
|
references_many :bars
|
96
96
|
search_on :name
|
@@ -99,7 +99,7 @@ end
|
|
99
99
|
|
100
100
|
class Bar
|
101
101
|
include Mongoid::Document
|
102
|
-
include SearchMagic
|
102
|
+
include SearchMagic
|
103
103
|
field :value
|
104
104
|
referenced_in :foo
|
105
105
|
search_on :value
|
@@ -111,7 +111,7 @@ Finally, it should be noted that nesting of searchable documents is possible. If
|
|
111
111
|
bc.. class Part
|
112
112
|
include Mongoid::Document
|
113
113
|
include Mongoid::Timestamps
|
114
|
-
include SearchMagic
|
114
|
+
include SearchMagic
|
115
115
|
field :serial
|
116
116
|
references_in :part_number
|
117
117
|
|
@@ -121,7 +121,7 @@ end
|
|
121
121
|
|
122
122
|
class PartNumber
|
123
123
|
include Mongoid::Document
|
124
|
-
include SearchMagic
|
124
|
+
include SearchMagic
|
125
125
|
field :value
|
126
126
|
references_many :parts
|
127
127
|
referenced_in :part_category
|
@@ -132,7 +132,7 @@ end
|
|
132
132
|
|
133
133
|
class PartCategory
|
134
134
|
include Mongoid::Document
|
135
|
-
include SearchMagic
|
135
|
+
include SearchMagic
|
136
136
|
field :name
|
137
137
|
references_many :part_numbers
|
138
138
|
|
@@ -29,7 +29,7 @@ module SearchMagic
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def search_for(pattern)
|
32
|
-
rval = /("[^"]+"|\S+)/
|
32
|
+
rval = /("[^"]+"|'[^']+'|\S+)/
|
33
33
|
rsearch = /(?:(#{searchables.keys.join('|')}):#{rval})|#{rval}/i
|
34
34
|
unless pattern.blank?
|
35
35
|
terms = pattern.scan(rsearch).map(&:compact).map do |term|
|
data/lib/search_magic/version.rb
CHANGED
data/lib/search_magic.rb
CHANGED
data/search_magic.gemspec
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -37,7 +37,7 @@ describe SearchMagic::FullTextSearch do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
context "when a model is saved, its :searchable_values update" do
|
40
|
-
subject {
|
40
|
+
subject { Fabricate.build(:asset, :title => "Foo Bar: The Bazzening", :description => "Sequel to last years hit summer blockbuster.", :tags => ["movies", "foo.bar", "the-bazzening"]) }
|
41
41
|
before(:each) { subject.save }
|
42
42
|
its(:searchable_values) { should_not be_empty }
|
43
43
|
its(:searchable_values) { should include("title:foo", "title:bar", "title:the", "title:bazzening")}
|
@@ -45,7 +45,7 @@ describe SearchMagic::FullTextSearch do
|
|
45
45
|
its(:searchable_values) { should_not include("uuid:ae9d14ee-be93-11df-9fec-78ca39fffe11", "uuid:ae9d14ee")}
|
46
46
|
its(:searchable_values) { should include("tag:movies", "tag:foo.bar", "tag:the-bazzening")}
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
context "when :search is performed on a model without :searchables" do
|
50
50
|
subject { NoSearchables.search_for("foo") }
|
51
51
|
it { should be_a(Mongoid::Criteria) }
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe SearchMagic::FullTextSearch do
|
2
|
+
context "when searching for \"title:'foo bar'\"" do
|
3
|
+
subject { Asset.search_for("title:'foo bar'") }
|
4
|
+
its("selector.keys") { should include(:searchable_values) }
|
5
|
+
it { subject.selector[:searchable_values]["$all"].should include(/title:.*foo/i, /title:.*bar/i)}
|
6
|
+
end
|
7
|
+
|
8
|
+
context "when searching for 'title:\"foo bar\"'" do
|
9
|
+
subject { Asset.search_for('title:"foo bar"') }
|
10
|
+
its("selector.keys") { should include(:searchable_values) }
|
11
|
+
it { subject.selector[:searchable_values]["$all"].should include(/title:.*foo/i, /title:.*bar/i)}
|
12
|
+
end
|
13
|
+
|
14
|
+
context "when searching for 'title:foo title:bar'" do
|
15
|
+
subject { Asset.search_for('title:foo title:bar') }
|
16
|
+
its("selector.keys") { should include(:searchable_values) }
|
17
|
+
it { subject.selector[:searchable_values]["$all"].should include(/title:.*foo/i, /title:.*bar/i)}
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
describe SearchMagic do
|
2
|
+
context "when included in a model" do
|
3
|
+
subject { SimpleInclusionModel }
|
4
|
+
it { should respond_to(:search_on, :search_for, :searchables, :arrange) }
|
5
|
+
its("searchables.keys") { should include(:foo, :bar) }
|
6
|
+
end
|
7
|
+
|
8
|
+
context "when saving a model" do
|
9
|
+
subject { Fabricate.build(:simple_inclusion_model, :foo => "F.o-o") }
|
10
|
+
before(:each) { subject.save! }
|
11
|
+
its(:searchable_values) { should include("foo:f.o-o") }
|
12
|
+
its(:arrangeable_values) { should include(:foo => "F.o-o") }
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when searching for a model" do
|
16
|
+
before(:each) { Fabricate(:simple_inclusion_model) }
|
17
|
+
subject { SimpleInclusionModel.search_for("foo") }
|
18
|
+
its(:count) { should == 1 }
|
19
|
+
its("first.foo") { should == "a foo" }
|
20
|
+
its("first.bar") { should == "a bar" }
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: search_magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Joshua Bowers
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-14 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -57,6 +57,17 @@ dependencies:
|
|
57
57
|
version: "0"
|
58
58
|
type: :development
|
59
59
|
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: fabrication
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
60
71
|
description: Adds scopes to a Mongoid document providing search and sort capabilities on arbitrary fields and associations.
|
61
72
|
email:
|
62
73
|
- joshua.bowers+code@gmail.com
|
@@ -79,6 +90,8 @@ files:
|
|
79
90
|
- lib/search_magic/stack_frame.rb
|
80
91
|
- lib/search_magic/version.rb
|
81
92
|
- search_magic.gemspec
|
93
|
+
- spec/fabricators/asset_fabricator.rb
|
94
|
+
- spec/fabricators/simple_inclusion_model_fabricator.rb
|
82
95
|
- spec/models/absolutely_not_searchable.rb
|
83
96
|
- spec/models/address.rb
|
84
97
|
- spec/models/asset.rb
|
@@ -95,12 +108,15 @@ files:
|
|
95
108
|
- spec/models/person.rb
|
96
109
|
- spec/models/phone.rb
|
97
110
|
- spec/models/player.rb
|
111
|
+
- spec/models/simple_inclusion_model.rb
|
98
112
|
- spec/spec_helper.rb
|
99
113
|
- spec/unit/search_magic/arrangements_spec.rb
|
100
114
|
- spec/unit/search_magic/associations_spec.rb
|
101
115
|
- spec/unit/search_magic/fields_spec.rb
|
102
116
|
- spec/unit/search_magic/graph_searches_spec.rb
|
103
117
|
- spec/unit/search_magic/model_updates_spec.rb
|
118
|
+
- spec/unit/search_magic/search_pattern_syntax_spec.rb
|
119
|
+
- spec/unit/search_magic/simple_inclusion_model_spec.rb
|
104
120
|
has_rdoc: true
|
105
121
|
homepage: http://github.com/joshuabowers/search_magic
|
106
122
|
licenses: []
|
@@ -130,6 +146,8 @@ signing_key:
|
|
130
146
|
specification_version: 3
|
131
147
|
summary: SearchMagic provides scoped full text search and sort capabilities to Mongoid documents
|
132
148
|
test_files:
|
149
|
+
- spec/fabricators/asset_fabricator.rb
|
150
|
+
- spec/fabricators/simple_inclusion_model_fabricator.rb
|
133
151
|
- spec/models/absolutely_not_searchable.rb
|
134
152
|
- spec/models/address.rb
|
135
153
|
- spec/models/asset.rb
|
@@ -146,9 +164,12 @@ test_files:
|
|
146
164
|
- spec/models/person.rb
|
147
165
|
- spec/models/phone.rb
|
148
166
|
- spec/models/player.rb
|
167
|
+
- spec/models/simple_inclusion_model.rb
|
149
168
|
- spec/spec_helper.rb
|
150
169
|
- spec/unit/search_magic/arrangements_spec.rb
|
151
170
|
- spec/unit/search_magic/associations_spec.rb
|
152
171
|
- spec/unit/search_magic/fields_spec.rb
|
153
172
|
- spec/unit/search_magic/graph_searches_spec.rb
|
154
173
|
- spec/unit/search_magic/model_updates_spec.rb
|
174
|
+
- spec/unit/search_magic/search_pattern_syntax_spec.rb
|
175
|
+
- spec/unit/search_magic/simple_inclusion_model_spec.rb
|