mongoid_search 0.3.3 → 0.3.4
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 +4 -4
- data/README.md +6 -0
- data/VERSION +1 -1
- data/lib/mongoid_search.rb +8 -0
- data/lib/mongoid_search/util.rb +4 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 832d506c4a4b192adabbc3858899481804da533e
|
4
|
+
data.tar.gz: ee2c35e2dc25e5de7cc7bb02c149260ff487ff04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f40a5e5437f1865b71bd929ff3c861c33f35197e5c561bfaff6d0ffd31671983c1c0c5699ccbe0f9fb9af7c3af253ff9b704f6b93c186be8c13168ea6dc03b4
|
7
|
+
data.tar.gz: 63e5ee87ed079f03373951efc4cc6eb6accf13cf48ab4e8f53b76bcd689fb04bb097fbe2a2e66db6eccd71438db0876b4abd1f8e61608d23ff37aabc92a3eb8c
|
data/README.md
CHANGED
@@ -166,6 +166,12 @@ Alternatively, you can create an initializer to setup those options:
|
|
166
166
|
# http://en.wikipedia.org/wiki/Typographic_ligature
|
167
167
|
config.ligatures = { "œ"=>"oe", "æ"=>"ae" }
|
168
168
|
|
169
|
+
# Strip symbols regex to be replaced. These symbols will be replaced by space
|
170
|
+
config.strip_symbols = /[._:;'\"`,?|+={}()!@#%^&*<>~\$\-\\\/\[\]]/
|
171
|
+
|
172
|
+
# Strip accents regex to be replaced. These sybols will be removed after strip_symbols replacing
|
173
|
+
config.strip_accents = /[^\s\p{Alnum}]/
|
174
|
+
|
169
175
|
# Minimum word size. Words smaller than it won't be indexed
|
170
176
|
config.minimum_word_size = 2
|
171
177
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
data/lib/mongoid_search.rb
CHANGED
@@ -60,6 +60,14 @@ module Mongoid::Search
|
|
60
60
|
mattr_accessor :minimum_word_size
|
61
61
|
@@minimum_word_size = 2
|
62
62
|
|
63
|
+
# Strip special symbols
|
64
|
+
mattr_accessor :strip_symbols
|
65
|
+
@@strip_symbols = /[._:;'\"`,?|+={}()!@#%^&*<>~\$\-\\\/\[\]]/
|
66
|
+
|
67
|
+
# Strip accents
|
68
|
+
mattr_accessor :strip_accents
|
69
|
+
@@strip_accents = /[^\s\p{Alnum}]/
|
70
|
+
|
63
71
|
def self.setup
|
64
72
|
yield self
|
65
73
|
end
|
data/lib/mongoid_search/util.rb
CHANGED
@@ -34,6 +34,8 @@ module Mongoid::Search::Util
|
|
34
34
|
ignore_list = Mongoid::Search.ignore_list
|
35
35
|
stem_keywords = Mongoid::Search.stem_keywords
|
36
36
|
stem_proc = Mongoid::Search.stem_proc
|
37
|
+
strip_symbols = Mongoid::Search.strip_symbols
|
38
|
+
strip_accents = Mongoid::Search.strip_accents
|
37
39
|
|
38
40
|
return [] if text.blank?
|
39
41
|
text = text.to_s.
|
@@ -41,8 +43,8 @@ module Mongoid::Search::Util
|
|
41
43
|
normalize(:kd).
|
42
44
|
downcase.
|
43
45
|
to_s.
|
44
|
-
gsub(
|
45
|
-
gsub(
|
46
|
+
gsub(strip_symbols, ' '). # strip symbols
|
47
|
+
gsub(strip_accents, ''). # strip accents
|
46
48
|
gsub(/[#{ligatures.keys.join("")}]/) {|c| ligatures[c]}.
|
47
49
|
split(' ').
|
48
50
|
reject { |word| word.size < Mongoid::Search.minimum_word_size }
|