Created
January 22, 2019 16:46
-
-
Save ccocchi/a5201dcd70c07d5388799546e264fa7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
require 'benchmark/ips' | |
require 'oj' | |
require File.expand_path(File.join(File.dirname(__FILE__), 'config', 'environment')) | |
require 'elasticsearch-dsl' | |
class Official | |
include Elasticsearch::DSL | |
def result | |
definition = search do | |
query do | |
bool do | |
must do | |
match title: 'test' | |
end | |
must do | |
terms 'profile.cities' => ['FR_10', 'ES_10'] | |
end | |
end | |
end | |
end | |
definition.to_hash | |
end | |
end | |
class Ours | |
include ::QueryBuilding::Builder | |
def result | |
query do | |
bool do | |
match :title, 'test' | |
terms 'profile.cities', ['FR_10', 'ES_10'] | |
end | |
end | |
end | |
end | |
official = Official.new | |
ours = Ours.new | |
Benchmark.ips do |x| | |
x.report('official') do | |
official.result | |
end | |
x.report('ours') do | |
ours.result | |
end | |
x.compare! | |
end |
Author
ccocchi
commented
Jan 22, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment