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.
- checksums.yaml +7 -0
- data/LICENSE.txt +202 -0
- data/README.md +154 -0
- data/ext/extconf.rb +0 -0
- data/lib/active_support/cache/couchbase_store.rb +407 -0
- data/lib/couchbase/3.2/libcouchbase.so +0 -0
- data/lib/couchbase/3.3/libcouchbase.so +0 -0
- data/lib/couchbase/3.4/libcouchbase.so +0 -0
- data/lib/couchbase/4.0/libcouchbase.so +0 -0
- data/lib/couchbase/analytics_options.rb +109 -0
- data/lib/couchbase/authenticator.rb +80 -0
- data/lib/couchbase/binary_collection.rb +145 -0
- data/lib/couchbase/binary_collection_options.rb +26 -0
- data/lib/couchbase/bucket.rb +173 -0
- data/lib/couchbase/cluster.rb +555 -0
- data/lib/couchbase/cluster_registry.rb +49 -0
- data/lib/couchbase/collection.rb +770 -0
- data/lib/couchbase/collection_options.rb +401 -0
- data/lib/couchbase/config_profiles.rb +57 -0
- data/lib/couchbase/configuration.rb +58 -0
- data/lib/couchbase/datastructures/couchbase_list.rb +192 -0
- data/lib/couchbase/datastructures/couchbase_map.rb +231 -0
- data/lib/couchbase/datastructures/couchbase_queue.rb +161 -0
- data/lib/couchbase/datastructures/couchbase_set.rb +145 -0
- data/lib/couchbase/datastructures.rb +26 -0
- data/lib/couchbase/deprecations.rb +61 -0
- data/lib/couchbase/diagnostics.rb +183 -0
- data/lib/couchbase/errors.rb +438 -0
- data/lib/couchbase/fork_hooks.rb +41 -0
- data/lib/couchbase/get_replica_strategy.rb +89 -0
- data/lib/couchbase/json_transcoder.rb +41 -0
- data/lib/couchbase/key_value_scan.rb +119 -0
- data/lib/couchbase/libcouchbase.rb +6 -0
- data/lib/couchbase/logger.rb +87 -0
- data/lib/couchbase/management/analytics_index_manager.rb +1160 -0
- data/lib/couchbase/management/bucket_manager.rb +479 -0
- data/lib/couchbase/management/collection_manager.rb +515 -0
- data/lib/couchbase/management/collection_query_index_manager.rb +247 -0
- data/lib/couchbase/management/query_index_manager.rb +671 -0
- data/lib/couchbase/management/scope_search_index_manager.rb +267 -0
- data/lib/couchbase/management/search_index_manager.rb +649 -0
- data/lib/couchbase/management/user_manager.rb +639 -0
- data/lib/couchbase/management/view_index_manager.rb +332 -0
- data/lib/couchbase/management.rb +31 -0
- data/lib/couchbase/metrics/logging_meter.rb +108 -0
- data/lib/couchbase/metrics/logging_value_recorder.rb +50 -0
- data/lib/couchbase/metrics/meter.rb +27 -0
- data/lib/couchbase/metrics/noop_meter.rb +30 -0
- data/lib/couchbase/metrics/noop_value_recorder.rb +27 -0
- data/lib/couchbase/metrics/value_recorder.rb +25 -0
- data/lib/couchbase/mutation_state.rb +65 -0
- data/lib/couchbase/options.rb +3097 -0
- data/lib/couchbase/protostellar/binary_collection.rb +55 -0
- data/lib/couchbase/protostellar/bucket.rb +59 -0
- data/lib/couchbase/protostellar/client.rb +97 -0
- data/lib/couchbase/protostellar/cluster.rb +182 -0
- data/lib/couchbase/protostellar/collection.rb +156 -0
- data/lib/couchbase/protostellar/connect_options.rb +63 -0
- data/lib/couchbase/protostellar/error_handling.rb +204 -0
- data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_pb.rb +54 -0
- data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_services_pb.rb +51 -0
- data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +42 -0
- data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +51 -0
- data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +38 -0
- data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +52 -0
- data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +42 -0
- data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +55 -0
- data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +51 -0
- data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +67 -0
- data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +31 -0
- data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +40 -0
- data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +51 -0
- data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +54 -0
- data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_pb.rb +46 -0
- data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_services_pb.rb +56 -0
- data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +74 -0
- data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +93 -0
- data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +35 -0
- data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +40 -0
- data/lib/couchbase/protostellar/generated/routing/v2/routing_pb.rb +26 -0
- data/lib/couchbase/protostellar/generated/routing/v2/routing_services_pb.rb +43 -0
- data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +78 -0
- data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +41 -0
- data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +36 -0
- data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +66 -0
- data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +30 -0
- data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +39 -0
- data/lib/couchbase/protostellar/generated.rb +9 -0
- data/lib/couchbase/protostellar/management/bucket_manager.rb +67 -0
- data/lib/couchbase/protostellar/management/collection_manager.rb +94 -0
- data/lib/couchbase/protostellar/management/collection_query_index_manager.rb +124 -0
- data/lib/couchbase/protostellar/management/query_index_manager.rb +112 -0
- data/lib/couchbase/protostellar/management.rb +24 -0
- data/lib/couchbase/protostellar/request.rb +79 -0
- data/lib/couchbase/protostellar/request_behaviour.rb +42 -0
- data/lib/couchbase/protostellar/request_generator/admin/bucket.rb +124 -0
- data/lib/couchbase/protostellar/request_generator/admin/collection.rb +96 -0
- data/lib/couchbase/protostellar/request_generator/admin/query.rb +132 -0
- data/lib/couchbase/protostellar/request_generator/admin.rb +24 -0
- data/lib/couchbase/protostellar/request_generator/kv.rb +488 -0
- data/lib/couchbase/protostellar/request_generator/query.rb +133 -0
- data/lib/couchbase/protostellar/request_generator/search.rb +403 -0
- data/lib/couchbase/protostellar/request_generator.rb +26 -0
- data/lib/couchbase/protostellar/response_converter/admin/bucket.rb +55 -0
- data/lib/couchbase/protostellar/response_converter/admin/collection.rb +42 -0
- data/lib/couchbase/protostellar/response_converter/admin/query.rb +59 -0
- data/lib/couchbase/protostellar/response_converter/admin.rb +24 -0
- data/lib/couchbase/protostellar/response_converter/kv.rb +151 -0
- data/lib/couchbase/protostellar/response_converter/query.rb +84 -0
- data/lib/couchbase/protostellar/response_converter/search.rb +136 -0
- data/lib/couchbase/protostellar/response_converter.rb +26 -0
- data/lib/couchbase/protostellar/retry/action.rb +38 -0
- data/lib/couchbase/protostellar/retry/orchestrator.rb +61 -0
- data/lib/couchbase/protostellar/retry/reason.rb +67 -0
- data/lib/couchbase/protostellar/retry/strategies/best_effort.rb +49 -0
- data/lib/couchbase/protostellar/retry/strategies/fail_fast.rb +33 -0
- data/lib/couchbase/protostellar/retry/strategies.rb +27 -0
- data/lib/couchbase/protostellar/retry.rb +28 -0
- data/lib/couchbase/protostellar/scope.rb +61 -0
- data/lib/couchbase/protostellar/timeout_defaults.rb +30 -0
- data/lib/couchbase/protostellar/timeouts.rb +83 -0
- data/lib/couchbase/protostellar.rb +29 -0
- data/lib/couchbase/query_options.rb +122 -0
- data/lib/couchbase/railtie.rb +47 -0
- data/lib/couchbase/raw_binary_transcoder.rb +39 -0
- data/lib/couchbase/raw_json_transcoder.rb +40 -0
- data/lib/couchbase/raw_string_transcoder.rb +42 -0
- data/lib/couchbase/scope.rb +272 -0
- data/lib/couchbase/search_options.rb +1744 -0
- data/lib/couchbase/subdoc.rb +293 -0
- data/lib/couchbase/tracing/noop_span.rb +29 -0
- data/lib/couchbase/tracing/noop_tracer.rb +29 -0
- data/lib/couchbase/tracing/request_span.rb +34 -0
- data/lib/couchbase/tracing/request_tracer.rb +28 -0
- data/lib/couchbase/tracing/threshold_logging_span.rb +112 -0
- data/lib/couchbase/tracing/threshold_logging_tracer.rb +231 -0
- data/lib/couchbase/transcoder_flags.rb +64 -0
- data/lib/couchbase/utils/generic_logger_adapter.rb +40 -0
- data/lib/couchbase/utils/hdr_histogram.rb +55 -0
- data/lib/couchbase/utils/observability.rb +263 -0
- data/lib/couchbase/utils/observability_constants.rb +200 -0
- data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
- data/lib/couchbase/utils/time.rb +71 -0
- data/lib/couchbase/utils.rb +23 -0
- data/lib/couchbase/version.rb +25 -0
- data/lib/couchbase/view_options.rb +67 -0
- data/lib/couchbase.rb +32 -0
- data/lib/rails/generators/couchbase/config/config_generator.rb +29 -0
- metadata +228 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
# Copyright 2023. 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
|
+
# frozen_string_literal: true
|
|
16
|
+
|
|
17
|
+
require "google/protobuf/well_known_types"
|
|
18
|
+
|
|
19
|
+
require "couchbase/errors"
|
|
20
|
+
require "couchbase/search_options"
|
|
21
|
+
|
|
22
|
+
require "couchbase/protostellar/generated/search/v1/search_pb"
|
|
23
|
+
require "couchbase/protostellar/request"
|
|
24
|
+
|
|
25
|
+
module Couchbase
|
|
26
|
+
module Protostellar
|
|
27
|
+
module RequestGenerator
|
|
28
|
+
class Search
|
|
29
|
+
HIGHLIGHT_STYLE_MAP = {
|
|
30
|
+
:html => :HIGHLIGHT_STYLE_HTML,
|
|
31
|
+
:ansi => :HIGHLIGHT_STYLE_ANSI,
|
|
32
|
+
nil => :HIGHLIGHT_STYLE_DEFAULT,
|
|
33
|
+
}.freeze
|
|
34
|
+
|
|
35
|
+
MATCH_QUERY_OPERATOR_MAP = {
|
|
36
|
+
:or => :OPERATOR_OR,
|
|
37
|
+
:and => :OPERATOR_AND,
|
|
38
|
+
}.freeze
|
|
39
|
+
|
|
40
|
+
SCAN_CONSISTENCY_MAP = {
|
|
41
|
+
:not_bounded => :SCAN_CONSISTENCY_NOT_BOUNDED,
|
|
42
|
+
}.freeze
|
|
43
|
+
|
|
44
|
+
DEFAULT_LIMIT = 10
|
|
45
|
+
DEFAULT_SKIP = 0
|
|
46
|
+
|
|
47
|
+
def search_query_request(index_name, query, options)
|
|
48
|
+
proto_opts = {
|
|
49
|
+
scan_consistency: SCAN_CONSISTENCY_MAP[options.scan_consistency],
|
|
50
|
+
include_explanation: options.explain,
|
|
51
|
+
highlight_style: HIGHLIGHT_STYLE_MAP[options.highlight_style],
|
|
52
|
+
disable_scoring: get_disable_scoring(options),
|
|
53
|
+
include_locations: options.include_locations,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
proto_opts[:highlight_fields] = options.highlight_fields unless options.highlight_fields.nil?
|
|
57
|
+
proto_opts[:fields] = options.fields unless options.fields.nil?
|
|
58
|
+
proto_opts[:sort] = get_sort(options) unless options.sort.nil?
|
|
59
|
+
proto_opts[:limit] = options.limit || DEFAULT_LIMIT
|
|
60
|
+
proto_opts[:skip] = options.skip || DEFAULT_SKIP
|
|
61
|
+
proto_opts[:collections] = options.collections unless options.collections.nil?
|
|
62
|
+
|
|
63
|
+
proto_req = Generated::Search::V1::SearchQueryRequest.new(
|
|
64
|
+
query: create_query(query),
|
|
65
|
+
index_name: index_name,
|
|
66
|
+
**proto_opts,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# Set the search facets in the request
|
|
70
|
+
get_facets(options).each do |key, facet|
|
|
71
|
+
proto_req.facets[key] = facet
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
create_search_request(proto_req, :search_query, options)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
def create_search_request(proto_request, rpc, options, idempotent: false)
|
|
80
|
+
Request.new(
|
|
81
|
+
service: :search,
|
|
82
|
+
rpc: rpc,
|
|
83
|
+
proto_request: proto_request,
|
|
84
|
+
timeout: options.timeout,
|
|
85
|
+
idempotent: idempotent,
|
|
86
|
+
)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def create_query(query)
|
|
90
|
+
sq = Couchbase::Cluster::SearchQuery
|
|
91
|
+
res = Generated::Search::V1::Query.new
|
|
92
|
+
|
|
93
|
+
case query
|
|
94
|
+
when sq::BooleanFieldQuery
|
|
95
|
+
res.boolean_field_query = create_boolean_field_query(query)
|
|
96
|
+
when sq::BooleanQuery
|
|
97
|
+
res.boolean_query = create_boolean_query(query)
|
|
98
|
+
when sq::ConjunctionQuery
|
|
99
|
+
res.conjunction_query = create_conjunction_query(query)
|
|
100
|
+
when sq::DateRangeQuery
|
|
101
|
+
res.date_range_query = create_date_range_query(query)
|
|
102
|
+
when sq::DisjunctionQuery
|
|
103
|
+
res.disjunction_query = create_disjunction_query(query)
|
|
104
|
+
when sq::DocIdQuery
|
|
105
|
+
res.doc_id_query = create_doc_id_query(query)
|
|
106
|
+
when sq::GeoBoundingBoxQuery
|
|
107
|
+
res.geo_bounding_box_query = create_geo_bounding_box_query(query)
|
|
108
|
+
when sq::GeoDistanceQuery
|
|
109
|
+
res.geo_distance_query = create_geo_distance_query(query)
|
|
110
|
+
when sq::GeoPolygonQuery
|
|
111
|
+
res.geo_polygon_query = create_geo_polygon_query(query)
|
|
112
|
+
when sq::MatchAllQuery
|
|
113
|
+
res.match_all_query = create_match_all_query(query)
|
|
114
|
+
when sq::MatchNoneQuery
|
|
115
|
+
res.match_none_query = create_match_none_query(query)
|
|
116
|
+
when sq::MatchPhraseQuery
|
|
117
|
+
res.match_phrase_query = create_match_phrase_query(query)
|
|
118
|
+
when sq::MatchQuery
|
|
119
|
+
res.match_query = create_match_query(query)
|
|
120
|
+
when sq::NumericRangeQuery
|
|
121
|
+
res.numeric_range_query = create_numeric_range_query(query)
|
|
122
|
+
when sq::PhraseQuery
|
|
123
|
+
res.phrase_query = create_phrase_query(query)
|
|
124
|
+
when sq::PrefixQuery
|
|
125
|
+
res.prefix_query = create_prefix_query(query)
|
|
126
|
+
when sq::QueryStringQuery
|
|
127
|
+
res.query_string_query = create_query_string_query(query)
|
|
128
|
+
when sq::RegexpQuery
|
|
129
|
+
res.regexp_query = create_regexp_query(query)
|
|
130
|
+
when sq::TermQuery
|
|
131
|
+
res.term_query = create_term_query(query)
|
|
132
|
+
when sq::TermRangeQuery
|
|
133
|
+
res.term_range_query = create_term_range_query(query)
|
|
134
|
+
when sq::WildcardQuery
|
|
135
|
+
res.wildcard_query = create_wildcard_query(query)
|
|
136
|
+
else
|
|
137
|
+
raise Couchbase::Error::CouchbaseError, "Unexpected search query type #{query.class}"
|
|
138
|
+
end
|
|
139
|
+
res
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def create_boolean_field_query(query)
|
|
143
|
+
query_attrs = query.to_h
|
|
144
|
+
query_attrs[:value] = query_attrs.delete(:bool)
|
|
145
|
+
|
|
146
|
+
Generated::Search::V1::BooleanFieldQuery.new(query_attrs)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def create_boolean_query(query)
|
|
150
|
+
query_attrs = {
|
|
151
|
+
boost: query.boost,
|
|
152
|
+
must: create_conjunction_query(query.instance_variable_get(:@must)),
|
|
153
|
+
must_not: create_disjunction_query(query.instance_variable_get(:@must_not)),
|
|
154
|
+
should: create_disjunction_query(query.instance_variable_get(:@should)),
|
|
155
|
+
}
|
|
156
|
+
Generated::Search::V1::BooleanQuery.new(query_attrs)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def create_conjunction_query(query)
|
|
160
|
+
query_attrs = {
|
|
161
|
+
boost: query.boost,
|
|
162
|
+
queries: query.instance_variable_get(:@queries).uniq.map(&:create_query),
|
|
163
|
+
}
|
|
164
|
+
Generated::Search::V1::ConjunctionQuery.new(query_attrs)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def create_date_range_query(query)
|
|
168
|
+
query_attrs = query.to_h
|
|
169
|
+
query_attrs[:start_date] = query_attrs.delete(:start)
|
|
170
|
+
query_attrs[:end_date] = query_attrs.delete(:end)
|
|
171
|
+
|
|
172
|
+
Generated::Search::V1::DateRangeQuery.new(query_attrs)
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def create_disjunction_query(query)
|
|
176
|
+
query_attrs = {
|
|
177
|
+
boost: query.boost,
|
|
178
|
+
queries: query.instance_variable_get(:@queries).uniq.map(&:create_query),
|
|
179
|
+
minimum: query.min,
|
|
180
|
+
}
|
|
181
|
+
Generated::Search::V1::DisjunctionQuery.new(query_attrs)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def create_doc_id_query(query)
|
|
185
|
+
Generated::Search::V1::DocIdQuery.new(query.to_h)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def create_geo_bounding_box_query(query)
|
|
189
|
+
query_attrs = query.to_h
|
|
190
|
+
query_attrs[:top_left] = Generated::Search::V1::LatLng.new(
|
|
191
|
+
longitude: query_attrs[:top_left][0],
|
|
192
|
+
latitude: query_attrs[:top_left][1],
|
|
193
|
+
)
|
|
194
|
+
query_attrs[:bottom_right] = Generated::Search::V1::LatLng.new(
|
|
195
|
+
longitude: query_attrs[:bottom_right][0],
|
|
196
|
+
latitude: query_attrs[:bottom_right][1],
|
|
197
|
+
)
|
|
198
|
+
Generated::Search::V1::GeoBoundingBoxQuery.new(query_attrs)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
def create_geo_distance_query(query)
|
|
202
|
+
query_attrs = query.to_h
|
|
203
|
+
longitude, latitude = query_attrs.delete(:location)
|
|
204
|
+
query_attrs[:center] = Generated::Search::V1::LatLng.new(
|
|
205
|
+
longitude: longitude,
|
|
206
|
+
latitude: latitude,
|
|
207
|
+
)
|
|
208
|
+
Generated::Search::V1::GeoDistanceQuery.new(query_attrs)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def create_geo_polygon_query(query)
|
|
212
|
+
query_attrs = query.to_h
|
|
213
|
+
polygon_points = query_attrs.delete(:polygon_points)
|
|
214
|
+
query_attrs[:vertices] = polygon_points.map do |lon, lat|
|
|
215
|
+
Generated::Search::V1::LatLng.new(
|
|
216
|
+
longitude: lon,
|
|
217
|
+
latitude: lat,
|
|
218
|
+
)
|
|
219
|
+
end
|
|
220
|
+
Generated::Search::V1::GeoPolygonQuery.new(query_attrs)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def create_match_all_query(_query)
|
|
224
|
+
Generated::Search::V1::MatchAllQuery.new
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
def create_match_none_query(_query)
|
|
228
|
+
Generated::Search::V1::MatchNoneQuery.new
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
def create_match_phrase_query(query)
|
|
232
|
+
query_attrs = query.to_h
|
|
233
|
+
query_attrs[:phrase] = query_attrs.delete(:match_phrase)
|
|
234
|
+
|
|
235
|
+
Generated::Search::V1::MatchPhraseQuery.new(query_attrs)
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
def create_match_query(query)
|
|
239
|
+
query_attrs = query.to_h
|
|
240
|
+
query_attrs[:value] = query_attrs.delete(:match)
|
|
241
|
+
query_attrs[:operator] = MATCH_QUERY_OPERATOR_MAP[query_attrs[:operator]] if query_attrs.include?(:operator)
|
|
242
|
+
|
|
243
|
+
Generated::Search::V1::MatchQuery.new(query_attrs)
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def create_numeric_range_query(query)
|
|
247
|
+
Generated::Search::V1::NumericRangeQuery.new(query.to_h)
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
def create_phrase_query(query)
|
|
251
|
+
Generated::Search::V1::PhraseQuery.new(query.to_h)
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def create_prefix_query(query)
|
|
255
|
+
Generated::Search::V1::PrefixQuery.new(query.to_h)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
def create_query_string_query(query)
|
|
259
|
+
query_attrs = query.to_h
|
|
260
|
+
query_attrs[:query_string] = query_attrs.delete(:query)
|
|
261
|
+
|
|
262
|
+
Generated::Search::V1::QueryStringQuery.new(query_attrs)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
def create_regexp_query(query)
|
|
266
|
+
Generated::Search::V1::RegexpQuery.new(query.to_h)
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def create_term_query(query)
|
|
270
|
+
Generated::Search::V1::TermQuery.new(query.to_h)
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
def create_term_range_query(query)
|
|
274
|
+
Generated::Search::V1::TermRangeQuery.new(query.to_h)
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def create_wildcard_query(query)
|
|
278
|
+
Generated::Search::V1::WildcardQuery.new(query.to_h)
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def get_sort(options)
|
|
282
|
+
options.sort.map do |s|
|
|
283
|
+
case s
|
|
284
|
+
when Couchbase::Cluster::SearchSort::SearchSortField
|
|
285
|
+
# TODO: missing, type and mode could change to Enums
|
|
286
|
+
Generated::Search::V1::Sorting.new(
|
|
287
|
+
field_sorting: Generated::Search::V1::FieldSorting.new(
|
|
288
|
+
field: s.field,
|
|
289
|
+
descending: s.desc,
|
|
290
|
+
missing: s.missing.to_s,
|
|
291
|
+
mode: s.mode.to_s,
|
|
292
|
+
type: s.type.to_s,
|
|
293
|
+
),
|
|
294
|
+
)
|
|
295
|
+
when Couchbase::Cluster::SearchSort::SearchSortId
|
|
296
|
+
Generated::Search::V1::Sorting.new(
|
|
297
|
+
id_sorting: Generated::Search::V1::IdSorting.new(
|
|
298
|
+
descending: s.desc,
|
|
299
|
+
),
|
|
300
|
+
)
|
|
301
|
+
when Couchbase::Cluster::SearchSort::SearchSortScore
|
|
302
|
+
Generated::Search::V1::Sorting.new(
|
|
303
|
+
score_sorting: Generated::Search::V1::ScoreSorting.new(
|
|
304
|
+
descending: s.desc,
|
|
305
|
+
),
|
|
306
|
+
)
|
|
307
|
+
when Couchbase::Cluster::SearchSort::SearchSortGeoDistance
|
|
308
|
+
Generated::Search::V1::Sorting.new(
|
|
309
|
+
geo_distance_sorting: Generated::Search::V1::GeoDistanceSorting.new(
|
|
310
|
+
field: s.field,
|
|
311
|
+
descending: s.desc,
|
|
312
|
+
center: Generated::Search::V1::LatLng.new(
|
|
313
|
+
latitude: s.latitude,
|
|
314
|
+
longitude: s.longitude,
|
|
315
|
+
),
|
|
316
|
+
unit: s.unit.to_s,
|
|
317
|
+
),
|
|
318
|
+
)
|
|
319
|
+
when String
|
|
320
|
+
if s[0] == "-"
|
|
321
|
+
desc = true
|
|
322
|
+
field = s[1..]
|
|
323
|
+
else
|
|
324
|
+
desc = false
|
|
325
|
+
field = s
|
|
326
|
+
end
|
|
327
|
+
if field == "_score"
|
|
328
|
+
Generated::Search::V1::Sorting.new(
|
|
329
|
+
score_sorting: Generated::Search::V1::ScoreSorting.new(
|
|
330
|
+
descending: desc,
|
|
331
|
+
),
|
|
332
|
+
)
|
|
333
|
+
else
|
|
334
|
+
Generated::Search::V1::Sorting.new(
|
|
335
|
+
# TODO: What to do with the rest of the FieldSorting attributes?
|
|
336
|
+
core_sorting: Generated::Search::V1::FieldSorting.new(
|
|
337
|
+
field: field,
|
|
338
|
+
descending: desc,
|
|
339
|
+
),
|
|
340
|
+
)
|
|
341
|
+
end
|
|
342
|
+
else
|
|
343
|
+
raise Couchbase::Error::CouchbaseError, "Unrecognised search sort type"
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
# The only scoring mode supported by the protocol is {Couchbase::SearchScoring.none}.
|
|
349
|
+
# This will be updated to support all types of scoring once the protostellar protocol supports them.
|
|
350
|
+
def get_disable_scoring(options)
|
|
351
|
+
return options.disable_scoring if options.scoring.nil?
|
|
352
|
+
|
|
353
|
+
options.validate_scoring
|
|
354
|
+
|
|
355
|
+
unless options.scoring.is_a?(Couchbase::SearchScoring::SearchScoringNone)
|
|
356
|
+
raise Couchbase::Error::FeatureNotAvailable,
|
|
357
|
+
"The #{Protostellar::NAME} protocol does not support #{options.scoring.class} scoring"
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
true
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
def get_facets(options)
|
|
364
|
+
return {} if options.facets.nil?
|
|
365
|
+
|
|
366
|
+
options.facets.transform_values do |facet|
|
|
367
|
+
case facet
|
|
368
|
+
when Couchbase::Cluster::SearchFacet::SearchFacetTerm
|
|
369
|
+
Generated::Search::V1::Facet.new(
|
|
370
|
+
term_facet: Generated::Search::V1::TermFacet.new(
|
|
371
|
+
field: facet.field,
|
|
372
|
+
size: facet.size,
|
|
373
|
+
),
|
|
374
|
+
)
|
|
375
|
+
when Couchbase::Cluster::SearchFacet::SearchFacetNumericRange
|
|
376
|
+
Generated::Search::V1::Facet.new(
|
|
377
|
+
numeric_range_facet: Generated::Search::V1::NumericRangeFacet.new(
|
|
378
|
+
field: facet.field,
|
|
379
|
+
size: facet.size,
|
|
380
|
+
numeric_ranges: facet.instance_variable_get(:@ranges).map do |r|
|
|
381
|
+
Generated::Search::V1::NumericRange(name: r[:name], min: r[:min], max: r[:max])
|
|
382
|
+
end,
|
|
383
|
+
),
|
|
384
|
+
)
|
|
385
|
+
when Couchbase::Cluster::SearchFacet::SearchFacetDateRange
|
|
386
|
+
Generated::Search::V1::Facet.new(
|
|
387
|
+
date_range_facet: Generated::Search::V1::DateRangeFacet.new(
|
|
388
|
+
field: facet.field,
|
|
389
|
+
size: facet.size,
|
|
390
|
+
date_ranges: facet.instance_variable_get(:@ranges).map do |r|
|
|
391
|
+
Generated::Search::V1::DateRange(name: r[:name], start: r[:start], end: r[:end])
|
|
392
|
+
end,
|
|
393
|
+
),
|
|
394
|
+
)
|
|
395
|
+
else
|
|
396
|
+
raise Couchbase::Error::CouchbaseError, "Unrecognised search facet type"
|
|
397
|
+
end
|
|
398
|
+
end
|
|
399
|
+
end
|
|
400
|
+
end
|
|
401
|
+
end
|
|
402
|
+
end
|
|
403
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Copyright 2023. 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
|
+
# frozen_string_literal: true
|
|
16
|
+
|
|
17
|
+
require_relative "request_generator/kv"
|
|
18
|
+
require_relative "request_generator/query"
|
|
19
|
+
|
|
20
|
+
module Couchbase
|
|
21
|
+
module Protostellar
|
|
22
|
+
# @api private
|
|
23
|
+
module RequestGenerator
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Copyright 2023. 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
|
+
# frozen_string_literal: true
|
|
16
|
+
|
|
17
|
+
require "couchbase/management/bucket_manager"
|
|
18
|
+
|
|
19
|
+
require_relative "../../request_generator/admin/bucket"
|
|
20
|
+
|
|
21
|
+
module Couchbase
|
|
22
|
+
module Protostellar
|
|
23
|
+
module ResponseConverter
|
|
24
|
+
module Admin
|
|
25
|
+
class Bucket
|
|
26
|
+
BUCKET_TYPE_MAP = RequestGenerator::Admin::Bucket::BUCKET_TYPE_MAP.invert.freeze
|
|
27
|
+
EVICTION_MODE_MAP = RequestGenerator::Admin::Bucket::EVICTION_MODE_MAP.invert.freeze
|
|
28
|
+
COMPRESSION_MODE_MAP = RequestGenerator::Admin::Bucket::COMPRESSION_MODE_MAP.invert.freeze
|
|
29
|
+
STORAGE_BACKEND_MAP = RequestGenerator::Admin::Bucket::STORAGE_BACKEND_MAP.invert.freeze
|
|
30
|
+
CONFLICT_RESOLUTION_TYPE_MAP = RequestGenerator::Admin::Bucket::CONFLICT_RESOLUTION_TYPE_MAP.invert.freeze
|
|
31
|
+
DURABILITY_LEVEL_MAP = RequestGenerator::Admin::Bucket::DURABILITY_LEVEL_MAP.invert.freeze
|
|
32
|
+
|
|
33
|
+
def self.to_bucket_settings_array(resp)
|
|
34
|
+
resp.buckets.map do |r|
|
|
35
|
+
Couchbase::Management::BucketSettings.new do |b|
|
|
36
|
+
b.name = r.bucket_name
|
|
37
|
+
b.flush_enabled = r.flush_enabled
|
|
38
|
+
b.ram_quota_mb = r.ram_quota_mb
|
|
39
|
+
b.num_replicas = r.num_replicas
|
|
40
|
+
b.replica_indexes = r.replica_indexes
|
|
41
|
+
b.bucket_type = BUCKET_TYPE_MAP[r.bucket_type]
|
|
42
|
+
b.max_expiry = r.max_expiry_secs
|
|
43
|
+
b.eviction_policy = EVICTION_MODE_MAP[r.eviction_mode]
|
|
44
|
+
b.minimum_durability_level = DURABILITY_LEVEL_MAP[r.minimum_durability_level]
|
|
45
|
+
b.compression_mode = COMPRESSION_MODE_MAP[r.compression_mode]
|
|
46
|
+
b.conflict_resolution_type = CONFLICT_RESOLUTION_TYPE_MAP[r.conflict_resolution_type]
|
|
47
|
+
b.storage_backend = STORAGE_BACKEND_MAP[r.storage_backend]
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Copyright 2023. 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
|
+
# frozen_string_literal: true
|
|
16
|
+
|
|
17
|
+
require "couchbase/management/collection_manager"
|
|
18
|
+
|
|
19
|
+
module Couchbase
|
|
20
|
+
module Protostellar
|
|
21
|
+
module ResponseConverter
|
|
22
|
+
module Admin
|
|
23
|
+
class Collection
|
|
24
|
+
def self.to_scope_spec_array(resp)
|
|
25
|
+
resp.scopes.map do |s|
|
|
26
|
+
Couchbase::Management::ScopeSpec.new do |scope_spec|
|
|
27
|
+
scope_spec.name = s.name
|
|
28
|
+
scope_spec.collections = s.collections.map do |c|
|
|
29
|
+
Couchbase::Management::CollectionSpec.new do |coll_spec|
|
|
30
|
+
coll_spec.name = c.name
|
|
31
|
+
coll_spec.scope_name = s.name
|
|
32
|
+
coll_spec.max_expiry = c.max_expiry_secs if c.has_max_expiry_secs?
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright 2023. 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
|
+
# frozen_string_literal: true
|
|
16
|
+
|
|
17
|
+
require "couchbase/management/query_index_manager"
|
|
18
|
+
|
|
19
|
+
module Couchbase
|
|
20
|
+
module Protostellar
|
|
21
|
+
module ResponseConverter
|
|
22
|
+
module Admin
|
|
23
|
+
class Query
|
|
24
|
+
INDEX_TYPE_MAP = {
|
|
25
|
+
:INDEX_TYPE_VIEW => :view,
|
|
26
|
+
:INDEX_TYPE_GSI => :gsi,
|
|
27
|
+
}.freeze
|
|
28
|
+
|
|
29
|
+
INDEX_STATE_MAP = {
|
|
30
|
+
:INDEX_STATE_DEFERRED => :deferred,
|
|
31
|
+
:INDEX_STATE_BUILDING => :building,
|
|
32
|
+
:INDEX_STATE_PENDING => :pending,
|
|
33
|
+
:INDEX_STATE_ONLINE => :online,
|
|
34
|
+
:INDEX_STATE_OFFLINE => :offline,
|
|
35
|
+
:INDEX_STATE_ABRIDGED => :abridged,
|
|
36
|
+
:INDEX_STATE_SCHEDULED => :scheduled,
|
|
37
|
+
}.freeze
|
|
38
|
+
|
|
39
|
+
def self.to_query_index_array(resp)
|
|
40
|
+
resp.indexes.map do |proto_idx|
|
|
41
|
+
Couchbase::Management::QueryIndex.new do |idx|
|
|
42
|
+
idx.bucket = proto_idx.bucket_name
|
|
43
|
+
idx.scope = proto_idx.scope_name
|
|
44
|
+
idx.collection = proto_idx.collection_name
|
|
45
|
+
idx.name = proto_idx.name
|
|
46
|
+
idx.is_primary = proto_idx.is_primary
|
|
47
|
+
idx.type = INDEX_TYPE_MAP[proto_idx.type]
|
|
48
|
+
idx.state = INDEX_STATE_MAP[proto_idx.state]
|
|
49
|
+
idx.index_key = proto_idx.fields.to_a
|
|
50
|
+
idx.condition = proto_idx.condition if proto_idx.has_condition?
|
|
51
|
+
idx.partition = proto_idx.partition if proto_idx.has_partition?
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Copyright 2023. 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
|
+
# frozen_string_literal: true
|
|
16
|
+
|
|
17
|
+
module Couchbase
|
|
18
|
+
module Protostellar
|
|
19
|
+
module ResponseConverter
|
|
20
|
+
module Admin
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|