chewy 0.5.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +26 -4
  3. data/CHANGELOG.md +16 -0
  4. data/Gemfile +3 -1
  5. data/README.md +2 -10
  6. data/chewy.gemspec +0 -1
  7. data/gemfiles/Gemfile.rails-3.2.active_record +6 -0
  8. data/gemfiles/Gemfile.rails-3.2.active_record.kaminari +7 -0
  9. data/gemfiles/Gemfile.rails-3.2.active_record.will_paginate +7 -0
  10. data/gemfiles/Gemfile.rails-4.0.active_record +6 -0
  11. data/gemfiles/Gemfile.rails-4.0.active_record.kaminari +7 -0
  12. data/gemfiles/Gemfile.rails-4.0.active_record.will_paginate +7 -0
  13. data/gemfiles/Gemfile.rails-4.0.mongoid +6 -0
  14. data/gemfiles/Gemfile.rails-4.0.mongoid.kaminari +7 -0
  15. data/gemfiles/Gemfile.rails-4.0.mongoid.will_paginate +7 -0
  16. data/gemfiles/Gemfile.rails-4.1.active_record +6 -0
  17. data/gemfiles/Gemfile.rails-4.1.active_record.kaminari +7 -0
  18. data/gemfiles/Gemfile.rails-4.1.active_record.will_paginate +7 -0
  19. data/gemfiles/Gemfile.rails-4.1.mongoid +6 -0
  20. data/gemfiles/Gemfile.rails-4.1.mongoid.kaminari +7 -0
  21. data/gemfiles/Gemfile.rails-4.1.mongoid.will_paginate +7 -0
  22. data/gemfiles/Gemfile.rails-4.2.active_record +6 -0
  23. data/gemfiles/Gemfile.rails-4.2.active_record.kaminari +7 -0
  24. data/gemfiles/Gemfile.rails-4.2.active_record.will_paginate +7 -0
  25. data/gemfiles/Gemfile.rails-4.2.mongoid +6 -0
  26. data/gemfiles/Gemfile.rails-4.2.mongoid.kaminari +7 -0
  27. data/gemfiles/Gemfile.rails-4.2.mongoid.will_paginate +7 -0
  28. data/lib/chewy.rb +33 -5
  29. data/lib/chewy/config.rb +1 -0
  30. data/lib/chewy/index/search.rb +6 -3
  31. data/lib/chewy/query.rb +74 -1
  32. data/lib/chewy/query/compose.rb +4 -4
  33. data/lib/chewy/query/pagination.rb +5 -4
  34. data/lib/chewy/query/pagination/kaminari.rb +1 -1
  35. data/lib/chewy/query/pagination/will_paginate.rb +27 -0
  36. data/lib/chewy/type.rb +1 -0
  37. data/lib/chewy/type/adapter/active_record.rb +2 -2
  38. data/lib/chewy/type/adapter/mongoid.rb +147 -0
  39. data/lib/chewy/type/adapter/object.rb +1 -1
  40. data/lib/chewy/type/import.rb +1 -0
  41. data/lib/chewy/type/observe.rb +34 -6
  42. data/lib/chewy/version.rb +1 -1
  43. data/spec/chewy/config_spec.rb +17 -17
  44. data/spec/chewy/fields/base_spec.rb +62 -62
  45. data/spec/chewy/fields/root_spec.rb +5 -5
  46. data/spec/chewy/index/actions_spec.rb +127 -127
  47. data/spec/chewy/index/aliases_spec.rb +9 -9
  48. data/spec/chewy/index/search_spec.rb +4 -4
  49. data/spec/chewy/index/settings_spec.rb +33 -33
  50. data/spec/chewy/index_spec.rb +49 -49
  51. data/spec/chewy/query/criteria_spec.rb +173 -161
  52. data/spec/chewy/query/filters_spec.rb +76 -76
  53. data/spec/chewy/query/loading_spec.rb +54 -23
  54. data/spec/chewy/query/nodes/and_spec.rb +4 -4
  55. data/spec/chewy/query/nodes/bool_spec.rb +8 -8
  56. data/spec/chewy/query/nodes/equal_spec.rb +19 -19
  57. data/spec/chewy/query/nodes/exists_spec.rb +6 -6
  58. data/spec/chewy/query/nodes/has_child_spec.rb +25 -25
  59. data/spec/chewy/query/nodes/has_parent_spec.rb +25 -25
  60. data/spec/chewy/query/nodes/match_all_spec.rb +1 -1
  61. data/spec/chewy/query/nodes/missing_spec.rb +4 -4
  62. data/spec/chewy/query/nodes/not_spec.rb +4 -4
  63. data/spec/chewy/query/nodes/or_spec.rb +4 -4
  64. data/spec/chewy/query/nodes/prefix_spec.rb +5 -5
  65. data/spec/chewy/query/nodes/query_spec.rb +2 -2
  66. data/spec/chewy/query/nodes/range_spec.rb +18 -18
  67. data/spec/chewy/query/nodes/raw_spec.rb +1 -1
  68. data/spec/chewy/query/nodes/regexp_spec.rb +18 -18
  69. data/spec/chewy/query/nodes/script_spec.rb +4 -4
  70. data/spec/chewy/query/pagination/kaminari_spec.rb +41 -39
  71. data/spec/chewy/query/pagination/will_paginage_spec.rb +60 -0
  72. data/spec/chewy/query/pagination_spec.rb +8 -7
  73. data/spec/chewy/query_spec.rb +166 -167
  74. data/spec/chewy/rspec/update_index_spec.rb +1 -1
  75. data/spec/chewy/runtime/version_spec.rb +30 -30
  76. data/spec/chewy/runtime_spec.rb +3 -3
  77. data/spec/chewy/type/actions_spec.rb +3 -3
  78. data/spec/chewy/type/adapter/active_record_spec.rb +143 -143
  79. data/spec/chewy/type/adapter/mongoid_spec.rb +219 -0
  80. data/spec/chewy/type/adapter/object_spec.rb +39 -39
  81. data/spec/chewy/type/import_spec.rb +67 -37
  82. data/spec/chewy/type/mapping_spec.rb +12 -12
  83. data/spec/chewy/type/observe_spec.rb +5 -6
  84. data/spec/chewy/type/wrapper_spec.rb +12 -12
  85. data/spec/chewy_spec.rb +26 -28
  86. data/spec/spec_helper.rb +19 -31
  87. data/spec/support/active_record.rb +52 -0
  88. data/spec/support/class_helpers.rb +0 -4
  89. data/spec/support/mongoid.rb +87 -0
  90. metadata +33 -18
  91. data/gemfiles/Gemfile.rails-3.2 +0 -15
  92. data/gemfiles/Gemfile.rails-4.0 +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 434f4c2db17b4906fcb08963bd2e539869179ee6
