couchbase 3.0.0.beta.1-universal-darwin-19 → 3.0.0-universal-darwin-19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +227 -0
  3. data/.rubocop_todo.yml +47 -0
  4. data/CONTRIBUTING.md +110 -0
  5. data/Gemfile +4 -0
  6. data/README.md +3 -3
  7. data/Rakefile +1 -1
  8. data/couchbase.gemspec +40 -39
  9. data/examples/analytics.rb +123 -108
  10. data/examples/auth.rb +33 -0
  11. data/examples/crud.rb +16 -2
  12. data/examples/managing_analytics_indexes.rb +18 -4
  13. data/examples/managing_buckets.rb +17 -3
  14. data/examples/managing_collections.rb +22 -9
  15. data/examples/managing_query_indexes.rb +38 -18
  16. data/examples/managing_search_indexes.rb +21 -6
  17. data/examples/managing_view_indexes.rb +18 -4
  18. data/examples/query.rb +17 -3
  19. data/examples/query_with_consistency.rb +30 -20
  20. data/examples/search.rb +116 -101
  21. data/examples/search_with_consistency.rb +43 -30
  22. data/examples/subdocument.rb +42 -30
  23. data/examples/view.rb +19 -10
  24. data/ext/CMakeLists.txt +40 -2
  25. data/ext/build_version.hxx.in +1 -1
  26. data/ext/couchbase/bucket.hxx +190 -38
  27. data/ext/couchbase/cluster.hxx +22 -4
  28. data/ext/couchbase/configuration.hxx +14 -14
  29. data/ext/couchbase/couchbase.cxx +108 -12
  30. data/ext/couchbase/error_map.hxx +202 -2
  31. data/ext/couchbase/errors.hxx +8 -2
  32. data/ext/couchbase/io/dns_client.hxx +6 -6
  33. data/ext/couchbase/io/http_command.hxx +2 -2
  34. data/ext/couchbase/io/http_session.hxx +7 -11
  35. data/ext/couchbase/io/http_session_manager.hxx +3 -3
  36. data/ext/couchbase/io/mcbp_command.hxx +101 -44
  37. data/ext/couchbase/io/mcbp_session.hxx +144 -49
  38. data/ext/couchbase/io/retry_action.hxx +30 -0
  39. data/ext/couchbase/io/retry_context.hxx +39 -0
  40. data/ext/couchbase/io/retry_orchestrator.hxx +96 -0
  41. data/ext/couchbase/io/retry_reason.hxx +235 -0
  42. data/ext/couchbase/io/retry_strategy.hxx +156 -0
  43. data/ext/couchbase/operations/document_decrement.hxx +2 -0
  44. data/ext/couchbase/operations/document_exists.hxx +2 -0
  45. data/ext/couchbase/operations/document_get.hxx +2 -0
  46. data/ext/couchbase/operations/document_get_and_lock.hxx +2 -0
  47. data/ext/couchbase/operations/document_get_and_touch.hxx +2 -0
  48. data/ext/couchbase/operations/document_get_projected.hxx +2 -0
  49. data/ext/couchbase/operations/document_increment.hxx +2 -0
  50. data/ext/couchbase/operations/document_insert.hxx +2 -0
  51. data/ext/couchbase/operations/document_lookup_in.hxx +2 -0
  52. data/ext/couchbase/operations/document_mutate_in.hxx +3 -0
  53. data/ext/couchbase/operations/document_query.hxx +10 -0
  54. data/ext/couchbase/operations/document_remove.hxx +2 -0
  55. data/ext/couchbase/operations/document_replace.hxx +2 -0
  56. data/ext/couchbase/operations/document_search.hxx +8 -3
  57. data/ext/couchbase/operations/document_touch.hxx +2 -0
  58. data/ext/couchbase/operations/document_unlock.hxx +2 -0
  59. data/ext/couchbase/operations/document_upsert.hxx +2 -0
  60. data/ext/couchbase/operations/query_index_create.hxx +14 -4
  61. data/ext/couchbase/operations/query_index_drop.hxx +12 -2
  62. data/ext/couchbase/operations/query_index_get_all.hxx +11 -2
  63. data/ext/couchbase/origin.hxx +47 -17
  64. data/ext/couchbase/platform/backtrace.c +189 -0
  65. data/ext/couchbase/platform/backtrace.h +54 -0
  66. data/ext/couchbase/platform/terminate_handler.cc +122 -0
  67. data/ext/couchbase/platform/terminate_handler.h +36 -0
  68. data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +6 -1
  69. data/ext/couchbase/protocol/status.hxx +14 -4
  70. data/ext/couchbase/version.hxx +2 -2
  71. data/ext/extconf.rb +39 -36
  72. data/ext/test/main.cxx +64 -16
  73. data/lib/couchbase.rb +0 -1
  74. data/lib/couchbase/analytics_options.rb +2 -4
  75. data/lib/couchbase/authenticator.rb +14 -0
  76. data/lib/couchbase/binary_collection.rb +9 -9
  77. data/lib/couchbase/binary_collection_options.rb +8 -6
  78. data/lib/couchbase/bucket.rb +18 -18
  79. data/lib/couchbase/cluster.rb +121 -90
  80. data/lib/couchbase/collection.rb +36 -38
  81. data/lib/couchbase/collection_options.rb +31 -17
  82. data/lib/couchbase/common_options.rb +1 -1
  83. data/lib/couchbase/datastructures/couchbase_list.rb +16 -16
  84. data/lib/couchbase/datastructures/couchbase_map.rb +18 -18
  85. data/lib/couchbase/datastructures/couchbase_queue.rb +13 -13
  86. data/lib/couchbase/datastructures/couchbase_set.rb +8 -7
  87. data/lib/couchbase/errors.rb +10 -3
  88. data/lib/couchbase/json_transcoder.rb +2 -2
  89. data/lib/couchbase/libcouchbase.bundle +0 -0
  90. data/lib/couchbase/management/analytics_index_manager.rb +37 -37
  91. data/lib/couchbase/management/bucket_manager.rb +25 -25
  92. data/lib/couchbase/management/collection_manager.rb +3 -3
  93. data/lib/couchbase/management/query_index_manager.rb +59 -14
  94. data/lib/couchbase/management/search_index_manager.rb +15 -12
  95. data/lib/couchbase/management/user_manager.rb +1 -1
  96. data/lib/couchbase/management/view_index_manager.rb +11 -5
  97. data/lib/couchbase/mutation_state.rb +12 -0
  98. data/lib/couchbase/query_options.rb +23 -9
  99. data/lib/couchbase/scope.rb +61 -1
  100. data/lib/couchbase/search_options.rb +40 -27
  101. data/lib/couchbase/subdoc.rb +31 -28
  102. data/lib/couchbase/version.rb +2 -2
  103. data/lib/couchbase/view_options.rb +0 -1
  104. metadata +20 -7
