couchbase 3.5.0-arm64-darwin-22

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