4
- data.tar.gz: 827aba062a02a1911666162159f48671a1ed3634
3
+ metadata.gz: 11ba7489e6c513a9a8e81cc220a64718808fcde0
4
+ data.tar.gz: 9a3336d2e062b027ab1ca03396dc6eac549d964a
5
5
  SHA512:
6
- metadata.gz: 1cf88693d5554070dc6bf5a6ce402e67c30afb4c2d9eb0018b2c8c61d774b1944099bf4d2d043c550743a973eb1fe83dba87e0f6443bec896b58f9a977cad6e6
7
- data.tar.gz: 5846df79cf664b56123a77cbfe3c6b3b2d030e5a475919d1500bcbe1d72671c942e440cbf5e95cb6f4091d68f832fb46198e7257a745360daebf10867f1489e0
6
+ metadata.gz: 17dfc426d7a92c958d5d1548aa7420e380b984297c650e8b9f29658306a8ef30b9a75c3a6d86e4149af6d3d6008228fd709a98797f881fc28600fbcb511cee26
7
+ data.tar.gz: 55899323c6be7796cd3640a3386c9f39ccfd785a01c0594e74a53fd9022b508e0372644dc92a739c997b9f3ba094e021ed81b2c6b4fc125910a2bec2b15aa515
@@ -1,14 +1,36 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 2.0.0
5
- - 2.1.1
4
+ - 2.1.3
6
5
  # - rbx