@@ -17,7 +17,7 @@ require "couchbase/errors"
17
17
  module Couchbase
18
18
  module Management
19
19
  class SearchIndexManager
20
- alias_method :inspect, :to_s
20
+ alias inspect to_s
21
21
 
22
22
  # @param [Couchbase::Backend] backend
23
23
  def initialize(backend)
@@ -58,17 +58,18 @@ module Couchbase
58
58
  # @raise [ArgumentError] if name, type or source_type is empty
59
59
  def upsert_index(index_definition, options = UpsertIndexOptions.new)
60
60
  @backend.search_index_upsert(
61
- {
62
- name: index_definition.name,
63
- type: index_definition.type,
64
- uuid: index_definition.uuid,
65
- params: (JSON.generate(index_definition.params) if index_definition.params),
66
- source_name: index_definition.source_name,
67
- source_type: index_definition.source_type,
68
- source_uuid: index_definition.source_uuid,
69
- source_params: (JSON.generate(index_definition.source_params) if index_definition.source_params),
70
- plan_params: (JSON.generate(index_definition.plan_params) if index_definition.plan_params),
71
- }, options.timeout)
61
+ {
62
+ name: index_definition.name,
63
+ type: index_definition.type,
64
+ uuid: index_definition.uuid,
65
+ params: (JSON.generate(index_definition.params) if index_definition.params),
66
+ source_name: index_definition.source_name,
67
+ source_type: index_definition.source_type,
68
+ source_uuid: index_definition.source_uuid,
69
+ source_params: (JSON.generate(index_definition.source_params) if index_definition.source_params),
70
+ plan_params: (JSON.generate(index_definition.plan_params) if index_definition.plan_params),
71
+ }, options.timeout
72
+ )
72
73
  end
