searchkick 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/CONTRIBUTING.md +9 -7
  4. data/README.md +86 -24
  5. data/lib/searchkick/bulk_indexer.rb +1 -1
  6. data/lib/searchkick/index_options.rb +12 -0
  7. data/lib/searchkick/model.rb +2 -2
  8. data/lib/searchkick/query.rb +36 -21
  9. data/lib/searchkick/record_data.rb +2 -2
  10. data/lib/searchkick/results.rb +2 -2
  11. data/lib/searchkick/version.rb +1 -1
  12. metadata +8 -106
  13. data/.github/ISSUE_TEMPLATE.md +0 -7
  14. data/.gitignore +0 -22
  15. data/.travis.yml +0 -33
  16. data/Gemfile +0 -16
  17. data/Rakefile +0 -16
  18. data/benchmark/Gemfile +0 -24
  19. data/benchmark/index.rb +0 -99
  20. data/benchmark/search.rb +0 -48
  21. data/docs/Searchkick-3-Upgrade.md +0 -57
  22. data/searchkick.gemspec +0 -30
  23. data/test/aggs_test.rb +0 -217
  24. data/test/autocomplete_test.rb +0 -81
  25. data/test/boost_test.rb +0 -225
  26. data/test/callbacks_test.rb +0 -59
  27. data/test/ci/before_install.sh +0 -17
  28. data/test/errors_test.rb +0 -19
  29. data/test/gemfiles/activerecord42.gemfile +0 -7
  30. data/test/gemfiles/activerecord50.gemfile +0 -7
  31. data/test/gemfiles/activerecord51.gemfile +0 -7
  32. data/test/gemfiles/apartment.gemfile +0 -8
  33. data/test/gemfiles/cequel.gemfile +0 -8
  34. data/test/gemfiles/mongoid5.gemfile +0 -7
  35. data/test/gemfiles/mongoid6.gemfile +0 -12
  36. data/test/gemfiles/nobrainer.gemfile +0 -8
  37. data/test/gemfiles/parallel_tests.gemfile +0 -8
  38. data/test/geo_shape_test.rb +0 -171
  39. data/test/highlight_test.rb +0 -109
  40. data/test/index_test.rb +0 -168
  41. data/test/inheritance_test.rb +0 -82
  42. data/test/language_test.rb +0 -79
  43. data/test/marshal_test.rb +0 -13
  44. data/test/match_test.rb +0 -293
  45. data/test/misspellings_test.rb +0 -56
  46. data/test/model_test.rb +0 -40
  47. data/test/multi_search_test.rb +0 -37
  48. data/test/multi_tenancy_test.rb +0 -22
  49. data/test/order_test.rb +0 -40
  50. data/test/pagination_test.rb +0 -96
  51. data/test/partial_reindex_test.rb +0 -65
  52. data/test/query_test.rb +0 -43
  53. data/test/reindex_test.rb +0 -87
  54. data/test/reindex_v2_job_test.rb +0 -27
  55. data/test/routing_test.rb +0 -23
  56. data/test/should_index_test.rb +0 -32
  57. data/test/similar_test.rb +0 -28
  58. data/test/sql_test.rb +0 -190
  59. data/test/suggest_test.rb +0 -100
  60. data/test/support/kaminari.yml +0 -21
  61. data/test/synonyms_test.rb +0 -69
  62. data/test/test_helper.rb +0 -593
  63. data/test/where_test.rb +0 -249
