couchbase 3.9.0-aarch64-linux-musl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +202 -0
  3. data/README.md +154 -0
  4. data/ext/extconf.rb +0 -0
  5. data/lib/active_support/cache/couchbase_store.rb +407 -0
  6. data/lib/couchbase/3.2/libcouchbase.so +0 -0
  7. data/lib/couchbase/3.3/libcouchbase.so +0 -0
  8. data/lib/couchbase/3.4/libcouchbase.so +0 -0
  9. data/lib/couchbase/4.0/libcouchbase.so +0 -0
  10. data/lib/couchbase/analytics_options.rb +109 -0
  11. data/lib/couchbase/authenticator.rb +80 -0
  12. data/lib/couchbase/binary_collection.rb +145 -0
  13. data/lib/couchbase/binary_collection_options.rb +26 -0
  14. data/lib/couchbase/bucket.rb +173 -0
  15. data/lib/couchbase/cluster.rb +555 -0
  16. data/lib/couchbase/cluster_registry.rb +49 -0
  17. data/lib/couchbase/collection.rb +770 -0
  18. data/lib/couchbase/collection_options.rb +401 -0
  19. data/lib/couchbase/config_profiles.rb +57 -0
  20. data/lib/couchbase/configuration.rb +58 -0
  21. data/lib/couchbase/datastructures/couchbase_list.rb +192 -0
  22. data/lib/couchbase/datastructures/couchbase_map.rb +231 -0
  23. data/lib/couchbase/datastructures/couchbase_queue.rb +161 -0
  24. data/lib/couchbase/datastructures/couchbase_set.rb +145 -0
  25. data/lib/couchbase/datastructures.rb +26 -0
  26. data/lib/couchbase/deprecations.rb +61 -0
  27. data/lib/couchbase/diagnostics.rb +183 -0
  28. data/lib/couchbase/errors.rb +438 -0
  29. data/lib/couchbase/fork_hooks.rb +41 -0
  30. data/lib/couchbase/get_replica_strategy.rb +89 -0
  31. data/lib/couchbase/json_transcoder.rb +41 -0
  32. data/lib/couchbase/key_value_scan.rb +119 -0
  33. data/lib/couchbase/libcouchbase.rb +6 -0
  34. data/lib/couchbase/logger.rb +87 -0
  35. data/lib/couchbase/management/analytics_index_manager.rb +1160 -0
  36. data/lib/couchbase/management/bucket_manager.rb +479 -0
  37. data/lib/couchbase/management/collection_manager.rb +515 -0
  38. data/lib/couchbase/management/collection_query_index_manager.rb +247 -0
  39. data/lib/couchbase/management/query_index_manager.rb +671 -0
  40. data/lib/couchbase/management/scope_search_index_manager.rb +267 -0
  41. data/lib/couchbase/management/search_index_manager.rb +649 -0
  42. data/lib/couchbase/management/user_manager.rb +639 -0
  43. data/lib/couchbase/management/view_index_manager.rb +332 -0
  44. data/lib/couchbase/management.rb +31 -0
  45. data/lib/couchbase/metrics/logging_meter.rb +108 -0
  46. data/lib/couchbase/metrics/logging_value_recorder.rb +50 -0
  47. data/lib/couchbase/metrics/meter.rb +27 -0
  48. data/lib/couchbase/metrics/noop_meter.rb +30 -0
  49. data/lib/couchbase/metrics/noop_value_recorder.rb +27 -0
  50. data/lib/couchbase/metrics/value_recorder.rb +25 -0
  51. data/lib/couchbase/mutation_state.rb +65 -0
  52. data/lib/couchbase/options.rb +3097 -0
  53. data/lib/couchbase/protostellar/binary_collection.rb +55 -0
  54. data/lib/couchbase/protostellar/bucket.rb +59 -0
  55. data/lib/couchbase/protostellar/client.rb +97 -0
  56. data/lib/couchbase/protostellar/cluster.rb +182 -0
  57. data/lib/couchbase/protostellar/collection.rb +156 -0
  58. data/lib/couchbase/protostellar/connect_options.rb +63 -0
  59. data/lib/couchbase/protostellar/error_handling.rb +204 -0
  60. data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_pb.rb +54 -0
  61. data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_services_pb.rb +51 -0
  62. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +42 -0
  63. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +51 -0
  64. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +38 -0
  65. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +52 -0
  66. data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +42 -0
  67. data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +55 -0
  68. data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +51 -0
  69. data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +67 -0
  70. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +31 -0
  71. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +40 -0
  72. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +51 -0
  73. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +54 -0
  74. data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_pb.rb +46 -0
  75. data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_services_pb.rb +56 -0
  76. data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +74 -0
  77. data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +93 -0
  78. data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +35 -0
  79. data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +40 -0
  80. data/lib/couchbase/protostellar/generated/routing/v2/routing_pb.rb +26 -0
  81. data/lib/couchbase/protostellar/generated/routing/v2/routing_services_pb.rb +43 -0
  82. data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +78 -0
  83. data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +41 -0
  84. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +36 -0
  85. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +66 -0
  86. data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +30 -0
  87. data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +39 -0
  88. data/lib/couchbase/protostellar/generated.rb +9 -0
  89. data/lib/couchbase/protostellar/management/bucket_manager.rb +67 -0
  90. data/lib/couchbase/protostellar/management/collection_manager.rb +94 -0
  91. data/lib/couchbase/protostellar/management/collection_query_index_manager.rb +124 -0
  92. data/lib/couchbase/protostellar/management/query_index_manager.rb +112 -0
  93. data/lib/couchbase/protostellar/management.rb +24 -0
  94. data/lib/couchbase/protostellar/request.rb +79 -0
  95. data/lib/couchbase/protostellar/request_behaviour.rb +42 -0
  96. data/lib/couchbase/protostellar/request_generator/admin/bucket.rb +124 -0
  97. data/lib/couchbase/protostellar/request_generator/admin/collection.rb +96 -0
  98. data/lib/couchbase/protostellar/request_generator/admin/query.rb +132 -0
  99. data/lib/couchbase/protostellar/request_generator/admin.rb +24 -0
  100. data/lib/couchbase/protostellar/request_generator/kv.rb +488 -0
  101. data/lib/couchbase/protostellar/request_generator/query.rb +133 -0
  102. data/lib/couchbase/protostellar/request_generator/search.rb +403 -0
  103. data/lib/couchbase/protostellar/request_generator.rb +26 -0
  104. data/lib/couchbase/protostellar/response_converter/admin/bucket.rb +55 -0
  105. data/lib/couchbase/protostellar/response_converter/admin/collection.rb +42 -0
  106. data/lib/couchbase/protostellar/response_converter/admin/query.rb +59 -0
  107. data/lib/couchbase/protostellar/response_converter/admin.rb +24 -0
  108. data/lib/couchbase/protostellar/response_converter/kv.rb +151 -0
  109. data/lib/couchbase/protostellar/response_converter/query.rb +84 -0
  110. data/lib/couchbase/protostellar/response_converter/search.rb +136 -0
  111. data/lib/couchbase/protostellar/response_converter.rb +26 -0
  112. data/lib/couchbase/protostellar/retry/action.rb +38 -0
  113. data/lib/couchbase/protostellar/retry/orchestrator.rb +61 -0
  114. data/lib/couchbase/protostellar/retry/reason.rb +67 -0
  115. data/lib/couchbase/protostellar/retry/strategies/best_effort.rb +49 -0
  116. data/lib/couchbase/protostellar/retry/strategies/fail_fast.rb +33 -0
  117. data/lib/couchbase/protostellar/retry/strategies.rb +27 -0
  118. data/lib/couchbase/protostellar/retry.rb +28 -0
  119. data/lib/couchbase/protostellar/scope.rb +61 -0
  120. data/lib/couchbase/protostellar/timeout_defaults.rb +30 -0
  121. data/lib/couchbase/protostellar/timeouts.rb +83 -0
  122. data/lib/couchbase/protostellar.rb +29 -0
  123. data/lib/couchbase/query_options.rb +122 -0
  124. data/lib/couchbase/railtie.rb +47 -0
  125. data/lib/couchbase/raw_binary_transcoder.rb +39 -0
  126. data/lib/couchbase/raw_json_transcoder.rb +40 -0
  127. data/lib/couchbase/raw_string_transcoder.rb +42 -0
  128. data/lib/couchbase/scope.rb +272 -0
  129. data/lib/couchbase/search_options.rb +1744 -0
  130. data/lib/couchbase/subdoc.rb +293 -0
  131. data/lib/couchbase/tracing/noop_span.rb +29 -0
  132. data/lib/couchbase/tracing/noop_tracer.rb +29 -0
  133. data/lib/couchbase/tracing/request_span.rb +34 -0
  134. data/lib/couchbase/tracing/request_tracer.rb +28 -0
  135. data/lib/couchbase/tracing/threshold_logging_span.rb +112 -0
  136. data/lib/couchbase/tracing/threshold_logging_tracer.rb +231 -0
  137. data/lib/couchbase/transcoder_flags.rb +64 -0
  138. data/lib/couchbase/utils/generic_logger_adapter.rb +40 -0
  139. data/lib/couchbase/utils/hdr_histogram.rb +55 -0
  140. data/lib/couchbase/utils/observability.rb +263 -0
  141. data/lib/couchbase/utils/observability_constants.rb +200 -0
  142. data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
  143. data/lib/couchbase/utils/time.rb +71 -0
  144. data/lib/couchbase/utils.rb +23 -0
  145. data/lib/couchbase/version.rb +25 -0
  146. data/lib/couchbase/view_options.rb +67 -0
  147. data/lib/couchbase.rb +32 -0
  148. data/lib/rails/generators/couchbase/config/config_generator.rb +29 -0
  149. metadata +228 -0
