Skip to content
This repository
Browse code

Merge pull request #29 from semaperepelitsa/master

Downcase utf-8 chars of keywords
  • Loading branch information...
commit 417e6ddc1e4313617aa7f85fc252cad7b8bc750c 2 parents cf7914e + 639b6cc
Mauricio Zaffari authored December 16, 2011
37  Gemfile.lock
... ...
@@ -1,32 +1,35 @@
1 1
 PATH
2 2
   remote: .
3 3
   specs:
4  
-    mongoid_search (0.2.6)
5  
-      bson_ext (~> 1.2)
  4
+    mongoid_search (0.2.7)
  5
+      bson_ext (>= 1.2)
6 6
       fast-stemmer (~> 1.0.0)
7  
-      mongoid (~> 2.0.0)
  7
+      mongoid (>= 2.0.0)
8 8
 
9 9
 GEM
10 10
   remote: http://rubygems.org/
11 11
   specs:
12  
-    activemodel (3.0.9)
13  
-      activesupport (= 3.0.9)
14  
-      builder (~> 2.1.2)
15  
-      i18n (~> 0.5.0)
16  
-    activesupport (3.0.9)
17  
-    bson (1.3.1)
18  
-    bson_ext (1.3.1)
19  
-    builder (2.1.2)
  12
+    activemodel (3.1.3)
  13
+      activesupport (= 3.1.3)
  14
+      builder (~> 3.0.0)
  15
+      i18n (~> 0.6)
  16
+    activesupport (3.1.3)
  17
+      multi_json (~> 1.0)
  18
+    bson (1.5.2)
  19
+    bson_ext (1.5.2)
  20
+      bson (= 1.5.2)
  21
+    builder (3.0.0)
20 22
     database_cleaner (0.6.7)
21 23
     diff-lcs (1.1.2)
22 24
     fast-stemmer (1.0.0)
23  
-    i18n (0.5.0)
24  
-    mongo (1.3.1)
25  
-      bson (>= 1.3.1)
26  
-    mongoid (2.0.2)
27  
-      activemodel (~> 3.0)
  25
+    i18n (0.6.0)
  26
+    mongo (1.5.2)
  27
+      bson (= 1.5.2)
  28
+    mongoid (2.3.4)
  29
+      activemodel (~> 3.1)
28 30
       mongo (~> 1.3)
29 31
       tzinfo (~> 0.3.22)
  32
+    multi_json (1.0.4)
30 33
     rake (0.8.7)
31 34
     rspec (2.6.0)
32 35
       rspec-core (~> 2.6.0)
@@ -39,7 +42,7 @@ GEM
39 42
     simplecov (0.4.2)
40 43
       simplecov-html (~> 0.4.4)
41 44
     simplecov-html (0.4.5)
42  
-    tzinfo (0.3.29)
  45
+    tzinfo (0.3.31)
43 46
 
44 47
 PLATFORMS
45 48
   ruby
2  lib/mongoid_search/util.rb
@@ -29,10 +29,10 @@ def self.normalize_keywords(text, stem_keywords, ignore_list)
29 29
     text = text.to_s.
30 30
       mb_chars.
31 31
       normalize(:kd).
  32
+      downcase.
32 33
       to_s.
33 34
       gsub(/[._:;'"`,?|+={}()!@#%^&*<>~\$\-\\\/\[\]]/, ' '). # strip punctuation
34 35
       gsub(/[^[:alnum:]\s]/,'').   # strip accents
35  
-      downcase.
36 36
       split(' ').
37 37
       reject { |word| word.size < 2 }
38 38
     text = text.reject { |word| ignore_list.include?(word) } unless ignore_list.blank?
6  spec/mongoid_search_spec.rb
@@ -26,7 +26,11 @@
26 26
     }
27 27
 
28 28
     it "should leave utf8 characters" do
29  
-      @product._keywords.should == ["amazing", "awesome", "ole", "Процессор", "Эльбрус", "процессоры"]
  29
+      @product._keywords.should == ["amazing", "awesome", "ole", "процессор", "процессоры", "эльбрус"]
  30
+    end
  31
+
  32
+    it "should return results in search when case doesn't match" do
  33
+      Product.search("ЭЛЬБРУС").size.should == 1
30 34
     end
31 35
   end
32 36
 
4  spec/util_spec.rb
@@ -22,6 +22,10 @@
22 22
     Util.normalize_keywords("CaFé", false, "").should == ["cafe"]
23 23
   end
24 24
 
  25
+  it "should downcase utf-8 chars of the text passed" do
  26
+    Util.normalize_keywords("Кафе", false, "").should == ["кафе"]
  27
+  end
  28
+
25 29
   it "should split whitespaces, hifens, dots, underlines, etc.." do
26 30
     Util.normalize_keywords("CaFé-express.com delicious;come visit, and 'win' an \"iPad\"", false, "").should == ["cafe", "express", "com", "delicious", "come", "visit", "and", "win", "an", "ipad"]
27 31
   end

0 notes on commit 417e6dd

Please sign in to comment.
Something went wrong with that request. Please try again.