couchbase 3.5.2-x86_64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) 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 +342 -0
  6. data/lib/couchbase/3.1/libcouchbase.bundle +0 -0
  7. data/lib/couchbase/3.2/libcouchbase.bundle +0 -0
  8. data/lib/couchbase/3.3/libcouchbase.bundle +0 -0
  9. data/lib/couchbase/analytics_options.rb +109 -0
  10. data/lib/couchbase/authenticator.rb +66 -0
  11. data/lib/couchbase/binary_collection.rb +130 -0
  12. data/lib/couchbase/binary_collection_options.rb +26 -0
  13. data/lib/couchbase/bucket.rb +146 -0
  14. data/lib/couchbase/cluster.rb +462 -0
  15. data/lib/couchbase/cluster_registry.rb +49 -0
  16. data/lib/couchbase/collection.rb +707 -0
  17. data/lib/couchbase/collection_options.rb +401 -0
  18. data/lib/couchbase/config_profiles.rb +57 -0
  19. data/lib/couchbase/configuration.rb +58 -0
  20. data/lib/couchbase/datastructures/couchbase_list.rb +160 -0
  21. data/lib/couchbase/datastructures/couchbase_map.rb +194 -0
  22. data/lib/couchbase/datastructures/couchbase_queue.rb +134 -0
  23. data/lib/couchbase/datastructures/couchbase_set.rb +128 -0
  24. data/lib/couchbase/datastructures.rb +26 -0
  25. data/lib/couchbase/diagnostics.rb +183 -0
  26. data/lib/couchbase/errors.rb +414 -0
  27. data/lib/couchbase/json_transcoder.rb +41 -0
  28. data/lib/couchbase/key_value_scan.rb +119 -0
  29. data/lib/couchbase/libcouchbase.rb +6 -0
  30. data/lib/couchbase/logger.rb +87 -0
  31. data/lib/couchbase/management/analytics_index_manager.rb +1129 -0
  32. data/lib/couchbase/management/bucket_manager.rb +445 -0
  33. data/lib/couchbase/management/collection_manager.rb +472 -0
  34. data/lib/couchbase/management/collection_query_index_manager.rb +224 -0
  35. data/lib/couchbase/management/query_index_manager.rb +619 -0
  36. data/lib/couchbase/management/scope_search_index_manager.rb +200 -0
  37. data/lib/couchbase/management/search_index_manager.rb +426 -0
  38. data/lib/couchbase/management/user_manager.rb +470 -0
  39. data/lib/couchbase/management/view_index_manager.rb +239 -0
  40. data/lib/couchbase/management.rb +31 -0
  41. data/lib/couchbase/mutation_state.rb +65 -0
  42. data/lib/couchbase/options.rb +2846 -0
  43. data/lib/couchbase/protostellar/binary_collection.rb +55 -0
  44. data/lib/couchbase/protostellar/bucket.rb +55 -0
  45. data/lib/couchbase/protostellar/client.rb +99 -0
  46. data/lib/couchbase/protostellar/cluster.rb +171 -0
  47. data/lib/couchbase/protostellar/collection.rb +152 -0
  48. data/lib/couchbase/protostellar/connect_options.rb +63 -0
  49. data/lib/couchbase/protostellar/error_handling.rb +203 -0
  50. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +61 -0
  51. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +35 -0
  52. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +57 -0
  53. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +36 -0
  54. data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +61 -0
  55. data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +37 -0
  56. data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +72 -0
  57. data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +44 -0
  58. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +52 -0
  59. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +30 -0
  60. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +70 -0
  61. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +36 -0
  62. data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +97 -0
  63. data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +46 -0
  64. data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +57 -0
  65. data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +30 -0
  66. data/lib/couchbase/protostellar/generated/routing/v1/routing_pb.rb +52 -0
  67. data/lib/couchbase/protostellar/generated/routing/v1/routing_services_pb.rb +30 -0
  68. data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +99 -0
  69. data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +30 -0
  70. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +57 -0
  71. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +36 -0
  72. data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +51 -0
  73. data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +30 -0
  74. data/lib/couchbase/protostellar/generated.rb +9 -0
  75. data/lib/couchbase/protostellar/management/bucket_manager.rb +67 -0
  76. data/lib/couchbase/protostellar/management/collection_manager.rb +94 -0
  77. data/lib/couchbase/protostellar/management/collection_query_index_manager.rb +124 -0
  78. data/lib/couchbase/protostellar/management/query_index_manager.rb +112 -0
  79. data/lib/couchbase/protostellar/management.rb +24 -0
  80. data/lib/couchbase/protostellar/request.rb +78 -0
  81. data/lib/couchbase/protostellar/request_behaviour.rb +42 -0
  82. data/lib/couchbase/protostellar/request_generator/admin/bucket.rb +124 -0
  83. data/lib/couchbase/protostellar/request_generator/admin/collection.rb +94 -0
  84. data/lib/couchbase/protostellar/request_generator/admin/query.rb +130 -0
  85. data/lib/couchbase/protostellar/request_generator/admin.rb +24 -0
  86. data/lib/couchbase/protostellar/request_generator/kv.rb +474 -0
  87. data/lib/couchbase/protostellar/request_generator/query.rb +133 -0
  88. data/lib/couchbase/protostellar/request_generator/search.rb +387 -0
  89. data/lib/couchbase/protostellar/request_generator.rb +26 -0
  90. data/lib/couchbase/protostellar/response_converter/admin/bucket.rb +55 -0
  91. data/lib/couchbase/protostellar/response_converter/admin/collection.rb +42 -0
  92. data/lib/couchbase/protostellar/response_converter/admin/query.rb +59 -0
  93. data/lib/couchbase/protostellar/response_converter/admin.rb +24 -0
  94. data/lib/couchbase/protostellar/response_converter/kv.rb +151 -0
  95. data/lib/couchbase/protostellar/response_converter/query.rb +84 -0
  96. data/lib/couchbase/protostellar/response_converter/search.rb +136 -0
  97. data/lib/couchbase/protostellar/response_converter.rb +26 -0
  98. data/lib/couchbase/protostellar/retry/action.rb +38 -0
  99. data/lib/couchbase/protostellar/retry/orchestrator.rb +60 -0
  100. data/lib/couchbase/protostellar/retry/reason.rb +67 -0
  101. data/lib/couchbase/protostellar/retry/strategies/best_effort.rb +49 -0
  102. data/lib/couchbase/protostellar/retry/strategies.rb +26 -0
  103. data/lib/couchbase/protostellar/retry.rb +28 -0
  104. data/lib/couchbase/protostellar/scope.rb +57 -0
  105. data/lib/couchbase/protostellar/timeout_defaults.rb +30 -0
  106. data/lib/couchbase/protostellar/timeouts.rb +83 -0
  107. data/lib/couchbase/protostellar.rb +29 -0
  108. data/lib/couchbase/query_options.rb +122 -0
  109. data/lib/couchbase/railtie.rb +47 -0
  110. data/lib/couchbase/raw_binary_transcoder.rb +39 -0
  111. data/lib/couchbase/raw_json_transcoder.rb +40 -0
  112. data/lib/couchbase/raw_string_transcoder.rb +42 -0
  113. data/lib/couchbase/scope.rb +258 -0
  114. data/lib/couchbase/search_options.rb +1650 -0
  115. data/lib/couchbase/subdoc.rb +293 -0
  116. data/lib/couchbase/transcoder_flags.rb +64 -0
  117. data/lib/couchbase/utils/generic_logger_adapter.rb +40 -0
  118. data/lib/couchbase/utils/stdlib_logger_adapter.rb +67 -0
  119. data/lib/couchbase/utils/time.rb +71 -0
  120. data/lib/couchbase/utils.rb +23 -0
  121. data/lib/couchbase/version.rb +25 -0
  122. data/lib/couchbase/view_options.rb +67 -0
  123. data/lib/couchbase.rb +30 -0
  124. data/lib/rails/generators/couchbase/config/config_generator.rb +29 -0
  125. metadata +190 -0