7
6
  gemfile:
8
7
  - Gemfile
9
- - gemfiles/Gemfile.rails-3.2
10
- - gemfiles/Gemfile.rails-4.0
8
+ - gemfiles/Gemfile.rails-3.2.active_record
9
+ - gemfiles/Gemfile.rails-3.2.active_record.kaminari
10
+ - gemfiles/Gemfile.rails-3.2.active_record.will_paginate
11
+ - gemfiles/Gemfile.rails-4.0.active_record
12
+ - gemfiles/Gemfile.rails-4.0.active_record.kaminari
13
+ - gemfiles/Gemfile.rails-4.0.active_record.will_paginate
14
+ - gemfiles/Gemfile.rails-4.0.mongoid
15
+ - gemfiles/Gemfile.rails-4.0.mongoid.kaminari
16
+ - gemfiles/Gemfile.rails-4.0.mongoid.will_paginate
17
+ - gemfiles/Gemfile.rails-4.1.active_record
18
+ - gemfiles/Gemfile.rails-4.1.active_record.kaminari
19
+ - gemfiles/Gemfile.rails-4.1.active_record.will_paginate
20
+ - gemfiles/Gemfile.rails-4.1.mongoid
21
+ - gemfiles/Gemfile.rails-4.1.mongoid.kaminari
22
+ - gemfiles/Gemfile.rails-4.1.mongoid.will_paginate
23
+ # - gemfiles/Gemfile.rails-4.2.active_record
24
+ # - gemfiles/Gemfile.rails-4.2.active_record.kaminari
25
+ # - gemfiles/Gemfile.rails-4.2.active_record.will_paginate
26
+ # - gemfiles/Gemfile.rails-4.2.mongoid
27
+ # - gemfiles/Gemfile.rails-4.2.mongoid.kaminari
28
+ # - gemfiles/Gemfile.rails-4.2.mongoid.will_paginate
29
+
11
30
  before_install:
12
31
  - curl -# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.0.tar.gz | tar xz -C /tmp
13
32
  before_script:
14
33
  - TEST_CLUSTER_COMMAND="/tmp/elasticsearch-1.3.0/bin/elasticsearch" rake elasticsearch:start
34
+ services:
35
+ - mongodb
36
+
@@ -1,5 +1,21 @@
1
1
  # master
2
2
 
3
+ # Version 0.6.0
4
+
5
+ ## Changes
6
+
7
+ * Mongoid support YaY! (@fabiotomio, @leemhenson)
8
+
9
+ * `urgent: true` option for `update_index` is deprecated and will be removed soon, use `Chewy.atomic` instead
10
+
11
+ * `timeout` and `timed_out` support (@MarkMurphy)
12
+
13
+ * will_paginate support (@josecoelho)
14
+
15
+ ## Bugfixes
16
+
17
+ * All the query chainable methods delegated to indexes and types (partially @Linuus)
18
+
3
19
  # Version 0.5.2
4
20
 
5
21
  ## Changes
data/Gemfile CHANGED
@@ -3,10 +3,12 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in chewy.gemspec
4
4
  gemspec
5
5
 
6
+ gem 'activerecord'
7
+ # gem 'mongoid'
6
8
  gem 'kaminari', require: false
9
+ # gem 'will_paginate', require: false
7
10
 
8
11
  group :test do
9
-
10
12
  gem 'guard'
11
13
  gem 'guard-rspec'
12
14
  gem 'rb-inotify', require: false
data/README.md CHANGED
@@ -241,15 +241,8 @@ There are 3 strategies for index updating: do not update index at all, update ri
241
241
  By default Chewy indexes are not updated when the observed model is saved or destroyed.
242
242
  This depends on the `Chewy.urgent_update` (false by default) or on the per-model update config.
243
243
  If you will perform `Chewy.urgent_update = true`, all the models will start to update elasticsearch
