From b5f09f1c9416da989987a69250dd72a190343eb9 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Thu, 5 Nov 2015 20:03:16 -0800 Subject: [PATCH] Added emoji search --- CHANGELOG.md | 1 + Gemfile | 1 + README.md | 16 ++++++++++++++++ lib/searchkick/query.rb | 4 ++++ test/match_test.rb | 12 ++++++++++++ 5 files changed, 34 insertions(+), 0 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2e2e22..47f9853 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Added aggregations method to get raw response - Use `execute: false` for lazy loading - Return nil when no aggs +- Added emoji search ## 1.0.0 diff --git a/Gemfile b/Gemfile index 2f782b5..82d1470 100644 --- a/Gemfile +++ b/Gemfile @@ -5,3 +5,4 @@ gemspec gem "sqlite3" gem "activerecord", "~> 4.2.0" +gem "gemoji-parser" diff --git a/README.md b/README.md index deeb14e..e360751 100644 --- a/README.md +++ b/README.md @@ -315,6 +315,22 @@ Or turn off misspellings with: Product.search "zuchini", misspellings: false # no zucchini ``` +### Emoji [master] + +Make :ice_cream::cake: match `ice cream cake`! + +Add this line to your application’s Gemfile: + +```ruby +gem 'gemoji-parser' +``` + +And use: + +```ruby +Product.search "[emoji go here]", emoji: true +``` + ### Indexing Control what data is indexed with the `search_data` method. Call `Product.reindex` after changing this method. diff --git a/lib/searchkick/query.rb b/lib/searchkick/query.rb index bfad1c2..694f46c 100644 --- a/lib/searchkick/query.rb +++ b/lib/searchkick/query.rb @@ -15,6 +15,10 @@ module Searchkick term = term.to_s end + if options[:emoji] + term = EmojiParser.parse_unicode(term) { |e| " #{e.name} " }.strip + end + @klass = klass @term = term @options = options diff --git a/test/match_test.rb b/test/match_test.rb index d17e157..b018455 100644 --- a/test/match_test.rb +++ b/test/match_test.rb @@ -197,4 +197,16 @@ class MatchTest < Minitest::Test ] assert_search "almond", [] end + + def test_emoji + skip unless defined?(EmojiParser) + store_names ["Banana"] + assert_search "🍌", ["Banana"], emoji: true + end + + def test_emoji_multiple + skip unless defined?(EmojiParser) + store_names ["Ice Cream Cake"] + assert_search "🍨🍰", ["Ice Cream Cake"], emoji: true + end end -- libgit2 0.21.0