73
74
 
74
75
  # Drops the index
@@ -357,6 +358,8 @@ module Couchbase
357
358
 
358
359
  # @yieldparam [SearchIndex] self
359
360
  def initialize
361
+ @type = "fulltext-index"
362
+ @source_type = "couchbase"
360
363
  yield self if block_given?
361
364
  end
362
365
  end
@@ -17,7 +17,7 @@ require "couchbase/errors"
17
17
  module Couchbase
18
18
  module Management
19
19
  class UserManager
20
- alias_method :inspect, :to_s
20
+ alias inspect to_s
21
21
 
22
22
  # @param [Couchbase::Backend] backend
23
23
  def initialize(backend)
@@ -32,7 +32,7 @@ module Couchbase
32
32
  # development document or a production document. The type of this argument is [Symbol] with allowed values
33
33
  # +:production+ and +:development+.
34
34
  class ViewIndexManager
35
- alias_method :inspect, :to_s
35
+ alias inspect to_s
36
36
 
37
37
  # @return [String] name of the bucket
38
38
  attr_accessor :bucket_name
@@ -80,8 +80,14 @@ module Couchbase
80
80
  # @return [void]
81
81
  def upsert_design_document(document, namespace, options = UpsertDesignDocumentOptions.new)
82
82
  @backend.view_index_upsert(@bucket_name, {
83
- name: document.name,
84
- views: document.views.map { |name, view| {name: name, map: view.map_function, reduce: view.reduce_function} }
83
+ name: document.name,
84
+ views: document.views.map do |name, view|
85
+ {
86
+ name: name,
87
+ map: view.map_function,
88
+ reduce: view.reduce_function,
89
+ }
90
+ end,
85
91
  }, namespace, options.timeout)
86
92
  end
87
93
 
@@ -184,11 +190,11 @@ module Couchbase
184
190
 
185
191
  # @return [String] map function in javascript as String
186
192
  attr_accessor :map_function
187
- alias_method :map, :map_function
193
+ alias map map_function
188
194
 
189
195
  # @return [String] reduce function in javascript as String
190
196
  attr_accessor :reduce_function
191
- alias_method :reduce, :reduce_function
197
+ alias reduce reduce_function
192
198
 
193
199
  # @return [Boolean] true if map function is defined
194
200
  def has_map?
@@ -47,5 +47,17 @@ module Couchbase
47
47
  def add(*mutation_tokens)
48
48
  @tokens |= mutation_tokens
49
49
  end
50
+
51
+ # @api private
52
+ def to_a
53
+ @tokens.map do |t|
54
+ {
55
+ bucket_name: t.bucket_name,
56
+ partition_id: t.partition_id,
57
+ partition_uuid: t.partition_uuid,
58
+ sequence_number: t.sequence_number,
59
+ }
60
+ end
61
+ end
50
62
  end
51
63
  end
@@ -16,7 +16,6 @@ require 'json'
16
16
 
17
17
  module Couchbase
18
18
  class Cluster
19
-
20
19
  class QueryOptions
21
20
  # @return [Integer] Timeout in milliseconds
22
21
  attr_accessor :timeout
@@ -33,7 +32,8 @@ module Couchbase
33
32
  # @return [Boolean] Allows explicitly marking a query as being readonly and not mutating any documents on the server side.
34
33
  attr_accessor :readonly
35
34
 
36
- # Allows customizing how long (in milliseconds) the query engine is willing to wait until the index catches up to whatever scan consistency is asked for in this query.
35
+ # Allows customizing how long (in milliseconds) the query engine is willing to wait until the index catches up to whatever scan
36
+ # consistency is asked for in this query.
37
37
  #
38
38
  # @note that if +:not_bounded+ consistency level is used, this method doesn't do anything
39
39
  # at all. If no value is provided to this method, the server default is used.