@@ -0,0 +1,200 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2024. 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
+ module Couchbase
18
+ module Management
19
+ class ScopeSearchIndexManager
20
+ alias inspect to_s
21
+
22
+ # @param [Couchbase::Backend] backend
23
+ # @param [String] bucket_name
24
+ # @param [String] scope_name
25
+ def initialize(backend, bucket_name, scope_name)
26
+ @backend = backend
27
+ @bucket_name = bucket_name
28
+ @scope_name = scope_name
29
+ end
30
+
31
+ # Fetches an index from the server if it exists
32
+ #
33
+ # @param [String] index_name name of the index
34
+ # @param [GetIndexOptions] options
35
+ #
36
+ # @return [SearchIndex]
37
+ #
38
+ # @raise [ArgumentError]
39
+ # @raise [Error::IndexNotFound]
40
+ def get_index(index_name, options = GetIndexOptions.new)
41
+ res = @backend.search_index_get(@bucket_name, @scope_name, index_name, options.timeout)
42
+ SearchIndexManager.extract_search_index(res)
43
+ end
44
+
45
+ # Fetches all indexes from the server
46
+ #
47
+ # @param [GetAllIndexesOptions] options
48
+ #
49
+ # @return [Array<SearchIndex>]
50
+ def get_all_indexes(options = GetAllIndexesOptions.new)
51
+ res = @backend.search_index_get_all(@bucket_name, @scope_name, options.timeout)
52
+ res[:indexes].map { |idx| SearchIndexManager.extract_search_index(idx) }
53
+ end
54
+
55
+ # Creates or updates the index
56
+ #
57
+ # @param [SearchIndex] index_definition the index definition
58
+ # @param [UpsertIndexOptions] options
59
+ #
60
+ # @return void
61
+ #
62
+ # @raise [ArgumentError] if name, type or source_type is empty
63
+ def upsert_index(index_definition, options = UpsertIndexOptions.new)
64
+ @backend.search_index_upsert(@bucket_name, @scope_name, index_definition.to_backend, options.timeout)
65
+ end
66
+
67
+ # Drops the index
68
+ #
69
+ # @param [String] index_name name of the index
70
+ # @param [DropIndexOptions] options
71
+ #
72
+ # @return void
73
+ #
74
+ # @raise [ArgumentError]
75
+ # @raise [Error::IndexNotFound]
76
+ def drop_index(index_name, options = DropIndexOptions.new)
77
+ @backend.search_index_drop(@bucket_name, @scope_name, index_name, options.timeout)
78
+ end
79
+
80
+ # Retrieves the number of documents that have been indexed for an index
81
+ #
82
+ # @param [String] index_name name of the index
83
+ # @param [GetIndexedDocumentsCountOptions] options
84
+ #
85
+ # @return [Integer]
86
+ #
87
+ # @raise [ArgumentError]
88
+ # @raise [Error::IndexNotFound]
89
+ def get_indexed_documents_count(index_name, options = GetIndexedDocumentsCountOptions.new)
90
+ res = @backend.search_index_get_documents_count(@bucket_name, @scope_name, index_name, options.timeout)
91
+ res[:count]
92
+ end
93
+
94
+ # Pauses updates and maintenance for the index
95
+ #
96
+ # @param [String] index_name name of the index
97
+ # @param [PauseIngestOptions] options
98
+ #
99
+ # @return void
100
+ #
101
+ # @raise [ArgumentError]
102
+ # @raise [Error::IndexNotFound]
103
+ def pause_ingest(index_name, options = PauseIngestOptions.new)
104
+ @backend.search_index_pause_ingest(@bucket_name, @scope_name, index_name, options.timeout)
105
+ end
106
+
107
+ # Resumes updates and maintenance for an index
108
+ #
109
+ # @param [String] index_name name of the index
110
+ # @param [ResumeIngestOptions] options
111
+ #
112
+ # @return void
113
+ #
114
+ # @raise [ArgumentError]
115
+ # @raise [Error::IndexNotFound]
116
+ def resume_ingest(index_name, options = ResumeIngestOptions.new)
117
+ @backend.search_index_resume_ingest(@bucket_name, @scope_name, index_name, options.timeout)
118
+ end
119
+
120
+ # Allows querying against the index
121
+ #
122
+ # @param [String] index_name name of the index
123
+ # @param [AllowQueryingOptions] options
124
+ #
125
+ # @return void
126
+ #
127
+ # @raise [ArgumentError]
128
+ # @raise [Error::IndexNotFound]
129
+ def allow_querying(index_name, options = AllowQueryingOptions.new)
130
+ @backend.search_index_allow_querying(@bucket_name, @scope_name, index_name, options.timeout)
131
+ end
132
+
133
+ # Disallows querying against the index
134
+ #
135
+ # @param [String] index_name name of the index
136
+ # @param [DisallowQueryingOptions] options
137
+ #
138
+ # @return void
139
+ #
140
+ # @raise [ArgumentError]
141
+ # @raise [Error::IndexNotFound]
142
+ def disallow_querying(index_name, options = DisallowQueryingOptions.new)
143
+ @backend.search_index_disallow_querying(@bucket_name, @scope_name, index_name, options.timeout)
144
+ end
145
+
146
+ # Freeze the assignment of index partitions to nodes
147
+ #
148
+ # @param [String] index_name name of the index
149
+ # @param [FreezePlanOptions] options
150
+ #
151
+ # @return void
152
+ #
153
+ # @raise [ArgumentError]
154
+ # @raise [Error::IndexNotFound]
155
+ def freeze_plan(index_name, options = FreezePlanOptions.new)
156
+ @backend.search_index_freeze_plan(@bucket_name, @scope_name, index_name, options.timeout)
157
+ end
158
+
159
+ # Unfreeze the assignment of index partitions to nodes
160
+ #
161
+ # @param [String] index_name name of the index
162
+ # @param [UnfreezePlanOptions] options
163
+ #
164
+ # @return void
165
+ #
166
+ # @raise [ArgumentError]
167
+ # @raise [Error::IndexNotFound]
168
+ def unfreeze_plan(index_name, options = UnfreezePlanOptions.new)
169
+ @backend.search_index_unfreeze_plan(@bucket_name, @scope_name, index_name, options.timeout)
170
+ end
171
+
172
+ # Allows to see how a document is analyzed against a specific index
173
+ #
174
+ # @param [String] index_name name of the index
175
+ # @param [Hash] document the document to be analyzed
176
+ #
177
+ # @return [Array<Hash>]
178
+ #
179
+ # @raise [ArgumentError]
180
+ # @raise [Error::IndexNotFound]
181
+ def analyze_document(index_name, document, options = AnalyzeDocumentOptions.new)
182
+ res = @backend.search_index_analyze_document(@bucket_name, @scope_name, index_name, JSON.generate(document), options.timeout)
183
+ JSON.parse(res[:analysis])
184
+ end
185
+
186
+ GetIndexOptions = SearchIndexManager::GetIndexOptions
187
+ GetAllIndexesOptions = SearchIndexManager::GetAllIndexesOptions
188
+ UpsertIndexOptions = SearchIndexManager::UpsertIndexOptions
189
+ DropIndexOptions = SearchIndexManager::DropIndexOptions
190
+ GetIndexedDocumentsCountOptions = SearchIndexManager::GetIndexedDocumentsCountOptions
191
+ PauseIngestOptions = SearchIndexManager::PauseIngestOptions
192
+ ResumeIngestOptions = SearchIndexManager::ResumeIngestOptions
193
+ AllowQueryingOptions = SearchIndexManager::AllowQueryingOptions
194
+ DisallowQueryingOptions = SearchIndexManager::DisallowQueryingOptions
195
+ FreezePlanOptions = SearchIndexManager::FreezePlanOptions
196
+ UnfreezePlanOptions = SearchIndexManager::UnfreezePlanOptions
197
+ AnalyzeDocumentOptions = SearchIndexManager::AnalyzeDocumentOptions
198
+ end
199
+ end
200
+ end
@@ -0,0 +1,426 @@
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
+
19
+ module Couchbase
20
+ module Management
21
+ class SearchIndexManager
22
+ alias inspect to_s
23
+
24
+ # @param [Couchbase::Backend] backend
25
+ def initialize(backend)
26
+ @backend = backend
27
+ end
28
+
29
+ # Fetches an index from the server if it exists
30
+ #
31
+ # @param [String] index_name name of the index
32
+ # @param [GetIndexOptions] options
33
+ #
34
+ # @return [SearchIndex]
35
+ #
36
+ # @raise [ArgumentError]
37
+ # @raise [Error::IndexNotFound]
38
+ def get_index(index_name, options = GetIndexOptions.new)
39
+ res = @backend.search_index_get(nil, nil, index_name, options.timeout)
40
+ self.class.extract_search_index(res)
41
+ end
42
+
43
+ # Fetches all indexes from the server
44
+ #
45
+ # @param [GetAllIndexesOptions] options
46
+ #
47
+ # @return [Array<SearchIndex>]
48
+ def get_all_indexes(options = GetAllIndexesOptions.new)
49
+ res = @backend.search_index_get_all(nil, nil, options.timeout)
50
+ res[:indexes].map { |idx| self.class.extract_search_index(idx) }
51
+ end
52
+
53
+ # Creates or updates the index
54
+ #
55
+ # @param [SearchIndex] index_definition the index definition
56
+ # @param [UpsertIndexOptions] options
57
+ #
58
+ # @return void
59
+ #
60
+ # @raise [ArgumentError] if name, type or source_type is empty
61
+ def upsert_index(index_definition, options = UpsertIndexOptions.new)
62
+ @backend.search_index_upsert(
63
+ nil,
64
+ nil,
65
+ {
66
+ name: index_definition.name,
67
+ type: index_definition.type,
68
+ uuid: index_definition.uuid,
69
+ params: (JSON.generate(index_definition.params) if index_definition.params),
70
+ source_name: index_definition.source_name,
71
+ source_type: index_definition.source_type,
72
+ source_uuid: index_definition.source_uuid,
73
+ source_params: (JSON.generate(index_definition.source_params) if index_definition.source_params),
74
+ plan_params: (JSON.generate(index_definition.plan_params) if index_definition.plan_params),
75
+ }, options.timeout
76
+ )
77
+ end
78
+
79
+ # Drops the index
80
+ #
81
+ # @param [String] index_name name of the index
82
+ # @param [DropIndexOptions] options
83
+ #
84
+ # @return void
85
+ #
86
+ # @raise [ArgumentError]
87
+ # @raise [Error::IndexNotFound]
88
+ def drop_index(index_name, options = DropIndexOptions.new)
89
+ @backend.search_index_drop(nil, nil, index_name, options.timeout)
90
+ end
91
+
92
+ # Retrieves the number of documents that have been indexed for an index
93
+ #
94
+ # @param [String] index_name name of the index
95
+ # @param [GetIndexedDocumentsCountOptions] options
96
+ #
97
+ # @return [Integer]
98
+ #
99
+ # @raise [ArgumentError]
100
+ # @raise [Error::IndexNotFound]
101
+ def get_indexed_documents_count(index_name, options = GetIndexedDocumentsCountOptions.new)
102
+ res = @backend.search_index_get_documents_count(nil, nil, index_name, options.timeout)
103
+ res[:count]
104
+ end
105
+
106
+ # Retrieves metrics, timings and counters for a given index
107
+ #
108
+ # @!macro uncommitted
109
+ #
110
+ # @param [String] index_name name of the index
111
+ # @param [GetIndexStatsOptions] options
112
+ #
113
+ # @return [Integer]
114
+ #
115
+ # @raise [ArgumentError]
116
+ # @raise [Error::IndexNotFound]
117
+ def get_index_stats(index_name, options = GetIndexStatsOptions.new)
118
+ res = @backend.search_index_get_stats(index_name, options.timeout)
119
+ JSON.parse(res)
120
+ end
121
+
122
+ # Retrieves statistics on search service. Information is provided on documents, partition indexes, mutations,
123
+ # compactions, queries, and more.
124
+ #
125
+ # @!macro uncommitted
126
+ #
127
+ # @param [GetIndexStatsOptions] options
128
+ #
129
+ # @return [Integer]
130
+ #
131
+ # @raise [ArgumentError]
132
+ def get_stats(options = GetIndexStatsOptions.new)
133
+ res = @backend.search_get_stats(options.timeout)
134
+ JSON.parse(res)
135
+ end
136
+
137
+ # Pauses updates and maintenance for the index
138
+ #
139
+ # @param [String] index_name name of the index
140
+ # @param [PauseIngestOptions] options
141
+ #
142
+ # @return void
143
+ #
144
+ # @raise [ArgumentError]
145
+ # @raise [Error::IndexNotFound]
146
+ def pause_ingest(index_name, options = PauseIngestOptions.new)
147
+ @backend.search_index_pause_ingest(nil, nil, index_name, options.timeout)
148
+ end
149
+
150
+ # Resumes updates and maintenance for an index
151
+ #
152
+ # @param [String] index_name name of the index
153
+ # @param [ResumeIngestOptions] options
154
+ #
155
+ # @return void
156
+ #
157
+ # @raise [ArgumentError]
158
+ # @raise [Error::IndexNotFound]
159
+ def resume_ingest(index_name, options = ResumeIngestOptions.new)
160
+ @backend.search_index_resume_ingest(nil, nil, index_name, options.timeout)
161
+ end
162
+
163
+ # Allows querying against the index
164
+ #
165
+ # @param [String] index_name name of the index
166
+ # @param [AllowQueryingOptions] options
167
+ #
168
+ # @return void
169
+ #
170
+ # @raise [ArgumentError]
171
+ # @raise [Error::IndexNotFound]
172
+ def allow_querying(index_name, options = AllowQueryingOptions.new)
173
+ @backend.search_index_allow_querying(nil, nil, index_name, options.timeout)
174
+ end
175
+
176
+ # Disallows querying against the index
177
+ #
178
+ # @param [String] index_name name of the index
179
+ # @param [DisallowQueryingOptions] options
180
+ #
181
+ # @return void
182
+ #
183
+ # @raise [ArgumentError]
184
+ # @raise [Error::IndexNotFound]
185
+ def disallow_querying(index_name, options = DisallowQueryingOptions.new)
186
+ @backend.search_index_disallow_querying(nil, nil, index_name, options.timeout)
187
+ end
188
+
189
+ # Freeze the assignment of index partitions to nodes
190
+ #
191
+ # @param [String] index_name name of the index
192
+ # @param [FreezePlanOptions] options
193
+ #
194
+ # @return void
195
+ #
196
+ # @raise [ArgumentError]
197
+ # @raise [Error::IndexNotFound]
198
+ def freeze_plan(index_name, options = FreezePlanOptions.new)
199
+ @backend.search_index_freeze_plan(nil, nil, index_name, options.timeout)
200
+ end
201
+
202
+ # Unfreeze the assignment of index partitions to nodes
203
+ #
204
+ # @param [String] index_name name of the index
205
+ # @param [UnfreezePlanOptions] options
206
+ #
207
+ # @return void
208
+ #
209
+ # @raise [ArgumentError]
210
+ # @raise [Error::IndexNotFound]
211
+ def unfreeze_plan(index_name, options = UnfreezePlanOptions.new)
212
+ @backend.search_index_unfreeze_plan(nil, nil, index_name, options.timeout)
213
+ end
214
+
215
+ # Allows to see how a document is analyzed against a specific index
216
+ #
217
+ # @param [String] index_name name of the index
218
+ # @param [Hash] document the document to be analyzed
219
+ #
220
+ # @return [Array<Hash>]
221
+ #
222
+ # @raise [ArgumentError]
223
+ # @raise [Error::IndexNotFound]
224
+ def analyze_document(index_name, document, options = AnalyzeDocumentOptions.new)
225
+ res = @backend.search_index_analyze_document(nil, nil, index_name, JSON.generate(document), options.timeout)
226
+ JSON.parse(res[:analysis])
227
+ end
228
+
229
+ class GetIndexOptions
230
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
231
+ attr_accessor :timeout
232
+
233
+ # @yieldparam [GetIndexOptions] self
234
+ def initialize
235
+ yield self if block_given?
236
+ end
237
+ end
238
+
239
+ class GetAllIndexesOptions
240
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
241
+ attr_accessor :timeout
242
+
243
+ # @yieldparam [GetAllIndexesOptions] self
244
+ def initialize
245
+ yield self if block_given?
246
+ end
247
+ end
248
+
249
+ class UpsertIndexOptions
250
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
251
+ attr_accessor :timeout
252
+
253
+ # @yieldparam [UpsertIndexOptions] self
254
+ def initialize
255
+ yield self if block_given?
256
+ end
257
+ end
258
+
259
+ class DropIndexOptions
260
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
261
+ attr_accessor :timeout
262
+
263
+ # @yieldparam [DropIndexOptions] self
264
+ def initialize
265
+ yield self if block_given?
266
+ end
267
+ end
268
+
269
+ class GetIndexedDocumentsCountOptions
270
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
271
+ attr_accessor :timeout
272
+
273
+ # @yieldparam [GetIndexedDocumentCountOptions] self
274
+ def initialize
275
+ yield self if block_given?
276
+ end
277
+ end
278
+
279
+ class GetIndexStatsOptions
280
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
281
+ attr_accessor :timeout
282
+
283
+ # @yieldparam [GetStatsOptions] self
284
+ def initialize
285
+ yield self if block_given?
286
+ end
287
+ end
288
+
289
+ class PauseIngestOptions
290
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
291
+ attr_accessor :timeout
292
+
293
+ # @yieldparam [PauseIngestOptions] self
294
+ def initialize
295
+ yield self if block_given?
296
+ end
297
+ end
298
+
299
+ class ResumeIngestOptions
300
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
301
+ attr_accessor :timeout
302
+
303
+ # @yieldparam [ResumeIngestOptions] self
304
+ def initialize
305
+ yield self if block_given?
306
+ end
307
+ end
308
+
309
+ class AllowQueryingOptions
310
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
311
+ attr_accessor :timeout
312
+
313
+ # @yieldparam [AllowQueryingOptions] self
314
+ def initialize
315
+ yield self if block_given?
316
+ end
317
+ end
318
+
319
+ class DisallowQueryingOptions
320
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
321
+ attr_accessor :timeout
322
+
323
+ # @yieldparam [DisallowQueryingOptions] self
324
+ def initialize
325
+ yield self if block_given?
326
+ end
327
+ end
328
+
329
+ class FreezePlanOptions
330
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
331
+ attr_accessor :timeout
332
+
333
+ # @yieldparam [FreezePlanOptions] self
334
+ def initialize
335
+ yield self if block_given?
336
+ end
337
+ end
338
+
339
+ class UnfreezePlanOptions
340
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
341
+ attr_accessor :timeout
342
+
343
+ # @yieldparam [UnfreezePlanOptions] self
344
+ def initialize
345
+ yield self if block_given?
346
+ end
347
+ end
348
+
349
+ class AnalyzeDocumentOptions
350
+ # @return [Integer] the time in milliseconds allowed for the operation to complete
351
+ attr_accessor :timeout
352
+
353
+ # @yieldparam [AnalyzeDocumentOptions] self
354
+ def initialize
355
+ yield self if block_given?
356
+ end
357
+ end
358
+
359
+ # @api private
360
+ def self.extract_search_index(resp)
361
+ SearchIndex.new do |index|
362
+ index.name = resp[:name]
363
+ index.type = resp[:type]
364
+ index.uuid = resp[:uuid]
365
+ index.params = resp[:params] ? JSON.parse(resp[:params]) : {}
366
+ index.source_name = resp[:source_name]
367
+ index.source_type = resp[:source_type]
368
+ index.source_uuid = resp[:source_uuid]
369
+ index.source_params = resp[:source_params] ? JSON.parse(resp[:source_params]) : {}
370
+ index.plan_params = resp[:plan_params] ? JSON.parse(resp[:plan_params]) : {}
371
+ end
372
+ end
373
+ end
374
+
375
+ class SearchIndex
376
+ # @return [String] name of the index
377
+ attr_accessor :name
378
+
379
+ # @return [String] type of the index
380
+ attr_accessor :type
381
+
382
+ # @return [String] UUID is required for update. It provides means of ensuring consistency.
383
+ attr_accessor :uuid
384
+
385
+ # @return [Hash] index properties such as store type and mappings
386
+ attr_accessor :params
387
+
388
+ # @return [String] name of the source of the data for the index (e.g. bucket name)
389
+ attr_accessor :source_name
390
+
391
+ # @return [String] type of the data source
392
+ attr_accessor :source_type
393
+
394
+ # @return [String] the UUID of the ata source, this can be used to more tightly tie the index to a source
395
+ attr_accessor :source_uuid
396
+
397
+ # @return [Hash] extra parameters for the source. These are usually things like advanced connection and tuning.
398
+ attr_accessor :source_params
399
+
400
+ # @return [Hash] plan properties such a number of replicas and number of partitions
401
+ attr_accessor :plan_params
402
+
403
+ # @yieldparam [SearchIndex] self
404
+ def initialize
405
+ @type = "fulltext-index"
406
+ @source_type = "couchbase"
407
+ yield self if block_given?
408
+ end
409
+
410
+ # @api private
411
+ def to_backend
412
+ {
413
+ name: name,
414
+ type: type,
415
+ uuid: uuid,
416
+ params: (JSON.generate(params) if params),
417
+ source_name: source_name,
418
+ source_type: source_type,
419
+ source_uuid: source_uuid,
420
+ source_params: (JSON.generate(source_params) if source_params),
421
+ plan_params: (JSON.generate(plan_params) if plan_params),
422
+ }
423
+ end
424
+ end
425
+ end
426
+ end