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.
@@ -1,7 +1,6 @@
1
- # encoding: utf-8
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 = Proc.new { |word| word.stem }
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 = Proc.new { |query| /#{query}/ }
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| /ˆ#{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 = { "œ"=>"oe", "æ"=>"ae" }
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'
@@ -1,5 +1,7 @@
1
1
  class Category
2
2
  include Mongoid::Document
3
+ include Mongoid::Attributes::Dynamic if ::Mongoid::VERSION >= '4'
4
+
3
5
  field :name, localize: true
4
6
  field :description
5
7
 
@@ -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 :attrs, :type => Array
7
- field :info, :type => Hash
8
+ field :unit
9
+ field :measures, type: Array
10
+ field :attrs, type: Array
11
+ field :info, type: Hash
8
12
 
9
- has_many :tags
10
- belongs_to :category
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, :tags => :name, :category => [:name, :description],
14
- :subproducts => [:brand, :name], :info => [ :summary, :description ]
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
@@ -1,8 +1,9 @@
1
1
  class Subproduct
2
2
  include Mongoid::Document
3
+ include Mongoid::Attributes::Dynamic if ::Mongoid::VERSION >= '4'
3
4
 
4
5
  field :brand
5
6
  field :name
6
7
 
7
- belongs_to :product, :inverse_of => :subproducts
8
+ embedded_in :product, inverse_of: :subproducts
8
9
  end
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
- self.name
11
+ name
11
12
  end
12
13
 
13
- search_in :title, :product => [:name, { :info => [ :summary, :description ], :category => [:name, :description]}]
14
+ search_in :title, product: [:name, { info: %i[summary description], category: %i[name description] }]
14
15
  end
@@ -1,5 +1,7 @@
1
- autoload :Product, "models/product.rb"
1
+ autoload :Product, 'models/product.rb'
2
2
  class Variant < Product
3
3
  field :color
4
+ field :size
4
5
  search_in :color
6
+ search_in :size, index: :_unit_keywords
5
7
  end