searchkick 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Searchkick
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
data/test/aggs_test.rb CHANGED
@@ -30,6 +30,10 @@ class AggsTest < Minitest::Test
30
30
  assert_equal ({1 => 1, 2 => 2}), store_agg({aggs: {store_id_new: {field: "store_id"}}}, "store_id_new")
31
31
  end
32
32
 
33
+ def test_min_doc_count
34
+ assert_equal ({2 => 2}), store_agg(aggs: {store_id: {min_doc_count: 2}})
35
+ end
36
+
33
37
  def test_no_aggs
34
38
  assert_nil Product.search("*").aggs
35
39
  end
@@ -3,8 +3,12 @@
3
3
  gem install bundler
4
4
 
5
5
  sudo apt-get purge elasticsearch
6
- wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.7.3.deb
7
- sudo dpkg -i elasticsearch-1.7.3.deb
6
+ if [[ $ELASTICSEARCH_VERSION == 1* ]]; then
7
+ wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-$ELASTICSEARCH_VERSION.deb
8
+ else
9
+ wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/$ELASTICSEARCH_VERSION/elasticsearch-$ELASTICSEARCH_VERSION.deb
10
+ fi
11
+ sudo dpkg -i elasticsearch-$ELASTICSEARCH_VERSION.deb
8
12
  sudo service elasticsearch start
9
13
 
10
14
  if [ -n "$NOBRAINER" ]; then
data/test/facets_test.rb CHANGED
@@ -2,7 +2,7 @@ require_relative "test_helper"
2
2
 
3
3
  class FacetsTest < Minitest::Test
4
4
  def setup
5
- skip if elasticsearch2?
5
+ skip unless elasticsearch_below20?
6
6
  super
