Sha256: 6a2b2d81cc7d8b1ae3faf9641055dccf64d431ded2f831d90ebc1aac785306e5

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

require "bundler/setup"
Bundler.require(:default)
require "active_record"
require "benchmark/ips"

ActiveRecord::Base.default_timezone = :utc
ActiveRecord::Base.time_zone_aware_attributes = true
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: "/tmp/searchkick"

class Product < ActiveRecord::Base
  searchkick batch_size: 1000

  def search_data
    {
      name: name,
      color: color,
      store_id: store_id
    }
  end
end

if ENV["SETUP"]
  total_docs = 1000000

  ActiveRecord::Migration.create_table :products, force: :cascade do |t|
    t.string :name
    t.string :color
    t.integer :store_id
  end

  Product.import ["name", "color", "store_id"], total_docs.times.map { |i| ["Product #{i}", ["red", "blue"].sample, rand(10)] }

  puts "Imported"

  Product.reindex

  puts "Reindexed"
end

query = Product.search("product", fields: [:name], where: {color: "red", store_id: 5}, limit: 10000, load: false, execute: false)

require "pp"
pp query.body.as_json
puts

Benchmark.ips do |x|
  x.report { query.dup.execute }
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
searchkick-3.1.0 benchmark/search.rb
searchkick-3.0.3 benchmark/search.rb
searchkick_evichat-0.0.2 benchmark/search.rb
searchkick-3.0.2 benchmark/search.rb
searchkick-3.0.1 benchmark/search.rb
searchkick-3.0.0 benchmark/search.rb