@@ -47,7 +47,8 @@ module Couchbase
47
47
  # @return [Integer] Supports customizing the number of items execution operators can batch for fetch from the KV layer on the server.
48
48
  attr_accessor :pipeline_batch
49
49
 
50
- # @return [Integer] Allows customizing the maximum number of items each execution operator can buffer between various operators on the server.
50
+ # @return [Integer] Allows customizing the maximum number of items each execution operator can buffer between various operators on the
51
+ # server.
51
52
  attr_accessor :pipeline_cap
52
53
 
53
54
  # @return [Boolean] Enables per-request metrics in the trailing section of the query
@@ -56,6 +57,14 @@ module Couchbase
56
57
  # @return [:off, :phases, :timings] Customize server profile level for this query
57
58
  attr_accessor :profile
58
59
 
60
+ # Associate scope qualifier (also known as +query_context+) with the query.
61
+ #
62
+ # The qualifier must be in form +{bucket_name}.{scope_name}+ or +default:{bucket_name}.{scope_name}+.
63
+ #
64
+ # @api uncommitted
65
+ # @return [String]
66
+ attr_accessor :scope_qualifier
67
+
59
68
  # @return [:not_bounded, :request_plus]
60
69
  attr_reader :scan_consistency
61
70
 
@@ -76,6 +85,7 @@ module Couchbase
76
85
  @named_parameters = nil
77
86
  @scan_consistency = nil
78
87
  @mutation_state = nil
88
+ @scope_qualifier = nil
79
89
  yield self if block_given?
80
90
  end
81
91
 
@@ -91,9 +101,11 @@ module Couchbase
91
101
  #
92
102
  # @note overrides consistency level set by {#consistent_with}
93
103
  #
94
- # [+:not_bounded+] The indexer will return whatever state it has to the query engine at the time of query. This is the default (for single-statement requests).
104
+ # [+:not_bounded+] The indexer will return whatever state it has to the query engine at the time of query. This is the default (for
105
+ # single-statement requests).
95
106
  #
96
- # [+:request_plus+] The indexer will wait until all mutations have been processed at the time of request before returning to the query engine.
107
+ # [+:request_plus+] The indexer will wait until all mutations have been processed at the time of request before returning to the query
108
+ # engine.
97
109
  #
98
110
  # @param [:not_bounded, :request_plus] level the index scan consistency to be used for this query
99
111
  def scan_consistency=(level)
@@ -122,7 +134,7 @@ module Couchbase
122
134
  # @api private
123
135
  # @return [Array<String>, nil]
124
136
  def export_positional_parameters
125
- @positional_parameters.map { |p| JSON.dump(p) } if @positional_parameters
137
+ @positional_parameters&.map { |p| JSON.dump(p) }
126
138
  end
127
139
 
128
140
  # Sets named parameters for the query
@@ -136,7 +148,7 @@ module Couchbase
136
148
  # @api private
137
149
  # @return [Hash<String => String>, nil]
138
150
  def export_named_parameters
139
- @named_parameters.each_with_object({}) { |(n, v), o| o[n.to_s] = JSON.dump(v) } if @named_parameters
151
+ @named_parameters&.each_with_object({}) { |(n, v), o| o[n.to_s] = JSON.dump(v) }
140
152
  end
141
153
  end
142
154
 
@@ -195,10 +207,12 @@ module Couchbase
195
207
  end
196
208
 
197
209
  class QueryMetrics
198
- # @return [Integer] The total time taken for the request, that is the time from when the request was received until the results were returned
210
+ # @return [Integer] The total time taken for the request, that is the time from when the request was received until the results were
211
+ # returned.
199
212
  attr_accessor :elapsed_time
200
213
 
201
- # @return [Integer] The time taken for the execution of the request, that is the time from when query execution started until the results were returned
214
+ # @return [Integer] The time taken for the execution of the request, that is the time from when query execution started until the
215
+ # results were returned
202
216
  attr_accessor :execution_time
203
217
 
204
218
  # @return [Integer] the total number of results selected by the engine before restriction through LIMIT clause.
@@ -13,13 +13,14 @@
13
13
  # limitations under the License.
14
14
 