@@ -0,0 +1,649 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020-2021 Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "couchbase/errors"
18
+ require "couchbase/options"
19
+
20
+ module Couchbase
21
+ module Management
22
+ module Options
23
+ module Search
24
+ # Options for {SearchIndexManager#get_index}
25
+ class GetIndex < ::Couchbase::Options::Base
26
+ # Creates an instance of options for {SearchIndexManager#get_index}
27
+ #
28
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
29
+ # @param [Symbol, nil] retry_strategy ignored by this operation
30
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
31
+ #
32
+ # @yieldparam [GetIndex] self
33
+ def initialize(timeout: nil,
34
+ retry_strategy: nil,
35
+ parent_span: nil)
36
+ super
37
+ yield self if block_given?
38
+ end
39
+
40
+ # @api private
41
+ DEFAULT = new.freeze
42
+ end
43
+
44
+ # Options for {SearchIndexManager#get_all_indexes}
45
+ class GetAllIndexes < ::Couchbase::Options::Base
46
+ # Creates an instance of options for {SearchIndexManager#get_all_indexes}
47
+ #
48
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
49
+ # @param [Symbol, nil] retry_strategy ignored by this operation
50
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
51
+ #
52
+ # @yieldparam [GetAllIndexes] self
53
+ def initialize(timeout: nil,
54
+ retry_strategy: nil,
55
+ parent_span: nil)
56
+ super
57
+ yield self if block_given?
58
+ end
59
+
60
+ # @api private
61
+ DEFAULT = new.freeze
62
+ end
63
+
64
+ # Options for {SearchIndexManager#upsert_index}
65
+ class UpsertIndex < ::Couchbase::Options::Base
66
+ # Creates an instance of options for {SearchIndexManager#upsert_index}
67
+ #
68
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
69
+ # @param [Symbol, nil] retry_strategy ignored by this operation
70
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
71
+ #
72
+ # @yieldparam [UpsertIndex] self
73
+ def initialize(timeout: nil,
74
+ retry_strategy: nil,
75
+ parent_span: nil)
76
+ super
77
+ yield self if block_given?
78
+ end
79
+
80
+ # @api private
81
+ DEFAULT = new.freeze
82
+ end
83
+
84
+ # Options for {SearchIndexManager#drop_index}
85
+ class DropIndex < ::Couchbase::Options::Base
86
+ # Creates an instance of options for {SearchIndexManager#drop_index}
87
+ #
88
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
89
+ # @param [Symbol, nil] retry_strategy ignored by this operation
90
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
91
+ #
92
+ # @yieldparam [DropIndex] self
93
+ def initialize(timeout: nil,
94
+ retry_strategy: nil,
95
+ parent_span: nil)
96
+ super
97
+ yield self if block_given?
98
+ end
99
+
100
+ # @api private
101
+ DEFAULT = new.freeze
102
+ end
103
+
104
+ # Options for {SearchIndexManager#get_indexed_documents_count}
105
+ class GetIndexedDocumentsCount < ::Couchbase::Options::Base
106
+ # Creates an instance of options for {SearchIndexManager#get_indexed_documents_count}
107
+ #
108
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
109
+ # @param [Symbol, nil] retry_strategy ignored by this operation
110
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
111
+ #
112
+ # @yieldparam [GetIndexedDocumentsCount] self
113
+ def initialize(timeout: nil,
114
+ retry_strategy: nil,
115
+ parent_span: nil)
116
+ super
117
+ yield self if block_given?
118
+ end
119
+
120
+ # @api private
121
+ DEFAULT = new.freeze
122
+ end
123
+
124
+ # Options for {SearchIndexManager#get_index_stats}
125
+ class GetIndexStats < ::Couchbase::Options::Base
126
+ # Creates an instance of options for {SearchIndexManager#get_index_stats}
127
+ #
128
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
129
+ # @param [Symbol, nil] retry_strategy ignored by this operation
130
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
131
+ #
132
+ # @yieldparam [GetIndexStats] self
133
+ def initialize(timeout: nil,
134
+ retry_strategy: nil,
135
+ parent_span: nil)
136
+ super
137
+ yield self if block_given?
138
+ end
139
+
140
+ # @api private
141
+ DEFAULT = new.freeze
142
+ end
143
+
144
+ # Options for {SearchIndexManager#pause_ingest}
145
+ class PauseIngest < ::Couchbase::Options::Base
146
+ # Creates an instance of options for {SearchIndexManager#pause_ingest}
147
+ #
148
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
149
+ # @param [Symbol, nil] retry_strategy ignored by this operation
150
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
151
+ #
152
+ # @yieldparam [PauseIngest] self
153
+ def initialize(timeout: nil,
154
+ retry_strategy: nil,
155
+ parent_span: nil)
156
+ super
157
+ yield self if block_given?
158
+ end
159
+
160
+ # @api private
161
+ DEFAULT = new.freeze
162
+ end
163
+
164
+ # Options for {SearchIndexManager#resume_ingest}
165
+ class ResumeIngest < ::Couchbase::Options::Base
166
+ # Creates an instance of options for {SearchIndexManager#resume_ingest}
167
+ #
168
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
169
+ # @param [Symbol, nil] retry_strategy ignored by this operation
170
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
171
+ #
172
+ # @yieldparam [ResumeIngest] self
173
+ def initialize(timeout: nil,
174
+ retry_strategy: nil,
175
+ parent_span: nil)
176
+ super
177
+ yield self if block_given?
178
+ end
179
+
180
+ # @api private
181
+ DEFAULT = new.freeze
182
+ end
183
+
184
+ # Options for {SearchIndexManager#allow_querying}
185
+ class AllowQuerying < ::Couchbase::Options::Base
186
+ # Creates an instance of options for {SearchIndexManager#allow_querying}
187
+ #
188
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
189
+ # @param [Symbol, nil] retry_strategy ignored by this operation
190
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
191
+ #
192
+ # @yieldparam [AllowQuerying] self
193
+ def initialize(timeout: nil,
194
+ retry_strategy: nil,
195
+ parent_span: nil)
196
+ super
197
+ yield self if block_given?
198
+ end
199
+
200
+ # @api private
201
+ DEFAULT = new.freeze
202
+ end
203
+
204
+ # Options for {SearchIndexManager#disallow_querying}
205
+ class DisallowQuerying < ::Couchbase::Options::Base
206
+ # Creates an instance of options for {SearchIndexManager#disallow_querying}
207
+ #
208
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
209
+ # @param [Symbol, nil] retry_strategy ignored by this operation
210
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
211
+ #
212
+ # @yieldparam [DisallowQuerying] self
213
+ def initialize(timeout: nil,
214
+ retry_strategy: nil,
215
+ parent_span: nil)
216
+ super
217
+ yield self if block_given?
218
+ end
219
+
220
+ # @api private
221
+ DEFAULT = new.freeze
222
+ end
223
+
224
+ # Options for {SearchIndexManager#freeze_plan}
225
+ class FreezePlan < ::Couchbase::Options::Base
226
+ # Creates an instance of options for {SearchIndexManager#freeze_plan}
227
+ #
228
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
229
+ # @param [Symbol, nil] retry_strategy ignored by this operation
230
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
231
+ #
232
+ # @yieldparam [FreezePlan] self
233
+ def initialize(timeout: nil,
234
+ retry_strategy: nil,
235
+ parent_span: nil)
236
+ super
237
+ yield self if block_given?
238
+ end
239
+
240
+ # @api private
241
+ DEFAULT = new.freeze
242
+ end
243
+
244
+ # Options for {SearchIndexManager#unfreeze_plan}
245
+ class UnfreezePlan < ::Couchbase::Options::Base
246
+ # Creates an instance of options for {SearchIndexManager#unfreeze_plan}
247
+ #
248
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
249
+ # @param [Symbol, nil] retry_strategy ignored by this operation
250
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
251
+ #
252
+ # @yieldparam [UnfreezePlan] self
253
+ def initialize(timeout: nil,
254
+ retry_strategy: nil,
255
+ parent_span: nil)
256
+ super
257
+ yield self if block_given?
258
+ end
259
+
260
+ # @api private
261
+ DEFAULT = new.freeze
262
+ end
263
+
264
+ # Options for {SearchIndexManager#analyze_document}
265
+ class AnalyzeDocument < ::Couchbase::Options::Base
266
+ # Creates an instance of options for {SearchIndexManager#analyze_document}
267
+ #
268
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
269
+ # @param [Symbol, nil] retry_strategy ignored by this operation
270
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
271
+ #
272
+ # @yieldparam [AnalyzeDocument] self
273
+ def initialize(timeout: nil,
274
+ retry_strategy: nil,
275
+ parent_span: nil)
276
+ super
277
+ yield self if block_given?
278
+ end
279
+
280
+ # @api private
281
+ DEFAULT = new.freeze
282
+ end
283
+ end
284
+ end
285
+
286
+ class SearchIndexManager
287
+ alias inspect to_s
288
+
289
+ # @param [Couchbase::Backend] backend
290
+ # @param [Couchbase::Observability::Wrapper] observability wrapper
291
+ #
292
+ # @api private
293
+ def initialize(backend, observability)
294
+ @backend = backend
295
+ @observability = observability
296
+ end
297
+
298
+ # Fetches an index from the server if it exists
299
+ #
300
+ # @param [String] index_name name of the index
301
+ # @param [Options::Search::GetIndex] options
302
+ #
303
+ # @return [SearchIndex]
304
+ #
305
+ # @raise [ArgumentError]
306
+ # @raise [Error::IndexNotFound]
307
+ def get_index(index_name, options = Options::Search::GetIndex::DEFAULT)
308
+ @observability.record_operation(Observability::OP_SM_GET_INDEX, options.parent_span, self, :search) do |obs_handler|
309
+ res = @backend.search_index_get(nil, nil, index_name, options.timeout, obs_handler)
310
+ self.class.extract_search_index(res)
311
+ end
312
+ end
313
+
314
+ # Fetches all indexes from the server
315
+ #
316
+ # @param [Options::Search::GetAllIndexes] options
317
+ #
318
+ # @return [Array<SearchIndex>]
319
+ def get_all_indexes(options = Options::Search::GetAllIndexes::DEFAULT)
320
+ @observability.record_operation(Observability::OP_SM_GET_ALL_INDEXES, options.parent_span, self, :search) do |obs_handler|
321
+ res = @backend.search_index_get_all(nil, nil, options.timeout, obs_handler)
322
+ res[:indexes].map { |idx| self.class.extract_search_index(idx) }
323
+ end
324
+ end
325
+
326
+ # Creates or updates the index
327
+ #
328
+ # @param [SearchIndex] index_definition the index definition
329
+ # @param [Options::Search::UpsertIndex] options
330
+ #
331
+ # @return void
332
+ #
333
+ # @raise [ArgumentError] if name, type or source_type is empty
334
+ def upsert_index(index_definition, options = Options::Search::UpsertIndex::DEFAULT)
335
+ @observability.record_operation(Observability::OP_SM_UPSERT_INDEX, options.parent_span, self, :search) do |obs_handler|
336
+ @backend.search_index_upsert(
337
+ nil,
338
+ nil,
339
+ {
340
+ name: index_definition.name,
341
+ type: index_definition.type,
342
+ uuid: index_definition.uuid,
343
+ params: (JSON.generate(index_definition.params) if index_definition.params),
344
+ source_name: index_definition.source_name,
345
+ source_type: index_definition.source_type,
346
+ source_uuid: index_definition.source_uuid,
347
+ source_params: (JSON.generate(index_definition.source_params) if index_definition.source_params),
348
+ plan_params: (JSON.generate(index_definition.plan_params) if index_definition.plan_params),
349
+ },
350
+ options.timeout,
351
+ obs_handler,
352
+ )
353
+ end
354
+ end
355
+
356
+ # Drops the index
357
+ #
358
+ # @param [String] index_name name of the index
359
+ # @param [Options::Search::DropIndex] options
360
+ #
361
+ # @return void
362
+ #
363
+ # @raise [ArgumentError]
364
+ # @raise [Error::IndexNotFound]
365
+ def drop_index(index_name, options = Options::Search::DropIndex::DEFAULT)
366
+ @observability.record_operation(Observability::OP_SM_DROP_INDEX, options.parent_span, self, :search) do |obs_handler|
367
+ @backend.search_index_drop(nil, nil, index_name, options.timeout, obs_handler)
368
+ end
369
+ end
370
+
371
+ # Retrieves the number of documents that have been indexed for an index
372
+ #
373
+ # @param [String] index_name name of the index
374
+ # @param [Options::Search::GetIndexedDocumentsCount] options
375
+ #
376
+ # @return [Integer]
377
+ #
378
+ # @raise [ArgumentError]
379
+ # @raise [Error::IndexNotFound]
380
+ def get_indexed_documents_count(index_name, options = Options::Search::GetIndexedDocumentsCount::DEFAULT)
381
+ @observability.record_operation(Observability::OP_SM_GET_INDEXED_DOCUMENTS_COUNT, options.parent_span, self,
382
+ :search) do |obs_handler|
383
+ res = @backend.search_index_get_documents_count(nil, nil, index_name, options.timeout, obs_handler)
384
+ res[:count]
385
+ end
386
+ end
387
+
388
+ # Retrieves metrics, timings and counters for a given index
389
+ #
390
+ # @!macro uncommitted
391
+ #
392
+ # @param [String] index_name name of the index
393
+ # @param [Options::Search::GetIndexStats] options
394
+ #
395
+ # @return [Integer]
396
+ #
397
+ # @raise [ArgumentError]
398
+ # @raise [Error::IndexNotFound]
399
+ def get_index_stats(index_name, options = Options::Search::GetIndexStats::DEFAULT)
400
+ @observability.record_operation(Observability::OP_SM_GET_INDEX_STATS, options.parent_span, self, :search) do |obs_handler|
401
+ res = @backend.search_index_get_stats(index_name, options.timeout, obs_handler)
402
+ JSON.parse(res)
403
+ end
404
+ end
405
+
406
+ # Retrieves statistics on search service. Information is provided on documents, partition indexes, mutations,
407
+ # compactions, queries, and more.
408
+ #
409
+ # @!macro uncommitted
410
+ #
411
+ # @param [Options::Search::GetIndexStats] options
412
+ #
413
+ # @return [Integer]
414
+ #
415
+ # @raise [ArgumentError]
416
+ def get_stats(options = Options::Search::GetIndexStats::DEFAULT)
417
+ @observability.record_operation(Observability::OP_SM_GET_STATS, options.parent_span, self, :search) do |obs_handler|
418
+ res = @backend.search_get_stats(options.timeout, obs_handler)
419
+ JSON.parse(res)
420
+ end
421
+ end
422
+
423
+ # Pauses updates and maintenance for the index
424
+ #
425
+ # @param [String] index_name name of the index
426
+ # @param [Options::Search::PauseIngest] options
427
+ #
428
+ # @return void
429
+ #
430
+ # @raise [ArgumentError]
431
+ # @raise [Error::IndexNotFound]
432
+ def pause_ingest(index_name, options = Options::Search::PauseIngest::DEFAULT)
433
+ @observability.record_operation(Observability::OP_SM_PAUSE_INGEST, options.parent_span, self, :search) do |obs_handler|
434
+ @backend.search_index_pause_ingest(nil, nil, index_name, options.timeout, obs_handler)
435
+ end
436
+ end
437
+
438
+ # Resumes updates and maintenance for an index
439
+ #
440
+ # @param [String] index_name name of the index
441
+ # @param [Options::Search::ResumeIngest] options
442
+ #
443
+ # @return void
444
+ #
445
+ # @raise [ArgumentError]
446
+ # @raise [Error::IndexNotFound]
447
+ def resume_ingest(index_name, options = Options::Search::ResumeIngest::DEFAULT)
448
+ @observability.record_operation(Observability::OP_SM_RESUME_INGEST, options.parent_span, self, :search) do |obs_handler|
449
+ @backend.search_index_resume_ingest(nil, nil, index_name, options.timeout, obs_handler)
450
+ end
451
+ end
452
+
453
+ # Allows querying against the index
454
+ #
455
+ # @param [String] index_name name of the index
456
+ # @param [Options::Search::AllowQuerying] options
457
+ #
458
+ # @return void
459
+ #
460
+ # @raise [ArgumentError]
461
+ # @raise [Error::IndexNotFound]
462
+ def allow_querying(index_name, options = Options::Search::AllowQuerying::DEFAULT)
463
+ @observability.record_operation(Observability::OP_SM_ALLOW_QUERYING, options.parent_span, self, :search) do |obs_handler|
464
+ @backend.search_index_allow_querying(nil, nil, index_name, options.timeout, obs_handler)
465
+ end
466
+ end
467
+
468
+ # Disallows querying against the index
469
+ #
470
+ # @param [String] index_name name of the index
471
+ # @param [Options::Search::DisallowQuerying] options
472
+ #
473
+ # @return void
474
+ #
475
+ # @raise [ArgumentError]
476
+ # @raise [Error::IndexNotFound]
477
+ def disallow_querying(index_name, options = Options::Search::DisallowQuerying::DEFAULT)
478
+ @observability.record_operation(Observability::OP_SM_DISALLOW_QUERYING, options.parent_span, self, :search) do |obs_handler|
479
+ @backend.search_index_disallow_querying(nil, nil, index_name, options.timeout, obs_handler)
480
+ end
481
+ end
482
+
483
+ # Freeze the assignment of index partitions to nodes
484
+ #
485
+ # @param [String] index_name name of the index
486
+ # @param [Options::Search::FreezePlan] options
487
+ #
488
+ # @return void
489
+ #
490
+ # @raise [ArgumentError]
491
+ # @raise [Error::IndexNotFound]
492
+ def freeze_plan(index_name, options = Options::Search::FreezePlan::DEFAULT)
493
+ @observability.record_operation(Observability::OP_SM_FREEZE_PLAN, options.parent_span, self, :search) do |obs_handler|
494
+ @backend.search_index_freeze_plan(nil, nil, index_name, options.timeout, obs_handler)
495
+ end
496
+ end
497
+
498
+ # Unfreeze the assignment of index partitions to nodes
499
+ #
500
+ # @param [String] index_name name of the index
501
+ # @param [Options::Search::UnfreezePlan] options
502
+ #
503
+ # @return void
504
+ #
505
+ # @raise [ArgumentError]
506
+ # @raise [Error::IndexNotFound]
507
+ def unfreeze_plan(index_name, options = Options::Search::UnfreezePlan::DEFAULT)
508
+ @observability.record_operation(Observability::OP_SM_UNFREEZE_PLAN, options.parent_span, self, :search) do |obs_handler|
509
+ @backend.search_index_unfreeze_plan(nil, nil, index_name, options.timeout, obs_handler)
510
+ end
511
+ end
512
+
513
+ # Allows to see how a document is analyzed against a specific index
514
+ #
515
+ # @param [String] index_name name of the index
516
+ # @param [Hash] document the document to be analyzed
517
+ # @param [Options::Search::AnalyzeDocument] options
518
+ #
519
+ # @return [Array<Hash>]
520
+ #
521
+ # @raise [ArgumentError]
522
+ # @raise [Error::IndexNotFound]
523
+ def analyze_document(index_name, document, options = Options::Search::AnalyzeDocument::DEFAULT)
524
+ @observability.record_operation(Observability::OP_SM_ANALYZE_DOCUMENT, options.parent_span, self, :search) do |obs_handler|
525
+ res = @backend.search_index_analyze_document(nil, nil, index_name, JSON.generate(document), options.timeout, obs_handler)
526
+ JSON.parse(res[:analysis])
527
+ end
528
+ end
529
+
530
+ # @api private
531
+ # @deprecated use {Options::Search::GetIndex} instead
532
+ GetIndexOptions = Options::Search::GetIndex
533
+
534
+ # @api private
535
+ # @deprecated use {Options::Search::GetAllIndexes} instead
536
+ GetAllIndexesOptions = Options::Search::GetAllIndexes
537
+
538
+ # @api private
539
+ # @deprecated use {Options::Search::UpsertIndex} instead
540
+ UpsertIndexOptions = Options::Search::UpsertIndex
541
+
542
+ # @api private
543
+ # @deprecated use {Options::Search::DropIndex} instead
544
+ DropIndexOptions = Options::Search::DropIndex
545
+
546
+ # @api private
547
+ # @deprecated use {Options::Search::GetIndexedDocumentsCount} instead
548
+ GetIndexedDocumentsCountOptions = Options::Search::GetIndexedDocumentsCount
549
+
550
+ # @api private
551
+ # @deprecated use {Options::Search::GetIndexStats} instead
552
+ GetIndexStatsOptions = Options::Search::GetIndexStats
553
+
554
+ # @api private
555
+ # @deprecated use {Options::Search::PauseIngest} instead
556
+ PauseIngestOptions = Options::Search::PauseIngest
557
+
558
+ # @api private
559
+ # @deprecated use {Options::Search::ResumeIngest} instead
560
+ ResumeIngestOptions = Options::Search::ResumeIngest
561
+
562
+ # @api private
563
+ # @deprecated use {Options::Search::AllowQuerying} instead
564
+ AllowQueryingOptions = Options::Search::AllowQuerying
565
+
566
+ # @api private
567
+ # @deprecated use {Options::Search::DisallowQuerying} instead
568
+ DisallowQueryingOptions = Options::Search::DisallowQuerying
569
+
570
+ # @api private
571
+ # @deprecated use {Options::Search::FreezePlan} instead
572
+ FreezePlanOptions = Options::Search::FreezePlan
573
+
574
+ # @api private
575
+ # @deprecated use {Options::Search::UnfreezePlan} instead
576
+ UnfreezePlanOptions = Options::Search::UnfreezePlan
577
+
578
+ # @api private
579
+ # @deprecated use {Options::Search::AnalyzeDocument} instead
580
+ AnalyzeDocumentOptions = Options::Search::AnalyzeDocument
581
+
582
+ # @api private
583
+ def self.extract_search_index(resp)
584
+ SearchIndex.new do |index|
585
+ index.name = resp[:name]
586
+ index.type = resp[:type]
587
+ index.uuid = resp[:uuid]
588
+ index.params = resp[:params] ? JSON.parse(resp[:params]) : {}
589
+ index.source_name = resp[:source_name]
590
+ index.source_type = resp[:source_type]
591
+ index.source_uuid = resp[:source_uuid]
592
+ index.source_params = resp[:source_params] ? JSON.parse(resp[:source_params]) : {}
593
+ index.plan_params = resp[:plan_params] ? JSON.parse(resp[:plan_params]) : {}
594
+ end
595
+ end
596
+ end
597
+
598
+ class SearchIndex
599
+ # @return [String] name of the index
600
+ attr_accessor :name
601
+
602
+ # @return [String] type of the index
603
+ attr_accessor :type
604
+
605
+ # @return [String] UUID is required for update. It provides means of ensuring consistency.
606
+ attr_accessor :uuid
607
+
608
+ # @return [Hash] index properties such as store type and mappings
609
+ attr_accessor :params
610
+
611
+ # @return [String] name of the source of the data for the index (e.g. bucket name)
612
+ attr_accessor :source_name
613
+
614
+ # @return [String] type of the data source
615
+ attr_accessor :source_type
616
+
617
+ # @return [String] the UUID of the ata source, this can be used to more tightly tie the index to a source
618
+ attr_accessor :source_uuid
619
+
620
+ # @return [Hash] extra parameters for the source. These are usually things like advanced connection and tuning.
621
+ attr_accessor :source_params
622
+
623
+ # @return [Hash] plan properties such a number of replicas and number of partitions
624
+ attr_accessor :plan_params
625
+
626
+ # @yieldparam [SearchIndex] self
627
+ def initialize
628
+ @type = "fulltext-index"
629
+ @source_type = "couchbase"
630
+ yield self if block_given?
631
+ end
632
+
633
+ # @api private
634
+ def to_backend
635
+ {
636
+ name: name,
637
+ type: type,
638
+ uuid: uuid,
639
+ params: (JSON.generate(params) if params),
640
+ source_name: source_name,
641
+ source_type: source_type,
642
+ source_uuid: source_uuid,
643
+ source_params: (JSON.generate(source_params) if source_params),
644
+ plan_params: (JSON.generate(plan_params) if plan_params),
645
+ }
646
+ end
647
+ end
648
+ end
649
+ end