7
7
  store [
8
8
  {name: "Product Show", latitude: 37.7833, longitude: 12.4167, store_id: 1, in_stock: true, color: "blue", price: 21, created_at: 2.days.ago},
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in searchkick.gemspec
4
+ gemspec path: "../../"
5
+
6
+ gem "sqlite3"
7
+ gem "activerecord", "~> 4.2.0"
8
+ gem "apartment"
data/test/match_test.rb CHANGED
@@ -110,12 +110,14 @@ class MatchTest < Minitest::Test
110
110
  end
111
111
 
112
112
  def test_misspelling_zucchini_transposition
113
+ skip if elasticsearch_below14?
113
114
  store_names ["zucchini"]
114
115
  assert_search "zuccihni", ["zucchini"]
115
116
  assert_search "zuccihni", [], misspellings: {transpositions: false}
116
117
  end
117
118
 
118
119
  def test_misspelling_lasagna
120
+ skip if elasticsearch_below14?
119
121
  store_names ["lasagna"]
120
122
  assert_search "lasanga", ["lasagna"], misspellings: {transpositions: true}
121
123
  assert_search "lasgana", ["lasagna"], misspellings: {transpositions: true}
@@ -124,6 +126,7 @@ class MatchTest < Minitest::Test
124
126
  end
125
127
 
126
128
  def test_misspelling_lasagna_pasta
129
+ skip if elasticsearch_below14?
127
130
  store_names ["lasagna pasta"]
128
131
  assert_search "lasanga", ["lasagna pasta"], misspellings: {transpositions: true}
129
132
  assert_search "lasanga pasta", ["lasagna pasta"], misspellings: {transpositions: true}
@@ -191,6 +194,11 @@ class MatchTest < Minitest::Test
191
194
  assert_search "ben & jerrys", ["Ben and Jerry's"]
192
195
  end
193
196
 
197
+ def test_phrase
198
+ store_names ["Fresh Honey", "Honey Fresh"]
199
+ assert_search "fresh honey", ["Fresh Honey"], match: :phrase
200
+ end
201
+
194
202
  def test_unsearchable
195
203
  store [
196
204
  {name: "Unsearchable", description: "Almond"}
@@ -0,0 +1,22 @@
1
+ require_relative "test_helper"
2
+
3
+ class MultiTenancyTest < Minitest::Test
4
+ def setup
5
+ skip unless defined?(Apartment)
6
+ end
7
+
8
+ def test_basic
9
+ Apartment::Tenant.switch!("tenant1")
10
+ store_names ["Product A"], Tenant
11
+ Apartment::Tenant.switch!("tenant2")
12
+ store_names ["Product B"], Tenant
13
+ Apartment::Tenant.switch!("tenant1")
14
+ assert_search "product", ["Product A"], {load: false}, Tenant
15
+ Apartment::Tenant.switch!("tenant2")
16
+ assert_search "product", ["Product B"], {load: false}, Tenant
17
+ end
18
+
19
+ def teardown
20
+ Apartment::Tenant.reset if defined?(Apartment)
21
+ end
22
+ end
data/test/order_test.rb CHANGED
@@ -28,9 +28,15 @@ class OrderTest < Minitest::Test
28
28
  end
29
29
 
30
30
  def test_order_ignore_unmapped
31
+ skip unless elasticsearch_below50?
31
32
  assert_order "product", [], order: {not_mapped: {ignore_unmapped: true}}
32
33
  end
33
34
 
35
+ def test_order_unmapped_type
36
+ skip if elasticsearch_below50?
37
+ assert_order "product", [], order: {not_mapped: {unmapped_type: "long"}}
38
+ end
39
+
34
40
  def test_order_array
35
41
  store [{name: "San Francisco", latitude: 37.7833, longitude: -122.4167}]
36
42
  assert_order "francisco", ["San Francisco"], order: [{_geo_distance: {location: "0,0"}}]
data/test/sql_test.rb CHANGED
@@ -77,6 +77,7 @@ class SqlTest < Minitest::Test
77
77
  # select
78
78
 
79
79
  def test_select
80
+ skip unless elasticsearch_below50?
80
81
  store [{name: "Product A", store_id: 1}]
81
82
  result = Product.search("product", load: false, select: [:name, :store_id]).first
82
83
  assert_equal %w(id name store_id), result.keys.reject { |k| k.start_with?("_") }.sort
@@ -85,12 +86,14 @@ class SqlTest < Minitest::Test
85
86
  end
86
87
 
87
88
  def test_select_array
89
+ skip unless elasticsearch_below50?
88
90
  store [{name: "Product A", user_ids: [1, 2]}]
89
91
  result = Product.search("product", load: false, select: [:user_ids]).first
90
92
  assert_equal [1, 2], result.user_ids
91
93
  end
92
94
 
93
95
  def test_select_single_field
96
+ skip unless elasticsearch_below50?
94
97
  store [{name: "Product A", store_id: 1}]
95
98
  result = Product.search("product", load: false, select: :name).first
96
99
  assert_equal %w(id name), result.keys.reject { |k| k.start_with?("_") }.sort
@@ -99,6 +102,7 @@ class SqlTest < Minitest::Test
99
102
  end
100
103
 
101
104
  def test_select_all
105
+ skip unless elasticsearch_below50?
102
106
  store [{name: "Product A", user_ids: [1, 2]}]
103
107
  hit = Product.search("product", select: true).hits.first
104
108
  assert_equal hit["_source"]["name"], "Product A"
@@ -106,6 +110,7 @@ class SqlTest < Minitest::Test
106
110
  end
107
111
 
108
112
  def test_select_none
113
+ skip unless elasticsearch_below50?
109
114
  store [{name: "Product A", user_ids: [1, 2]}]
110
115
  hit = Product.search("product", select: []).hits.first
111
116
  assert_nil hit["_source"]
data/test/test_helper.rb CHANGED
@@ -21,8 +21,16 @@ I18n.config.enforce_available_locales = true
21
21
  ActiveJob::Base.logger = nil if defined?(ActiveJob)
22
22
  ActiveSupport::LogSubscriber.logger = Logger.new(STDOUT) if ENV["NOTIFICATIONS"]
23
23
 
24
- def elasticsearch2?
25
- Searchkick.server_version.starts_with?("2.")
24
+ def elasticsearch_below50?
25
+ Searchkick.server_below?("5.0.0-alpha1")
26
+ end
27
+
28
+ def elasticsearch_below20?
29
+ Searchkick.server_below?("2.0.0")
30
+ end
31
+
32
+ def elasticsearch_below14?
33
+ Searchkick.server_below?("1.4.0")
26
34
  end
27
35
 
28
36
  def mongoid2?
@@ -156,6 +164,43 @@ else
156
164
 
157
165
  ActiveRecord::Base.raise_in_transactional_callbacks = true if ActiveRecord::Base.respond_to?(:raise_in_transactional_callbacks=)
158
166
 
167
+ if defined?(Apartment)
168
+ class Rails
169
+ def self.env
170
+ ENV["RACK_ENV"]
171
+ end
172
+ end
173
+
174
+ tenants = ["tenant1", "tenant2"]
175
+ Apartment.configure do |config|
176
+ config.tenant_names = tenants
177
+ config.database_schema_file = false
178
+ config.excluded_models = ["Product", "Store", "Animal", "Dog", "Cat"]
179
+ end
180
+
181
+ class Tenant < ActiveRecord::Base
182
+ searchkick index_prefix: -> { Apartment::Tenant.current }
183
+ end
184
+
185
+ tenants.each do |tenant|
186
+ begin
187
+ Apartment::Tenant.create(tenant)
188
+ rescue Apartment::TenantExists
189
+ # do nothing
190
+ end
191
+ Apartment::Tenant.switch!(tenant)
192
+
193
+ ActiveRecord::Migration.create_table :tenants, force: true do |t|
194
+ t.string :name
195
+ t.timestamps null: true
196
+ end
197
+
198
+ Tenant.reindex
199
+ end
200
+
201
+ Apartment::Tenant.reset
202
+ end
203
+
159
204
  ActiveRecord::Migration.create_table :products do |t|
160
205
  t.string :name
161
206
  t.integer :store_id
@@ -251,7 +296,7 @@ class Store
251
296
  mappings: {
252
297
  store: {
253
298
  properties: {
254
- name: {type: "string", analyzer: "keyword"}
299
+ name: elasticsearch_below50? ? {type: "string", analyzer: "keyword"} : {type: "keyword"}
255
300
  }
256
301
  }
257
302
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchkick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -131,6 +131,7 @@ files:
131
131
  - test/gemfiles/activerecord32.gemfile
132
132
  - test/gemfiles/activerecord40.gemfile
133
133
  - test/gemfiles/activerecord41.gemfile
134
+ - test/gemfiles/apartment.gemfile
134
135
  - test/gemfiles/mongoid2.gemfile
135
136
  - test/gemfiles/mongoid3.gemfile
136
137
  - test/gemfiles/mongoid4.gemfile
@@ -143,6 +144,7 @@ files:
143
144
  - test/misspellings_test.rb
144
145
  - test/model_test.rb
145
146
  - test/multi_search_test.rb
147
+ - test/multi_tenancy_test.rb
146
148
  - test/order_test.rb
147
149
  - test/pagination_test.rb
148
150
  - test/query_test.rb
@@ -177,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
179
  version: '0'
178
180
  requirements: []
179
181
  rubyforge_project:
180
- rubygems_version: 2.4.5.1
182
+ rubygems_version: 2.6.1
181
183
  signing_key:
182
184
  specification_version: 4
183
185
  summary: Searchkick learns what your users are looking for. As more people search,
@@ -195,6 +197,7 @@ test_files:
195
197
  - test/gemfiles/activerecord32.gemfile
196
198
  - test/gemfiles/activerecord40.gemfile
197
199
  - test/gemfiles/activerecord41.gemfile
200
+ - test/gemfiles/apartment.gemfile
198
201
  - test/gemfiles/mongoid2.gemfile
199
202
  - test/gemfiles/mongoid3.gemfile
200
203
  - test/gemfiles/mongoid4.gemfile
@@ -207,6 +210,7 @@ test_files:
207
210
  - test/misspellings_test.rb
208
211
  - test/model_test.rb
209
212
  - test/multi_search_test.rb
213
+ - test/multi_tenancy_test.rb
210
214
  - test/order_test.rb
211
215
  - test/pagination_test.rb
212
216
  - test/query_test.rb