15
15
  require "couchbase/collection"
16
+ require "couchbase/query_options"
16
17
 
17
18
  module Couchbase
18
19
  class Scope
19
20
  attr_reader :bucket_name
20
21
  attr_reader :name
21
22
 
22
- alias_method :inspect, :to_s
23
+ alias inspect to_s
23
24
 
24
25
  # @param [Couchbase::Backend] backend
25
26
  # @param [String] bucket_name name of the bucket
@@ -38,5 +39,64 @@ module Couchbase
38
39
  def collection(collection_name)
39
40
  Collection.new(@backend, @bucket_name, @name, collection_name)
40
41
  end
42
+
43
+ # Performs a query against the query (N1QL) services.
44
+ #
45
+ # The query will be implicitly scoped using current bucket and scope names.
46
+ #
47
+ # @see QueryOptions#scope_qualifier
48
+ # @see Cluster#query
49
+ #
50
+ # @param [String] statement the N1QL query statement
51
+ # @param [QueryOptions] options the custom options for this query
52
+ #
53
+ # @return [QueryResult]
54
+ def query(statement, options = Cluster::QueryOptions.new)
55
+ resp = @backend.document_query(statement, {
56
+ timeout: options.timeout,
57
+ adhoc: options.adhoc,
58
+ client_context_id: options.client_context_id,
59
+ max_parallelism: options.max_parallelism,
60
+ readonly: options.readonly,
61
+ scan_wait: options.scan_wait,
62
+ scan_cap: options.scan_cap,
63
+ pipeline_batch: options.pipeline_batch,
64
+ pipeline_cap: options.pipeline_cap,
65
+ metrics: options.metrics,
66
+ profile: options.profile,
67
+ positional_parameters: options.export_positional_parameters,
68
+ named_parameters: options.export_named_parameters,
69
+ scope_name: @name,
70
+ bucket_name: @bucket_name,
71
+ scope_qualifier: options.scope_qualifier,
72
+ raw_parameters: options.raw_parameters,
73
+ scan_consistency: options.scan_consistency,
74
+ mutation_state: options.mutation_state&.to_a,
75
+ })
76
+
77
+ Cluster::QueryResult.new do |res|
78
+ res.meta_data = Cluster::QueryMetaData.new do |meta|
79
+ meta.status = resp[:meta][:status]
80
+ meta.request_id = resp[:meta][:request_id]
81
+ meta.client_context_id = resp[:meta][:client_context_id]
82
+ meta.signature = JSON.parse(resp[:meta][:signature]) if resp[:meta][:signature]
83
+ meta.profile = JSON.parse(resp[:meta][:profile]) if resp[:meta][:profile]
84
+ meta.metrics = Cluster::QueryMetrics.new do |metrics|
85
+ if resp[:meta][:metrics]
86
+ metrics.elapsed_time = resp[:meta][:metrics][:elapsed_time]
87
+ metrics.execution_time = resp[:meta][:metrics][:execution_time]
88
+ metrics.sort_count = resp[:meta][:metrics][:sort_count]
89
+ metrics.result_count = resp[:meta][:metrics][:result_count]
90
+ metrics.result_size = resp[:meta][:metrics][:result_size]
91
+ metrics.mutation_count = resp[:meta][:metrics][:mutation_count]
92
+ metrics.error_count = resp[:meta][:metrics][:error_count]
93
+ metrics.warning_count = resp[:meta][:metrics][:warning_count]
94
+ end
95
+ end
96
+ res[:warnings] = resp[:warnings].map { |warn| QueryWarning.new(warn[:code], warn[:message]) } if resp[:warnings]
97
+ end
98
+ res.instance_variable_set("@rows", resp[:rows])
99
+ end
100
+ end
41
101
  end
42
102
  end
@@ -304,7 +304,8 @@ module Couchbase
304
304
  #
305
305
  # @note The lower boundary is considered inclusive by default on the server side.
306
306
  #
307
- # @param [Time, String] time_point start time. When +Time+ object is passed {#date_time_parser} must be +nil+ (to use server default)
307
+ # @param [Time, String] time_point start time. When +Time+ object is passed {#date_time_parser} must be +nil+ (to use server
308
+ # default)
308
309
  # @param [Boolean] inclusive
