Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #29 from semaperepelitsa/master

Downcase utf-8 chars of keywords
  • Loading branch information...
commit 417e6ddc1e4313617aa7f85fc252cad7b8bc750c 2 parents cf7914e + 639b6cc
@mauriciozaffari authored
View
37 Gemfile.lock
@@ -1,32 +1,35 @@
PATH
remote: .
specs:
- mongoid_search (0.2.6)
- bson_ext (~> 1.2)
+ mongoid_search (0.2.7)
+ bson_ext (>= 1.2)
fast-stemmer (~> 1.0.0)
- mongoid (~> 2.0.0)
+ mongoid (>= 2.0.0)
GEM
remote: http://rubygems.org/
specs:
- activemodel (3.0.9)
- activesupport (= 3.0.9)
- builder (~> 2.1.2)
- i18n (~> 0.5.0)
- activesupport (3.0.9)
- bson (1.3.1)
- bson_ext (1.3.1)
- builder (2.1.2)
+ activemodel (3.1.3)
+ activesupport (= 3.1.3)
+ builder (~> 3.0.0)
+ i18n (~> 0.6)
+ activesupport (3.1.3)
+ multi_json (~> 1.0)
+ bson (1.5.2)
+ bson_ext (1.5.2)
+ bson (= 1.5.2)
+ builder (3.0.0)
database_cleaner (0.6.7)
diff-lcs (1.1.2)
fast-stemmer (1.0.0)
- i18n (0.5.0)
- mongo (1.3.1)
- bson (>= 1.3.1)
- mongoid (2.0.2)
- activemodel (~> 3.0)
+ i18n (0.6.0)
+ mongo (1.5.2)
+ bson (= 1.5.2)
+ mongoid (2.3.4)
+ activemodel (~> 3.1)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
+ multi_json (1.0.4)
rake (0.8.7)
rspec (2.6.0)
rspec-core (~> 2.6.0)
@@ -39,7 +42,7 @@ GEM
simplecov (0.4.2)
simplecov-html (~> 0.4.4)
simplecov-html (0.4.5)
- tzinfo (0.3.29)
+ tzinfo (0.3.31)
PLATFORMS
ruby
View
2  lib/mongoid_search/util.rb
@@ -29,10 +29,10 @@ def self.normalize_keywords(text, stem_keywords, ignore_list)
text = text.to_s.
mb_chars.
normalize(:kd).
+ downcase.
to_s.
gsub(/[._:;'"`,?|+={}()!@#%^&*<>~\$\-\\\/\[\]]/, ' '). # strip punctuation
gsub(/[^[:alnum:]\s]/,''). # strip accents
- downcase.
split(' ').
reject { |word| word.size < 2 }
text = text.reject { |word| ignore_list.include?(word) } unless ignore_list.blank?
View
6 spec/mongoid_search_spec.rb
@@ -26,7 +26,11 @@
}
it "should leave utf8 characters" do
- @product._keywords.should == ["amazing", "awesome", "ole", "Процессор", "Эльбрус", "процессоры"]
+ @product._keywords.should == ["amazing", "awesome", "ole", "процессор", "процессоры", "эльбрус"]
+ end
+
+ it "should return results in search when case doesn't match" do
+ Product.search("ЭЛЬБРУС").size.should == 1
end
end
View
4 spec/util_spec.rb
@@ -22,6 +22,10 @@
Util.normalize_keywords("CaFé", false, "").should == ["cafe"]
end
+ it "should downcase utf-8 chars of the text passed" do
+ Util.normalize_keywords("Кафе", false, "").should == ["кафе"]
+ end
+
it "should split whitespaces, hifens, dots, underlines, etc.." do
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"]
end
Please sign in to comment.
Something went wrong with that request. Please try again.