test/test_helper.rb in searchkick-2.5.0 vs test/test_helper.rb in searchkick-3.0.0
- old
+ new
@@ -36,22 +36,10 @@
ActiveJob::Base.queue_adapter = :inline
end
ActiveSupport::LogSubscriber.logger = ActiveSupport::Logger.new(STDOUT) if ENV["NOTIFICATIONS"]
-def elasticsearch_below50?
- Searchkick.server_below?("5.0.0-alpha1")
-end
-
-def elasticsearch_below60?
- Searchkick.server_below?("6.0.0-alpha1")
-end
-
-def elasticsearch_below22?
- Searchkick.server_below?("2.2.0")
-end
-
def nobrainer?
defined?(NoBrainer)
end
def cequel?
@@ -119,10 +107,16 @@
class Sku
include Mongoid::Document
field :name
end
+
+ class Song
+ include Mongoid::Document
+
+ field :name
+ end
elsif defined?(NoBrainer)
NoBrainer.configure do |config|
config.app_name = :searchkick
config.environment = :test
end
@@ -130,11 +124,11 @@
class Product
include NoBrainer::Document
include NoBrainer::Document::Timestamps
field :id, type: Object
- field :name, type: String
+ field :name, type: Text
field :in_stock, type: Boolean
field :backordered, type: Boolean
field :orders_count, type: Integer
field :found_rate
field :price, type: Integer
@@ -186,10 +180,17 @@
include NoBrainer::Document
field :id, type: String
field :name, type: String
end
+
+ class Song
+ include NoBrainer::Document
+
+ field :id, type: Object
+ field :name, type: String
+ end
elsif defined?(Cequel)
cequel =
Cequel.connect(
host: "127.0.0.1",
port: 9042,
@@ -274,11 +275,18 @@
key :id, :uuid
column :name, :text
end
- [Product, Store, Region, Speaker, Animal].each(&:synchronize_schema)
+ class Song
+ include Cequel::Record
+
+ key :id, :timeuuid, auto: true
+ column :name, :text
+ end
+
+ [Product, Store, Region, Speaker, Animal, Sku, Song].each(&:synchronize_schema)
else
require "active_record"
# for debugging
# ActiveRecord::Base.logger = Logger.new(STDOUT)
@@ -365,10 +373,14 @@
ActiveRecord::Migration.create_table :skus, id: :uuid do |t|
t.string :name
end
+ ActiveRecord::Migration.create_table :songs do |t|
+ t.string :name
+ end
+
class Product < ActiveRecord::Base
belongs_to :store
end
class Store < ActiveRecord::Base
@@ -390,10 +402,13 @@
class Cat < Animal
end
class Sku < ActiveRecord::Base
end
+
+ class Song < ActiveRecord::Base
+ end
end
class Product
searchkick \
synonyms: [
@@ -415,19 +430,18 @@
text_end: [:name],
word_start: [:name],
word_middle: [:name],
word_end: [:name],
highlight: [:name],
- searchable: [:name, :color],
filterable: [:name, :color, :description],
similarity: "BM25",
match: ENV["MATCH"] ? ENV["MATCH"].to_sym : nil
attr_accessor :conversions, :user_ids, :aisle, :details
def search_data
- serializable_hash.except("id").merge(
+ serializable_hash.except("id", "_id").merge(
conversions: conversions,
user_ids: user_ids,
location: {lat: latitude, lon: longitude},
multiple_locations: [{lat: latitude, lon: longitude}, {lat: 0, lon: 0}],
aisle: aisle,
@@ -446,17 +460,16 @@
end
end
class Store
searchkick \
- default_fields: elasticsearch_below60? ? nil : [:name],
routing: true,
merge_mappings: true,
mappings: {
store: {
properties: {
- name: elasticsearch_below50? ? {type: "string", analyzer: "keyword"} : {type: "keyword"}
+ name: {type: "keyword"}
}
}
}
def search_document_id
@@ -468,11 +481,10 @@
end
end
class Region
searchkick \
- default_fields: elasticsearch_below60? ? nil : [:name],
geo_shape: {
territory: {tree: "quadtree", precision: "10km"}
}
attr_accessor :territory
@@ -486,36 +498,38 @@
end
end
class Speaker
searchkick \
- default_fields: elasticsearch_below60? ? nil : [:name],
conversions: ["conversions_a", "conversions_b"]
attr_accessor :conversions_a, :conversions_b, :aisle
def search_data
- serializable_hash.except("id").merge(
+ serializable_hash.except("id", "_id").merge(
conversions_a: conversions_a,
conversions_b: conversions_b,
aisle: aisle
)
end
end
class Animal
searchkick \
- default_fields: elasticsearch_below60? ? nil : [:name],
- inheritance: !elasticsearch_below60?,
+ inheritance: true,
text_start: [:name],
suggest: [:name],
index_name: -> { "#{name.tableize}-#{Date.today.year}#{Searchkick.index_suffix}" },
callbacks: defined?(ActiveJob) ? :async : true
# wordnet: true
end
class Sku
searchkick callbacks: defined?(ActiveJob) ? :async : true
+end
+
+class Song
+ searchkick language: "chinese"
end
Product.searchkick_index.delete if Product.searchkick_index.exists?
Product.reindex
Product.reindex # run twice for both index paths