309
310
  def start_time(time_point, inclusive = nil)
310
311
  @start_time = time_point
@@ -332,13 +333,11 @@ module Couchbase
332
333
  yield self if block_given?
333
334
  end
334
335
 
335
- DATE_FORMAT_RFC3339 = "%Y-%m-%dT%H:%M:%S%:z"
336
+ DATE_FORMAT_RFC3339 = "%Y-%m-%dT%H:%M:%S%:z".freeze
336
337
 
337
338
  # @return [String]
338
339
  def to_json(*args)
339
- if @start_time.nil? && @end_time.nil?
340
- raise ArgumentError, "either start_time or end_time must be set for DateRangeQuery"
341
- end
340
+ raise ArgumentError, "either start_time or end_time must be set for DateRangeQuery" if @start_time.nil? && @end_time.nil?
342
341
 
343
342
  data = {}
344
343
  data["boost"] = boost if boost
@@ -415,9 +414,7 @@ module Couchbase
415
414
 
416
415
  # @return [String]
417
416
  def to_json(*args)
418
- if @min.nil? && @max.nil?
419
- raise ArgumentError, "either min or max must be set for NumericRangeQuery"
420
- end
417
+ raise ArgumentError, "either min or max must be set for NumericRangeQuery" if @min.nil? && @max.nil?
421
418
 
422
419
  data = {}
423
420
  data["boost"] = boost if boost
@@ -485,9 +482,7 @@ module Couchbase
485
482
 
486
483
  # @return [String]
487
484
  def to_json(*args)
488
- if @min.nil? && @max.nil?
489
- raise ArgumentError, "either min or max must be set for TermRangeQuery"
490
- end
485
+ raise ArgumentError, "either min or max must be set for TermRangeQuery" if @min.nil? && @max.nil?
491
486
 
492
487
  data = {}
493
488
  data["boost"] = boost if boost
@@ -540,8 +535,8 @@ module Couchbase
540
535
  # @return [String]
541
536
  def to_json(*args)
542
537
  data = {
543
- "location" => [@longitude, @latitude],
544
- "distance" => @distance
538
+ "location" => [@longitude, @latitude],
539
+ "distance" => @distance,
545
540
  }
546
541
  data["boost"] = boost if boost
547
542
  data["field"] = field if field
@@ -589,8 +584,8 @@ module Couchbase
589
584
  # @return [String]
590
585
  def to_json(*args)
591
586
  data = {
592
- "top_left" => [@top_left_longitude, @top_left_latitude],
593
- "bottom_right" => [@bottom_right_longitude, @bottom_right_latitude]
587
+ "top_left" => [@top_left_longitude, @top_left_latitude],
588
+ "bottom_right" => [@bottom_right_longitude, @bottom_right_latitude],
594
589
  }
595
590
  data["boost"] = boost if boost
596
591
  data["field"] = field if field
@@ -633,6 +628,7 @@ module Couchbase
633
628
  # @return [String]
634
629
  def to_json(*args)
635
630
  raise ArgumentError, "compound conjunction query must have sub-queries" if @queries.nil? || @queries.empty?
631
+
636
632
  data = {"conjuncts" => @queries.uniq}
637
633
  data["boost"] = boost if boost
638
634
  data.to_json(*args)
@@ -677,9 +673,11 @@ module Couchbase
677
673
  # @return [String]
678
674
  def to_json(*args)
679
675
  raise ArgumentError, "compound disjunction query must have sub-queries" if @queries.nil? || @queries.empty?
676
+
680
677
  data = {"disjuncts" => @queries.uniq}
681
678
  if min
682
679
  raise ArgumentError, "disjunction query has fewer sub-queries than configured minimum" if @queries.size < min
680
+
683
681
  data["min"] = min
684
682
  end
685
683
  data["boost"] = boost if boost
@@ -739,6 +737,7 @@ module Couchbase
739
737
  if @must.empty? && @must_not.empty? && @should.empty?
740
738
  raise ArgumentError, "BooleanQuery must have at least one non-empty sub-query"
741
739
  end
740
+
742
741
  data = {}