244
- index right after save. Also
244
+ index right after save.
245
245
 
246
- ```ruby
247
- class User < ActiveRecord::Base
248
- update_index 'users#user', 'self', urgent: true
249
- end
250
- ```
251
-
252
- will make the same effect for User model only.
253
246
  Note than urgent update options affects only outside-atomic-block behavour. Inside
254
247
  the `Chewy.atomic { }` block indexes updates as described below.
255
248
 
@@ -764,9 +757,8 @@ See [update_index.rb](lib/chewy/rspec/update_index.rb) for more details.
764
757
  * Typecasting support
765
758
  * Advanced (simplyfied) query DSL: `UsersIndex.query { email == 'my@gmail.com' }` will produce term query
766
759
  * update_all support
767
- * Other than ActiveRecord ORMs support (Mongoid)
768
760
  * Maybe, closer ORM/ODM integration, creating index classes implicitly
769
- * Asunc indexes updating
761
+ * Async indexes updating
770
762
 
771
763
  ## Contributing
772
764
 
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rspec-its', '~> 1.0.1'
24
24
  spec.add_development_dependency 'rspec-collection_matchers'
25
25
  spec.add_development_dependency 'sqlite3'
26
- spec.add_development_dependency 'activerecord', '>= 3.2'
27
26
  spec.add_development_dependency 'database_cleaner'
28
27
  spec.add_development_dependency 'elasticsearch-extensions'
29
28
  spec.add_development_dependency 'rubysl', '~> 2.0' if RUBY_ENGINE == 'rbx'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 3.2.0'
6
+ gem 'activesupport', '~> 3.2.0'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 3.2.0'
6
+ gem 'activesupport', '~> 3.2.0'
7
+ gem 'kaminari', require: false
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 3.2.0'
6
+ gem 'activesupport', '~> 3.2.0'
7
+ gem 'will_paginate', require: false
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 4.0.0'
6
+ gem 'activesupport', '~> 4.0.0'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 4.0.0'
6
+ gem 'activesupport', '~> 4.0.0'
7
+ gem 'kaminari', require: false
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 4.0.0'
6
+ gem 'activesupport', '~> 4.0.0'
7
+ gem 'will_paginate', require: false
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'mongoid', '~> 4.0.0'
6
+ gem 'activesupport', '~> 4.0.0'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'mongoid', '~> 4.0.0'
6
+ gem 'activesupport', '~> 4.0.0'
7
+ gem 'kaminari', require: false
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'mongoid', '~> 4.0.0'
6
+ gem 'activesupport', '~> 4.0.0'
7
+ gem 'will_paginate', require: false
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 4.1.0'
6
+ gem 'activesupport', '~> 4.1.0'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 4.1.0'
6
+ gem 'activesupport', '~> 4.1.0'
7
+ gem 'kaminari', require: false
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 4.1.0'
6
+ gem 'activesupport', '~> 4.1.0'
7
+ gem 'will_paginate', require: false
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'mongoid', '~> 4.0.0'
6
+ gem 'activesupport', '~> 4.1.0'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'mongoid', '~> 4.0.0'
6
+ gem 'activesupport', '~> 4.1.0'
7
+ gem 'kaminari', require: false
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'mongoid', '~> 4.0.0'
6
+ gem 'activesupport', '~> 4.1.0'
7
+ gem 'will_paginate', require: false
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 4.2.0'
6
+ gem 'activesupport', '~> 4.2.0'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 4.2.0'
6
+ gem 'activesupport', '~> 4.2.0'
7
+ gem 'kaminari', require: false
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'activerecord', '~> 4.2.0'
6
+ gem 'activesupport', '~> 4.2.0'
7
+ gem 'will_paginate', require: false
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'mongoid', '~> 4.0.0'
6
+ gem 'activesupport', '~> 4.2.0'
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'mongoid', '~> 4.0.0'
6
+ gem 'activesupport', '~> 4.2.0'
7
+ gem 'kaminari', require: false
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '../'
4
+
5
+ gem 'mongoid', '~> 4.0.0'
6
+ gem 'activesupport', '~> 4.2.0'
7
+ gem 'will_paginate', require: false
@@ -7,10 +7,6 @@ require 'i18n/core_ext/hash'
7
7
  require 'chewy/backports/deep_dup' unless Object.respond_to?(:deep_dup)