@@ -1,593 +0,0 @@
1
- require "bundler/setup"
2
- Bundler.require(:default)
3
- require "minitest/autorun"
4
- require "minitest/pride"
5
- require "logger"
6
- require "active_support/core_ext" if defined?(NoBrainer)
7
- require "active_support/notifications"
8
-
9
- Searchkick.index_suffix = ENV["TEST_ENV_NUMBER"]
10
-
11
- ENV["RACK_ENV"] = "test"
12
-
13
- Minitest::Test = Minitest::Unit::TestCase unless defined?(Minitest::Test)
14
-
15
- if !defined?(ParallelTests) || ParallelTests.first_process?
16
- File.delete("elasticsearch.log") if File.exist?("elasticsearch.log")
17
- end
18
-
19
- Searchkick.client.transport.logger = Logger.new("elasticsearch.log")
20
- Searchkick.search_timeout = 5
21
-
22
- if defined?(Redis)
23
- if defined?(ConnectionPool)
24
- Searchkick.redis = ConnectionPool.new { Redis.new }
25
- else
26
- Searchkick.redis = Redis.new
27
- end
28
- end
29
-
30
- puts "Running against Elasticsearch #{Searchkick.server_version}"
31
-
32
- I18n.config.enforce_available_locales = true
33
-
34
- if defined?(ActiveJob)
35
- ActiveJob::Base.logger = nil
36
- ActiveJob::Base.queue_adapter = :inline
37
- end
38
-
39
- ActiveSupport::LogSubscriber.logger = ActiveSupport::Logger.new(STDOUT) if ENV["NOTIFICATIONS"]
40
-
41
- def nobrainer?
42
- defined?(NoBrainer)
43
- end
44
-
45
- def cequel?
46
- defined?(Cequel)
47
- end
48
-
49
- if defined?(Mongoid)
50
- Mongoid.logger.level = Logger::INFO
51
- Mongo::Logger.logger.level = Logger::INFO if defined?(Mongo::Logger)
52
-
53
- Mongoid.configure do |config|
54
- config.connect_to "searchkick_test"
55
- end
56
-
57
- class Product
58
- include Mongoid::Document
59
- include Mongoid::Timestamps
60
-
61
- field :name
62
- field :store_id, type: Integer
63
- field :in_stock, type: Boolean
64
- field :backordered, type: Boolean
65
- field :orders_count, type: Integer
66
- field :found_rate, type: BigDecimal
67
- field :price, type: Integer
68
- field :color
69
- field :latitude, type: BigDecimal
70
- field :longitude, type: BigDecimal
71
- field :description
72
- field :alt_description
73
- end
74
-
75
- class Store
76
- include Mongoid::Document
77
- has_many :products
78
-
79
- field :name
80
- end
81
-
82
- class Region
83
- include Mongoid::Document
84
-
85
- field :name
86
- field :text
87
- end
88
-
89
- class Speaker
90
- include Mongoid::Document
91
-
92
- field :name
93
- end
94
-
95
- class Animal
96
- include Mongoid::Document
97
-
98
- field :name
99
- end
100
-
101
- class Dog < Animal
102
- end
103
-
104
- class Cat < Animal
105
- end
106
-
107
- class Sku
108
- include Mongoid::Document
109
-
110
- field :name
111
- end
112
-
113
- class Song
114
- include Mongoid::Document
115
-
116
- field :name
117
- end
118
- elsif defined?(NoBrainer)
119
- NoBrainer.configure do |config|
120
- config.app_name = :searchkick
121
- config.environment = :test
122
- end
123
-
124
- class Product
125
- include NoBrainer::Document
126
- include NoBrainer::Document::Timestamps
127
-
128
- field :id, type: Object
129
- field :name, type: Text
130
- field :in_stock, type: Boolean
131
- field :backordered, type: Boolean
132
- field :orders_count, type: Integer
133
- field :found_rate
134
- field :price, type: Integer
135
- field :color, type: String
136
- field :latitude
137
- field :longitude
138
- field :description, type: String
139
- field :alt_description, type: String
140
-
141
- belongs_to :store, validates: false
142
- end
143
-
144
- class Store
145
- include NoBrainer::Document
146
-
147
- field :id, type: Object
148
- field :name, type: String
149
- end
150
-
151
- class Region
152
- include NoBrainer::Document
153
-
154
- field :id, type: Object
155
- field :name, type: String
156
- field :text, type: Text
157
- end
158
-
159
- class Speaker
160
- include NoBrainer::Document
161
-
162
- field :id, type: Object
163
- field :name, type: String
164
- end
165
-
166
- class Animal
167
- include NoBrainer::Document
168
-
169
- field :id, type: Object
170
- field :name, type: String
171
- end
172
-
173
- class Dog < Animal
174
- end
175
-
176
- class Cat < Animal
177
- end
178
-
179
- class Sku
180
- include NoBrainer::Document
181
-
182
- field :id, type: String
183
- field :name, type: String
184
- end
185
-
186
- class Song
187
- include NoBrainer::Document
188
-
189
- field :id, type: Object
190
- field :name, type: String
191
- end
192
- elsif defined?(Cequel)
193
- cequel =
194
- Cequel.connect(
195
- host: "127.0.0.1",
196
- port: 9042,
197
- keyspace: "searchkick_test",
198
- default_consistency: :all
199
- )
200
- # cequel.logger = ActiveSupport::Logger.new(STDOUT)
201
- cequel.schema.drop! if cequel.schema.exists?
202
- cequel.schema.create!
203
- Cequel::Record.connection = cequel
204
-
205
- class Product
206
- include Cequel::Record
207
-
208
- key :id, :uuid, auto: true
209
- column :name, :text, index: true
210
- column :store_id, :int
211
- column :in_stock, :boolean
212
- column :backordered, :boolean
213
- column :orders_count, :int
214
- column :found_rate, :decimal
215
- column :price, :int
216
- column :color, :text
217
- column :latitude, :decimal
218
- column :longitude, :decimal
219
- column :description, :text
220
- column :alt_description, :text
221
- column :created_at, :timestamp
222
- end
223
-
224
- class Store
225
- include Cequel::Record
226
-
227
- key :id, :timeuuid, auto: true
228
- column :name, :text
229
-
230
- # has issue with id serialization
231
- def search_data
232
- {
233
- name: name
234
- }
235
- end
236
- end
237
-
238
- class Region
239
- include Cequel::Record
240
-
241
- key :id, :timeuuid, auto: true
242
- column :name, :text
243
- column :text, :text
244
- end
245
-
246
- class Speaker
247
- include Cequel::Record
248
-
249
- key :id, :timeuuid, auto: true
250
- column :name, :text
251
- end
252
-
253
- class Animal
254
- include Cequel::Record
255
-
256
- key :id, :timeuuid, auto: true
257
- column :name, :text
258
-
259
- # has issue with id serialization
260
- def search_data
261
- {
262
- name: name
263
- }
264
- end
265
- end
266
-
267
- class Dog < Animal
268
- end
269
-
270
- class Cat < Animal
271
- end
272
-
273
- class Sku
274
- include Cequel::Record
275
-
276
- key :id, :uuid
277
- column :name, :text
278
- end
279
-
280
- class Song
281
- include Cequel::Record
282
-
283
- key :id, :timeuuid, auto: true
284
- column :name, :text
285
- end
286
-
287
- [Product, Store, Region, Speaker, Animal, Sku, Song].each(&:synchronize_schema)
288
- else
289
- require "active_record"
290
-
291
- # for debugging
292
- # ActiveRecord::Base.logger = Logger.new(STDOUT)
293
-
294
- # rails does this in activerecord/lib/active_record/railtie.rb
295
- ActiveRecord::Base.default_timezone = :utc
296
- ActiveRecord::Base.time_zone_aware_attributes = true
297
-
298
- # migrations
299
- ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
300
-
301
- ActiveRecord::Base.raise_in_transactional_callbacks = true if ActiveRecord::VERSION::STRING.start_with?("4.2.")
302
-
303
- if defined?(Apartment)
304
- class Rails
305
- def self.env
306
- ENV["RACK_ENV"]
307
- end
308
- end
309
-
310
- tenants = ["tenant1", "tenant2"]
311
- Apartment.configure do |config|
312
- config.tenant_names = tenants
313
- config.database_schema_file = false
314
- config.excluded_models = ["Product", "Store", "Animal", "Dog", "Cat"]
315
- end
316
-
317
- class Tenant < ActiveRecord::Base
318
- searchkick index_prefix: -> { Apartment::Tenant.current }
319
- end
320
-
321
- tenants.each do |tenant|
322
- begin
323
- Apartment::Tenant.create(tenant)
324
- rescue Apartment::TenantExists
325
- # do nothing
326
- end
327
- Apartment::Tenant.switch!(tenant)
328
-
329
- ActiveRecord::Migration.create_table :tenants, force: true do |t|
330
- t.string :name
331
- t.timestamps null: true
332
- end
333
-
334
- Tenant.reindex
335
- end
336
-
337
- Apartment::Tenant.reset
338
- end
339
-
340
- ActiveRecord::Migration.create_table :products do |t|
341
- t.string :name
342
- t.integer :store_id
343
- t.boolean :in_stock
344
- t.boolean :backordered
345
- t.integer :orders_count
346
- t.decimal :found_rate
347
- t.integer :price
348
- t.string :color
349
- t.decimal :latitude, precision: 10, scale: 7
350
- t.decimal :longitude, precision: 10, scale: 7
351
- t.text :description
352
- t.text :alt_description
353
- t.timestamps null: true
354
- end
355
-
356
- ActiveRecord::Migration.create_table :stores do |t|
357
- t.string :name
358
- end
359
-
360
- ActiveRecord::Migration.create_table :regions do |t|
361
- t.string :name
362
- t.text :text
363
- end
364
-
365
- ActiveRecord::Migration.create_table :speakers do |t|
366
- t.string :name
367
- end
368
-
369
- ActiveRecord::Migration.create_table :animals do |t|
370
- t.string :name
371
- t.string :type
372
- end
373
-
374
- ActiveRecord::Migration.create_table :skus, id: :uuid do |t|
375
- t.string :name
376
- end
377
-
378
- ActiveRecord::Migration.create_table :songs do |t|
379
- t.string :name
380
- end
381
-
382
- class Product < ActiveRecord::Base
383
- belongs_to :store
384
- end
385
-
386
- class Store < ActiveRecord::Base
387
- has_many :products
388
- end
389
-
390
- class Region < ActiveRecord::Base
391
- end
392
-
393
- class Speaker < ActiveRecord::Base
394
- end
395
-
396
- class Animal < ActiveRecord::Base
397
- end
398
-
399
- class Dog < Animal
400
- end
401
-
402
- class Cat < Animal
403
- end
404
-
405
- class Sku < ActiveRecord::Base
406
- end
407
-
408
- class Song < ActiveRecord::Base
409
- end
410
- end
411
-
412
- class Product
413
- searchkick \
414
- synonyms: [
415
- ["clorox", "bleach"],
416
- ["scallion", "greenonion"],
417
- ["saran wrap", "plastic wrap"],
418
- ["qtip", "cottonswab"],
419
- ["burger", "hamburger"],
420
- ["bandaid", "bandag"],
421
- ["UPPERCASE", "lowercase"],
422
- "lightbulb => led,lightbulb",
423
- "lightbulb => halogenlamp"
424
- ],
425
- suggest: [:name, :color],
426
- conversions: [:conversions],
427
- locations: [:location, :multiple_locations],
428
- text_start: [:name],
429
- text_middle: [:name],
430
- text_end: [:name],
431
- word_start: [:name],
432
- word_middle: [:name],
433
- word_end: [:name],
434
- highlight: [:name],
435
- filterable: [:name, :color, :description],
436
- similarity: "BM25",
437
- match: ENV["MATCH"] ? ENV["MATCH"].to_sym : nil
438
-
439
- attr_accessor :conversions, :user_ids, :aisle, :details
440
-
441
- def search_data
442
- serializable_hash.except("id", "_id").merge(
443
- conversions: conversions,
444
- user_ids: user_ids,
445
- location: {lat: latitude, lon: longitude},
446
- multiple_locations: [{lat: latitude, lon: longitude}, {lat: 0, lon: 0}],
447
- aisle: aisle,
448
- details: details
449
- )
450
- end
451
-
452
- def should_index?
453
- name != "DO NOT INDEX"
454
- end
455
-
456
- def search_name
457
- {
458
- name: name
459
- }
460
- end
461
- end
462
-
463
- class Store
464
- searchkick \
465
- routing: true,
466
- merge_mappings: true,
467
- mappings: {
468
- store: {
469
- properties: {
470
- name: {type: "keyword"}
471
- }
472
- }
473
- }
474
-
475
- def search_document_id
476
- id
477
- end
478
-
479
- def search_routing
480
- name
481
- end
482
- end
483
-
484
- class Region
485
- searchkick \
486
- geo_shape: {
487
- territory: {tree: "quadtree", precision: "10km"}
488
- }
489
-
490
- attr_accessor :territory
491
-
492
- def search_data
493
- {
494
- name: name,
495
- text: text,
496
- territory: territory
497
- }
498
- end
499
- end
500
-
501
- class Speaker
502
- searchkick \
503
- conversions: ["conversions_a", "conversions_b"]
504
-
505
- attr_accessor :conversions_a, :conversions_b, :aisle
506
-
507
- def search_data
508
- serializable_hash.except("id", "_id").merge(
509
- conversions_a: conversions_a,
510
- conversions_b: conversions_b,
511
- aisle: aisle
512
- )
513
- end
514
- end
515
-
516
- class Animal
517
- searchkick \
518
- inheritance: true,
519
- text_start: [:name],
520
- suggest: [:name],
521
- index_name: -> { "#{name.tableize}-#{Date.today.year}#{Searchkick.index_suffix}" },
522
- callbacks: defined?(ActiveJob) ? :async : true
523
- # wordnet: true
524
- end
525
-
526
- class Sku
527
- searchkick callbacks: defined?(ActiveJob) ? :async : true
528
- end
529
-
530
- class Song
531
- searchkick
532
- end
533
-
534
- Product.searchkick_index.delete if Product.searchkick_index.exists?
535
- Product.reindex
536
- Product.reindex # run twice for both index paths
537
- Product.create!(name: "Set mapping")
538
-
539
- Store.reindex
540
- Animal.reindex
541
- Speaker.reindex
542
- Region.reindex
543
-
544
- class Minitest::Test
545
- def setup
546
- Product.destroy_all
547
- Store.destroy_all
548
- Animal.destroy_all
549
- Speaker.destroy_all
550
- end
551
-
552
- protected
553
-
554
- def store(documents, klass = Product)
555
- documents.shuffle.each do |document|
556
- klass.create!(document)
557
- end
558
- klass.searchkick_index.refresh
559
- end
560
-
561
- def store_names(names, klass = Product)
562
- store names.map { |name| {name: name} }, klass
563
- end
564
-
565
- # no order
566
- def assert_search(term, expected, options = {}, klass = Product)
567
- assert_equal expected.sort, klass.search(term, options).map(&:name).sort
568
- end
569
-
570
- def assert_order(term, expected, options = {}, klass = Product)
571
- assert_equal expected, klass.search(term, options).map(&:name)
572
- end
573
-
574
- def assert_equal_scores(term, options = {}, klass = Product)
575
- assert_equal 1, klass.search(term, options).hits.map { |a| a["_score"] }.uniq.size
576
- end
577
-
578
- def assert_first(term, expected, options = {}, klass = Product)
579
- assert_equal expected, klass.search(term, options).map(&:name).first
580
- end
581
-
582
- def with_options(klass, options)
583
- previous_options = klass.searchkick_options.dup
584
- begin
585
- klass.searchkick_options.merge!(options)
586
- klass.reindex
587
- yield
588
- ensure
589
- klass.searchkick_options.clear
590
- klass.searchkick_options.merge!(previous_options)
591
- end
592
- end
593
- end