743
742
  data["must"] = @must unless @must.empty?
744
743
  data["must_not"] = @must_not unless @must_not.empty?
@@ -758,7 +757,8 @@ module Couchbase
758
757
  TermQuery.new(term, &block)
759
758
  end
760
759
 
761
- # A query that looks for **exact** matches of the term in the index (no analyzer, no stemming). Useful to check what the actual content of the index is. It can also apply fuzziness on the term. Usual better alternative is `MatchQuery`.
760
+ # A query that looks for **exact** matches of the term in the index (no analyzer, no stemming). Useful to check what the actual
761
+ # content of the index is. It can also apply fuzziness on the term. Usual better alternative is `MatchQuery`.
762
762
  class TermQuery < SearchQuery
763
763
  # @return [Float]
764
764
  attr_accessor :boost
@@ -840,7 +840,8 @@ module Couchbase
840
840
  PhraseQuery.new(*terms, &block)
841
841
  end
842
842
 
843
- # A query that looks for **exact** match of several terms (in the exact order) in the index. Usual better alternative is {MatchPhraseQuery}.
843
+ # A query that looks for **exact** match of several terms (in the exact order) in the index. Usual better alternative is
844
+ # {MatchPhraseQuery}.
844
845
  class PhraseQuery < SearchQuery
845
846
  # @return [Float]
846
847
  attr_accessor :boost
@@ -958,6 +959,7 @@ module Couchbase
958
959
 
959
960
  # @yieldparam [SearchSortScore]
960
961
  def initialize
962
+ super
961
963
  yield self if block_given?
962
964
  end
963
965
 
@@ -973,6 +975,7 @@ module Couchbase
973
975
 
974
976
  # @yieldparam [SearchSortId]
975
977
  def initialize
978
+ super
976
979
  yield self if block_given?
977
980
  end
978
981
 
@@ -1001,6 +1004,7 @@ module Couchbase
1001
1004
  # @param [String] field the name of the filed for ordering
1002
1005
  # @yieldparam [SearchSortField]
1003
1006
  def initialize(field)
1007
+ super()
1004
1008
  @field = field
1005
1009
  yield self if block_given?
1006
1010
  end
@@ -1032,6 +1036,7 @@ module Couchbase
1032
1036
  # @param [Float] latitude
1033
1037
  # @yieldparam [SearchSortGeoDistance]
1034
1038
  def initialize(field, longitude, latitude)
1039
+ super()
1035
1040
  @field = field
1036
1041
  @longitude = longitude
1037
1042
  @latitude = latitude
@@ -1119,19 +1124,20 @@ module Couchbase
1119
1124
 
1120
1125
  # @param [String] field name of the field
1121
1126
  def initialize(field)
1127
+ super()
1122
1128
  @field = field
1123
1129
  @ranges = []
1124
1130
  yield self if block_given?
1125
1131
  end
1126
1132
 
1127
- DATE_FORMAT_RFC3339 = "%Y-%m-%dT%H:%M:%S%:z"
1133
+ DATE_FORMAT_RFC3339 = "%Y-%m-%dT%H:%M:%S%:z".freeze
1128
1134
 
1129
1135
  # @param [String] name the name of the range
1130
1136
  # @param [Time, String, nil] start_time lower bound of the range (pass +nil+ if there is no lower bound)
1131
1137
  # @param [Time, String, nil] end_time lower bound of the range (pass +nil+ if there is no lower bound)
1132
1138
  def add(name, start_time, end_time)
1133
- start_time = start_time.strftime(DATE_FORMAT_RFC3339) if start_time && start_time.respond_to?(:strftime)
1134
- end_time = end_time.strftime(DATE_FORMAT_RFC3339) if end_time && end_time.respond_to?(:strftime)
1139
+ start_time = start_time.strftime(DATE_FORMAT_RFC3339) if start_time.respond_to?(:strftime)
1140
+ end_time = end_time.strftime(DATE_FORMAT_RFC3339) if end_time.respond_to?(:strftime)
1135
1141
  @ranges.append({name: name, start: start_time, end: end_time})
1136
1142
  end
1137
1143
 
