mongoid_search 0.3.2 → 0.3.6
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.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.md +152 -105
- data/Rakefile +5 -2
- data/VERSION +1 -1
- data/lib/mongoid_search/log.rb +2 -1
- data/lib/mongoid_search/mongoid_search.rb +61 -42
- data/lib/mongoid_search/railtie.rb +2 -5
- data/lib/mongoid_search/tasks/mongoid_search.rake +16 -0
- data/lib/mongoid_search/util.rb +19 -18
- data/lib/mongoid_search.rb +14 -7
- data/spec/models/category.rb +2 -0
- data/spec/models/product.rb +15 -6
- data/spec/models/subproduct.rb +2 -1
- data/spec/models/tag.rb +3 -2
- data/spec/models/variant.rb +3 -1
- data/spec/mongoid_search_spec.rb +231 -133
- data/spec/spec_helper.rb +4 -1
- data/spec/util_spec.rb +28 -29
- metadata +56 -52
data/lib/mongoid_search.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require 'mongoid_search/mongoid_search'
|
|
2
2
|
|
|
3
3
|
require 'mongoid_search/railtie' if defined?(Rails)
|
|
4
|
-
require 'mongoid_search/mongoid_search'
|
|
5
4
|
|
|
6
5
|
module Mongoid::Search
|
|
7
6
|
## Default matching type. Match :any or :all searched keywords
|
|
@@ -22,7 +21,7 @@ module Mongoid::Search
|
|
|
22
21
|
|
|
23
22
|
## Stem procedure
|
|
24
23
|
mattr_accessor :stem_proc
|
|
25
|
-
@@stem_proc =
|
|
24
|
+
@@stem_proc = proc { |word| word.stem }
|
|
26
25
|
|
|
27
26
|
## Words to ignore
|
|
28
27
|
mattr_accessor :ignore_list
|
|
@@ -42,25 +41,33 @@ module Mongoid::Search
|
|
|
42
41
|
mattr_accessor :regex
|
|
43
42
|
|
|
44
43
|
## Match partial words on both sides (slower)
|
|
45
|
-
@@regex =
|
|
44
|
+
@@regex = proc { |query| /#{query}/ }
|
|
46
45
|
|
|
47
46
|
## Match partial words on the beginning or in the end (slightly faster)
|
|
48
|
-
# @@regex = Proc.new { |query|
|
|
47
|
+
# @@regex = Proc.new { |query| /^#{query}/ }
|
|
49
48
|
# @@regex = Proc.new { |query| /#{query}$/ }
|
|
50
49
|
|
|
51
50
|
# Ligatures to be replaced
|
|
52
51
|
# http://en.wikipedia.org/wiki/Typographic_ligature
|
|
53
52
|
mattr_accessor :ligatures
|
|
54
|
-
@@ligatures = {
|
|
53
|
+
@@ligatures = { 'œ' => 'oe', 'æ' => 'ae', 'ꜵ' => 'ao' }
|
|
55
54
|
|
|
56
55
|
# Minimum word size. Words smaller than it won't be indexed
|
|
57
56
|
mattr_accessor :minimum_word_size
|
|
58
57
|
@@minimum_word_size = 2
|
|
59
58
|
|
|
59
|
+
# Strip special symbols
|
|
60
|
+
mattr_accessor :strip_symbols
|
|
61
|
+
@@strip_symbols = /[._:;'\"`,?|+={}()!@#%^&*<>~\$\-\\\/\[\]]/
|
|
62
|
+
|
|
63
|
+
# Strip accents
|
|
64
|
+
mattr_accessor :strip_accents
|
|
65
|
+
@@strip_accents = /[^\s\p{Alnum}]/
|
|
66
|
+
|
|
60
67
|
def self.setup
|
|
61
68
|
yield self
|
|
62
69
|
end
|
|
63
70
|
end
|
|
64
71
|
|
|
65
72
|
require 'mongoid_search/util'
|
|
66
|
-
require 'mongoid_search/log'
|
|
73
|
+
require 'mongoid_search/log'
|
data/spec/models/category.rb
CHANGED
data/spec/models/product.rb
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
class Product
|
|
2
2
|
include Mongoid::Document
|
|
3
3
|
include Mongoid::Search
|
|
4
|
+
include Mongoid::Attributes::Dynamic if ::Mongoid::VERSION >= '4'
|
|
5
|
+
|
|
4
6
|
field :brand
|
|
5
7
|
field :name
|
|
6
|
-
field :
|
|
7
|
-
field :
|
|
8
|
+
field :unit
|
|
9
|
+
field :measures, type: Array
|
|
10
|
+
field :attrs, type: Array
|
|
11
|
+
field :info, type: Hash
|
|
8
12
|
|
|
9
|
-
has_many
|
|
10
|
-
|
|
13
|
+
has_many :tags
|
|
14
|
+
if Mongoid::Compatibility::Version.mongoid6_or_newer?
|
|
15
|
+
belongs_to :category, required: false
|
|
16
|
+
else
|
|
17
|
+
belongs_to :category
|
|
18
|
+
end
|
|
11
19
|
embeds_many :subproducts
|
|
12
20
|
|
|
13
|
-
search_in :brand, :name, :outlet, :attrs, :
|
|
14
|
-
|
|
21
|
+
search_in :brand, :name, :outlet, :attrs, tags: :name, category: %i[name description],
|
|
22
|
+
subproducts: %i[brand name], info: %i[summary description]
|
|
23
|
+
search_in :unit, :measures, index: :_unit_keywords
|
|
15
24
|
end
|
data/spec/models/subproduct.rb
CHANGED
data/spec/models/tag.rb
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
class Tag
|
|
2
2
|
include Mongoid::Document
|
|
3
3
|
include Mongoid::Search
|
|
4
|
+
include Mongoid::Attributes::Dynamic if ::Mongoid::VERSION >= '4'
|
|
4
5
|
|
|
5
6
|
field :name
|
|
6
7
|
|
|
7
8
|
belongs_to :product
|
|
8
9
|
|
|
9
10
|
def title
|
|
10
|
-
|
|
11
|
+
name
|
|
11
12
|
end
|
|
12
13
|
|
|
13
|
-
search_in :title, :
|
|
14
|
+
search_in :title, product: [:name, { info: %i[summary description], category: %i[name description] }]
|
|
14
15
|
end
|