8
8
  require 'singleton'
9
9
 
10
- begin
11
- require 'kaminari'
12
- rescue LoadError
13
- end
14
10
  require 'elasticsearch'
15
11
 
16
12
  require 'chewy/version'
@@ -23,10 +19,40 @@ require 'chewy/query'
23
19
  require 'chewy/fields/base'
24
20
  require 'chewy/fields/root'
25
21
 
22
+ begin
23
+ require 'kaminari'
24
+ require 'chewy/query/pagination/kaminari'
25
+ rescue LoadError
26
+ end
27
+
28
+ begin
29
+ require 'will_paginate'
30
+ require 'will_paginate/collection'
31
+ require 'chewy/query/pagination/will_paginate'
32
+ rescue LoadError
33
+ end
34
+
26
35
  require 'chewy/railtie' if defined?(::Rails)
27
36
 
28
37
  ActiveSupport.on_load(:active_record) do
29
38
  extend Chewy::Type::Observe::ActiveRecordMethods
39
+
40
+ begin
41
+ require 'will_paginate/active_record'
42
+ rescue LoadError
43
+ end
44
+ end
45
+
46
+ ActiveSupport.on_load(:mongoid) do
47
+ module Mongoid::Document::ClassMethods
48
+ include Chewy::Type::Observe::MongoidMethods
49
+ end
50
+
51
+ begin
52
+ require 'will_paginate/mongoid'
53
+ require 'chewy/query/pagination/will_paginate'
54
+ rescue LoadError
55
+ end
30
56
  end
31
57
 
32
58
  module Chewy
@@ -62,8 +88,10 @@ module Chewy
62
88
  def create_type index, target, options = {}, &block
63
89
  type = Class.new(Chewy::Type)
64
90
 
65
- adapter = if (target.is_a?(Class) && target < ActiveRecord::Base) || target.is_a?(::ActiveRecord::Relation)
91
+ adapter = if defined?(::ActiveRecord::Base) && ((target.is_a?(Class) && target < ::ActiveRecord::Base) || target.is_a?(::ActiveRecord::Relation))
66
92
  Chewy::Type::Adapter::ActiveRecord.new(target, options)
93
+ elsif defined?(::Mongoid::Document) && ((target.is_a?(Class) && target.ancestors.include?(::Mongoid::Document)) || target.is_a?(::Mongoid::Criteria))
94
+ Chewy::Type::Adapter::Mongoid.new(target, options)
67
95
  else
68
96
  Chewy::Type::Adapter::Object.new(target, options)
69
97
  end
@@ -171,6 +171,7 @@ module Chewy
171
171
  @yaml_options ||= begin
172
172
  if defined?(Rails)
173
173
  file = Rails.root.join(*%w(config chewy.yml))
174
+
174
175
  if File.exists?(file)
175
176
  yaml = ERB.new(File.read(file)).result
176
177
  YAML.load(yaml)[Rails.env].try(:deep_symbolize_keys)
@@ -4,9 +4,12 @@ module Chewy
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- singleton_class.delegate :explain, :limit, :offset, :highlight, :rescore,
8
- :facets, :aggregations, :none, :strategy, :query, :filter, :post_filter,
9
- :order, :reorder, :only, :types, :suggest, :delete_all, :total_count, to: :all
7
+ singleton_class.delegate :explain, :query_mode, :filter_mode, :post_filter_mode,
8
+ :timeout, :limit, :offset, :highlight, :rescore, :facets, :script_score,
9
+ :boost_factor, :random_score, :field_value_factor, :decay, :aggregations,
10
+ :suggest, :none, :strategy, :query, :filter, :post_filter, :boost_mode,
11
+ :score_mode, :order, :reorder, :only, :types, :delete_all, :total,
12
+ :total_count, :total_entries, to: :all
10
13
  end