@@ -1161,7 +1167,8 @@ module Couchbase
1161
1167
  # @return [Array<String>] list of the fields to highlight
1162
1168
  attr_accessor :highlight_fields
1163
1169
 
1164
- # @return [Array<String>] list of field values which should be retrieved for result documents, provided they were stored while indexing
1170
+ # @return [Array<String>] list of field values which should be retrieved for result documents, provided they were stored while
1171
+ # indexing
1165
1172
  attr_accessor :fields
1166
1173
 
1167
1174
  # @return [:not_bounded] specifies level of consistency for the query
@@ -1201,7 +1208,8 @@ module Couchbase
1201
1208
  #
1202
1209
  # The list might contain either strings or special objects, that derive from {SearchSort}.
1203
1210
  #
1204
- # In case of String, the value represents the name of the field with optional +-+ in front of the name, which will turn on descending mode for this field. One field is special is +"_score"+ which will sort results by their score.
1211
+ # In case of String, the value represents the name of the field with optional +-+ in front of the name, which will turn on descending
1212
+ # mode for this field. One field is special is +"_score"+ which will sort results by their score.
1205
1213
  #
1206
1214
  # When nothing specified, the Server will order results by their score descending, which is equivalent of +"-_score"+.
1207
1215
  #
@@ -1218,6 +1226,7 @@ module Couchbase
1218
1226
 
1219
1227
  # @yieldparam [SearchOptions] self
1220
1228
  def initialize
1229
+ super
1221
1230
  @explain = false
1222
1231
  @transcoder = JsonTranscoder.new
1223
1232
  @scan_consistency = nil
@@ -1272,31 +1281,31 @@ module Couchbase
1272
1281
  #
1273
1282
  # @return [Array<String>]
1274
1283
  def fields
1275
- @locations.map { |location| location.field }.uniq
1284
+ @locations.map(&:field).uniq
1276
1285
  end
1277
1286
 
1278
1287
  # Lists all terms in this locations, considering all fields
1279
1288
  #
1280
1289
  # @return [Array<String>]
1281
1290
  def terms
1282
- @locations.map { |location| location.term }.uniq
1291
+ @locations.map(&:term).uniq
1283
1292
  end
1284
1293
 
1285
1294
  # Lists the terms for a given field
1286
1295
  #
1287
1296
  # @return [Array<String>]
1288
1297
  def terms_for_field(name)
1289
- get_for_field(name).map { |location| location.term }.uniq
1298
+ get_for_field(name).map(&:term).uniq
1290
1299
  end
1291
1300
 
1292
1301
  # @param [Array<SearchRowLocation>] locations
1293
1302
  def initialize(locations)
1303
+ super()
1294
1304
  @locations = locations
1295
1305
  end
1296
1306
  end
1297
1307
 
1298
- # An individual facet result has both metadata and details, as each facet can define ranges into which results are
1299
- # categorized
1308
+ # An individual facet result has both metadata and details, as each facet can define ranges into which results are categorized
1300
1309
  class SearchFacetResult
1301
1310
  # @return [String]
1302
1311
  attr_accessor :name
@@ -1323,6 +1332,7 @@ module Couchbase
1323
1332
 
1324
1333
  # @yieldparam [TermFacetResult] self
1325
1334
  def initialize
1335
+ super
1326
1336
  yield self if block_given?
1327
1337
  end
1328
1338
 
@@ -1334,6 +1344,7 @@ module Couchbase
1334
1344
  attr_reader :count
1335
1345
 
1336
1346
  def initialize(term, count)
1347
+ super()
1337
1348
  @term = term
1338
1349
  @count = count
1339
1350
  end
@@ -1350,6 +1361,7 @@ module Couchbase
1350
1361
 
1351
1362
  # @yieldparam [DateRangeFacetResult] self
1352
1363
  def initialize
1364
+ super
1353
1365
  yield self if block_given?
1354
1366
  end
1355
1367
 
@@ -1385,6 +1397,7 @@ module Couchbase
1385
1397
 
1386
1398
  # @yieldparam [NumericRangeFacetResult] self
1387
1399
  def initialize
1400
+ super
1388
1401
  yield self if block_given?
1389
1402
  end
1390
1403