11
14
 
12
15
  module ClassMethods
@@ -224,6 +224,55 @@ module Chewy
224
224
  chain { criteria.update_options post_filter_mode: value }
225
225
  end
226
226
 
227
+ # A search timeout, bounding the search request to be executed within the
228
+ # specified time value and bail with the hits accumulated up to that point
229
+ # when expired. Defaults to no timeout.
230
+ #
231
+ # By default, the coordinating node waits to receive a response from all
232
+ # shards. If one node is having trouble, it could slow down the response to
233
+ # all search requests.
234
+ #
235
+ # The timeout parameter tells the coordinating node how long it should wait
236
+ # before giving up and just returning the results that it already has. It
237
+ # can be better to return some results than none at all.
238
+ #
239
+ # The response to a search request will indicate whether the search timed
240
+ # out and how many shards responded successfully:
241
+ #
242
+ # ...
243
+ # "timed_out": true,
244
+ # "_shards": {
245
+ # "total": 5,
246
+ # "successful": 4,
247
+ # "failed": 1
248
+ # },
249
+ # ...
250
+ #
251
+ # The primary shard assigned to perform the index operation might not be
252
+ # available when the index operation is executed. Some reasons for this
253
+ # might be that the primary shard is currently recovering from a gateway or
254
+ # undergoing relocation. By default, the index operation will wait on the
255
+ # primary shard to become available for up to 1 minute before failing and
256
+ # responding with an error. The timeout parameter can be used to explicitly
257
+ # specify how long it waits.
258
+ #
259
+ # UsersIndex.timeout("5000ms")
260
+ #
261
+ # Timeout is not a circuit breaker.
262
+ #
263
+ # It should be noted that this timeout does not halt the execution of the
264
+ # query, it merely tells the coordinating node to return the results
265
+ # collected so far and to close the connection. In the background, other
266
+ # shards may still be processing the query even though results have been
267
+ # sent.
268
+ #
269
+ # Use the timeout because it is important to your SLA, not because you want
270
+ # to abort the execution of long running queries.
271
+ #
272
+ def timeout value
273
+ chain { criteria.update_request_options timeout: value }
274
+ end
275
+
227
276
  # Sets elasticsearch <tt>size</tt> search request param
228
277
  # Default value is set in the elasticsearch and is 10.
229
278
  #
@@ -790,6 +839,28 @@ module Chewy
790
839
  _delete_all_response
791
840
  end
792
841
 
842
+ # Returns request total time elapsed as reported by elasticsearch
843
+ #
844
+ # UsersIndex.query(...).filter(...).took
845
+ #
846
+ def took
847
+ _response['took']
848
+ end
849
+
850
+ # Returns request timed_out as reported by elasticsearch
851
+ #
852
+ # The timed_out value tells us whether the query timed out or not.
853
+ #
854
+ # By default, search requests do not timeout. If low response times are more
855
+ # important to you than complete results, you can specify a timeout as 10 or
856
+ # "10ms" (10 milliseconds), or "1s" (1 second). See #timeout method.
857
+ #
858
+ # UsersIndex.query(...).filter(...).timed_out
859
+ #
860
+ def timed_out
861
+ _response['timed_out']
862
+ end
863
+
793
864
  protected
794
865
 
795
866
  def initialize_clone other
@@ -835,7 +906,9 @@ module Chewy
835
906
  def _results
836
907
  @_results ||= (criteria.none? || _response == {} ? [] : _response['hits']['hits']).map do |hit|
837
908
  attributes = (hit['_source'] || {}).merge(hit['highlight'] || {}, &RESULT_MERGER)
838
- attributes.reverse_merge!(id: hit['_id']).merge!(_score: hit['_score'])
909
+ attributes.reverse_merge!(id: hit['_id'])
910
+ .merge!(_score: hit['_score'])
911
+ .merge!(_explanation: hit['_explanation'])
839
912
 
840
913
  wrapper = index.type_hash[hit['_type']].new attributes
841
914
  wrapper._data = hit