couchbase 3.4.1 → 3.4.3
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 +4 -4
- data/README.md +2 -2
- data/ext/couchbase/CMakeLists.txt +59 -7
- data/ext/couchbase/cmake/Documentation.cmake +0 -1
- data/ext/couchbase/cmake/OpenSSL.cmake +98 -3
- data/ext/couchbase/cmake/Testing.cmake +12 -4
- data/ext/couchbase/cmake/ThirdPartyDependencies.cmake +4 -0
- data/ext/couchbase/cmake/build_config.hxx.in +3 -0
- data/ext/couchbase/core/bucket.cxx +3 -2
- data/ext/couchbase/core/bucket.hxx +9 -0
- data/ext/couchbase/core/cluster.hxx +17 -0
- data/ext/couchbase/core/cluster_options.cxx +2 -2
- data/ext/couchbase/core/cluster_options.hxx +4 -7
- data/ext/couchbase/core/{config_profile.cxx → cluster_options_fwd.hxx} +7 -6
- data/ext/couchbase/core/config_profile.hxx +2 -65
- data/ext/couchbase/core/config_profiles.cxx +79 -0
- data/ext/couchbase/core/config_profiles.hxx +56 -0
- data/ext/couchbase/core/error_context/search.hxx +1 -1
- data/ext/couchbase/core/impl/analytics.cxx +237 -0
- data/ext/couchbase/core/impl/boolean_field_query.cxx +40 -0
- data/ext/couchbase/core/impl/boolean_query.cxx +62 -0
- data/ext/couchbase/core/impl/cluster.cxx +2 -1
- data/ext/couchbase/core/impl/conjunction_query.cxx +51 -0
- data/ext/couchbase/core/impl/date_range.cxx +89 -0
- data/ext/couchbase/core/impl/date_range_facet.cxx +54 -0
- data/ext/couchbase/core/impl/date_range_facet_result.cxx +64 -0
- data/ext/couchbase/core/impl/date_range_query.cxx +125 -0
- data/ext/couchbase/core/impl/disjunction_query.cxx +51 -0
- data/ext/couchbase/core/impl/dns_srv_tracker.cxx +5 -3
- data/ext/couchbase/core/impl/encoded_search_facet.hxx +29 -0
- data/ext/couchbase/core/impl/encoded_search_query.hxx +29 -0
- data/ext/couchbase/core/impl/encoded_search_sort.hxx +29 -0
- data/ext/couchbase/core/impl/geo_bounding_box_query.cxx +46 -0
- data/ext/couchbase/core/impl/geo_distance_query.cxx +43 -0
- data/ext/couchbase/core/impl/geo_polygon_query.cxx +46 -0
- data/ext/couchbase/core/impl/internal_date_range_facet_result.cxx +80 -0
- data/ext/couchbase/core/impl/internal_date_range_facet_result.hxx +48 -0
- data/ext/couchbase/core/impl/internal_numeric_range_facet_result.cxx +80 -0
- data/ext/couchbase/core/impl/internal_numeric_range_facet_result.hxx +48 -0
- data/ext/couchbase/core/impl/internal_search_error_context.cxx +141 -0
- data/ext/couchbase/core/impl/internal_search_error_context.hxx +61 -0
- data/ext/couchbase/core/impl/internal_search_meta_data.cxx +60 -0
- data/ext/couchbase/core/impl/internal_search_meta_data.hxx +41 -0
- data/ext/couchbase/core/impl/internal_search_result.cxx +84 -0
- data/ext/couchbase/core/impl/internal_search_result.hxx +43 -0
- data/ext/couchbase/core/impl/internal_search_row.cxx +82 -0
- data/ext/couchbase/core/impl/internal_search_row.hxx +56 -0
- data/ext/couchbase/core/impl/internal_search_row_location.hxx +32 -0
- data/ext/couchbase/core/impl/internal_search_row_locations.cxx +137 -0
- data/ext/couchbase/core/impl/internal_search_row_locations.hxx +45 -0
- data/ext/couchbase/core/impl/internal_term_facet_result.cxx +80 -0
- data/ext/couchbase/core/impl/internal_term_facet_result.hxx +48 -0
- data/ext/couchbase/core/impl/match_all_query.cxx +35 -0
- data/ext/couchbase/core/impl/match_none_query.cxx +35 -0
- data/ext/couchbase/core/impl/match_phrase_query.cxx +43 -0
- data/ext/couchbase/core/impl/match_query.cxx +59 -0
- data/ext/couchbase/core/impl/numeric_range.cxx +49 -0
- data/ext/couchbase/core/impl/numeric_range_facet.cxx +54 -0
- data/ext/couchbase/core/impl/numeric_range_facet_result.cxx +64 -0
- data/ext/couchbase/core/impl/numeric_range_query.cxx +56 -0
- data/ext/couchbase/core/impl/phrase_query.cxx +42 -0
- data/ext/couchbase/core/impl/prefix_query.cxx +40 -0
- data/ext/couchbase/core/impl/query.cxx +5 -5
- data/ext/couchbase/core/impl/query_string_query.cxx +37 -0
- data/ext/couchbase/core/impl/regexp_query.cxx +40 -0
- data/ext/couchbase/core/impl/search.cxx +191 -0
- data/ext/couchbase/core/impl/search_error_context.cxx +147 -0
- data/ext/couchbase/core/impl/search_meta_data.cxx +46 -0
- data/ext/couchbase/core/impl/search_result.cxx +66 -0
- data/ext/couchbase/core/impl/search_row.cxx +74 -0
- data/ext/couchbase/core/impl/search_row_location.cxx +64 -0
- data/ext/couchbase/core/impl/search_row_locations.cxx +66 -0
- data/ext/couchbase/core/impl/search_sort_field.cxx +104 -0
- data/ext/couchbase/core/impl/search_sort_id.cxx +43 -0
- data/ext/couchbase/core/impl/search_sort_score.cxx +43 -0
- data/ext/couchbase/core/impl/term_facet.cxx +36 -0
- data/ext/couchbase/core/impl/term_facet_result.cxx +64 -0
- data/ext/couchbase/core/impl/term_query.cxx +56 -0
- data/ext/couchbase/core/impl/term_range_query.cxx +57 -0
- data/ext/couchbase/core/impl/wildcard_query.cxx +40 -0
- data/ext/couchbase/core/io/dns_client.cxx +225 -0
- data/ext/couchbase/core/io/dns_client.hxx +19 -188
- data/ext/couchbase/core/io/http_context.hxx +1 -1
- data/ext/couchbase/core/io/http_session.hxx +10 -0
- data/ext/couchbase/core/io/http_session_manager.hxx +5 -3
- data/ext/couchbase/core/io/mcbp_session.cxx +28 -1
- data/ext/couchbase/core/io/retry_orchestrator.hxx +3 -2
- data/ext/couchbase/core/json_string.hxx +5 -0
- data/ext/couchbase/core/meta/version.cxx +18 -4
- data/ext/couchbase/core/mozilla_ca_bundle.hxx +39 -0
- data/ext/couchbase/core/operations/document_analytics.cxx +1 -0
- data/ext/couchbase/core/operations/document_analytics.hxx +1 -0
- data/ext/couchbase/core/operations/document_append.hxx +1 -1
- data/ext/couchbase/core/operations/document_decrement.hxx +1 -1
- data/ext/couchbase/core/operations/document_exists.hxx +1 -1
- data/ext/couchbase/core/operations/document_get.hxx +1 -1
- data/ext/couchbase/core/operations/document_get_and_lock.hxx +1 -1
- data/ext/couchbase/core/operations/document_get_and_touch.hxx +1 -1
- data/ext/couchbase/core/operations/document_get_projected.hxx +1 -1
- data/ext/couchbase/core/operations/document_increment.hxx +1 -1
- data/ext/couchbase/core/operations/document_insert.hxx +1 -1
- data/ext/couchbase/core/operations/document_lookup_in.hxx +1 -1
- data/ext/couchbase/core/operations/document_mutate_in.hxx +1 -1
- data/ext/couchbase/core/operations/document_prepend.hxx +1 -1
- data/ext/couchbase/core/operations/document_query.cxx +2 -0
- data/ext/couchbase/core/operations/document_query.hxx +6 -0
- data/ext/couchbase/core/operations/document_remove.hxx +1 -1
- data/ext/couchbase/core/operations/document_replace.hxx +1 -1
- data/ext/couchbase/core/operations/document_search.cxx +4 -1
- data/ext/couchbase/core/operations/document_search.hxx +2 -1
- data/ext/couchbase/core/operations/document_touch.hxx +1 -1
- data/ext/couchbase/core/operations/document_unlock.hxx +1 -1
- data/ext/couchbase/core/operations/document_upsert.hxx +1 -1
- data/ext/couchbase/core/operations/document_view.hxx +1 -0
- data/ext/couchbase/core/protocol/client_request.hxx +11 -2
- data/ext/couchbase/core/public_fwd.hxx +21 -0
- data/ext/couchbase/core/tls_verify_mode.hxx +26 -0
- data/ext/couchbase/core/topology/configuration.cxx +15 -2
- data/ext/couchbase/core/topology/configuration.hxx +5 -1
- data/ext/couchbase/core/transactions/active_transaction_record.hxx +2 -2
- data/ext/couchbase/core/transactions/attempt_context_impl.cxx +3 -0
- data/ext/couchbase/core/transactions/attempt_context_impl.hxx +1 -1
- data/ext/couchbase/core/transactions/attempt_context_testing_hooks.cxx +93 -0
- data/ext/couchbase/core/transactions/attempt_context_testing_hooks.hxx +48 -75
- data/ext/couchbase/core/transactions/cleanup_testing_hooks.cxx +52 -0
- data/ext/couchbase/core/transactions/cleanup_testing_hooks.hxx +17 -31
- data/ext/couchbase/core/transactions/exceptions.hxx +12 -9
- data/ext/couchbase/core/transactions/internal/transaction_context.hxx +12 -12
- data/ext/couchbase/core/transactions/internal/transactions_cleanup.hxx +7 -1
- data/ext/couchbase/core/transactions/transaction_context.cxx +1 -0
- data/ext/couchbase/core/transactions/transactions_cleanup.cxx +144 -155
- data/ext/couchbase/core/utils/connection_string.cxx +27 -3
- data/ext/couchbase/core/utils/connection_string.hxx +3 -3
- data/ext/couchbase/core/utils/json.cxx +4 -1
- data/ext/couchbase/couchbase/analytics_error_context.hxx +143 -0
- data/ext/couchbase/couchbase/analytics_meta_data.hxx +155 -0
- data/ext/couchbase/couchbase/analytics_metrics.hxx +163 -0
- data/ext/couchbase/couchbase/analytics_options.hxx +359 -0
- data/ext/couchbase/couchbase/analytics_result.hxx +102 -0
- data/ext/couchbase/couchbase/analytics_scan_consistency.hxx +46 -0
- data/ext/couchbase/couchbase/analytics_status.hxx +41 -0
- data/ext/couchbase/couchbase/analytics_warning.hxx +85 -0
- data/ext/couchbase/couchbase/behavior_options.hxx +10 -1
- data/ext/couchbase/couchbase/boolean_field_query.hxx +77 -0
- data/ext/couchbase/couchbase/boolean_query.hxx +223 -0
- data/ext/couchbase/couchbase/cluster.hxx +75 -1
- data/ext/couchbase/couchbase/conjunction_query.hxx +88 -0
- data/ext/couchbase/couchbase/date_range.hxx +69 -0
- data/ext/couchbase/couchbase/date_range_facet.hxx +56 -0
- data/ext/couchbase/couchbase/date_range_facet_result.hxx +55 -0
- data/ext/couchbase/couchbase/date_range_query.hxx +265 -0
- data/ext/couchbase/couchbase/disjunction_query.hxx +109 -0
- data/ext/couchbase/couchbase/doc_id_query.hxx +111 -0
- data/ext/couchbase/couchbase/error_context.hxx +7 -6
- data/ext/couchbase/couchbase/fmt/analytics_scan_consistency.hxx +52 -0
- data/ext/couchbase/couchbase/fmt/analytics_status.hxx +76 -0
- data/ext/couchbase/couchbase/fmt/search_scan_consistency.hxx +49 -0
- data/ext/couchbase/couchbase/geo_bounding_box_query.hxx +107 -0
- data/ext/couchbase/couchbase/geo_distance_query.hxx +109 -0
- data/ext/couchbase/couchbase/geo_point.hxx +32 -0
- data/ext/couchbase/couchbase/geo_polygon_query.hxx +85 -0
- data/ext/couchbase/couchbase/highlight_style.hxx +45 -0
- data/ext/couchbase/couchbase/match_all_query.hxx +43 -0
- data/ext/couchbase/couchbase/match_none_query.hxx +43 -0
- data/ext/couchbase/couchbase/match_operator.hxx +45 -0
- data/ext/couchbase/couchbase/match_phrase_query.hxx +108 -0
- data/ext/couchbase/couchbase/match_query.hxx +163 -0
- data/ext/couchbase/couchbase/numeric_range.hxx +58 -0
- data/ext/couchbase/couchbase/numeric_range_facet.hxx +56 -0
- data/ext/couchbase/couchbase/numeric_range_facet_result.hxx +55 -0
- data/ext/couchbase/couchbase/numeric_range_query.hxx +143 -0
- data/ext/couchbase/couchbase/phrase_query.hxx +93 -0
- data/ext/couchbase/couchbase/prefix_query.hxx +82 -0
- data/ext/couchbase/couchbase/query_options.hxx +0 -1
- data/ext/couchbase/couchbase/query_string_query.hxx +72 -0
- data/ext/couchbase/couchbase/regexp_query.hxx +82 -0
- data/ext/couchbase/couchbase/scope.hxx +73 -0
- data/ext/couchbase/couchbase/search_date_range.hxx +68 -0
- data/ext/couchbase/couchbase/search_error_context.hxx +138 -0
- data/ext/couchbase/couchbase/search_facet.hxx +60 -0
- data/ext/couchbase/couchbase/search_facet_result.hxx +50 -0
- data/ext/couchbase/couchbase/search_meta_data.hxx +85 -0
- data/ext/couchbase/couchbase/search_metrics.hxx +127 -0
- data/ext/couchbase/couchbase/search_numeric_range.hxx +69 -0
- data/ext/couchbase/couchbase/search_options.hxx +509 -0
- data/ext/couchbase/couchbase/search_query.hxx +69 -0
- data/ext/couchbase/couchbase/search_result.hxx +77 -0
- data/ext/couchbase/couchbase/search_row.hxx +104 -0
- data/ext/couchbase/couchbase/search_row_location.hxx +55 -0
- data/ext/couchbase/couchbase/search_row_locations.hxx +86 -0
- data/ext/couchbase/couchbase/search_scan_consistency.hxx +34 -0
- data/ext/couchbase/couchbase/search_sort.hxx +58 -0
- data/ext/couchbase/couchbase/search_sort_field.hxx +117 -0
- data/ext/couchbase/couchbase/search_sort_field_missing.hxx +26 -0
- data/ext/couchbase/couchbase/search_sort_field_mode.hxx +27 -0
- data/ext/couchbase/couchbase/search_sort_field_type.hxx +28 -0
- data/ext/couchbase/couchbase/search_sort_id.hxx +60 -0
- data/ext/couchbase/couchbase/search_sort_score.hxx +60 -0
- data/ext/couchbase/couchbase/search_term_range.hxx +51 -0
- data/ext/couchbase/couchbase/security_options.hxx +3 -0
- data/ext/couchbase/couchbase/term_facet.hxx +48 -0
- data/ext/couchbase/couchbase/term_facet_result.hxx +55 -0
- data/ext/couchbase/couchbase/term_query.hxx +151 -0
- data/ext/couchbase/couchbase/term_range_query.hxx +142 -0
- data/ext/couchbase/couchbase/tracing/request_span.hxx +63 -0
- data/ext/couchbase/couchbase/tracing/request_tracer.hxx +2 -40
- data/ext/couchbase/couchbase/transactions/async_attempt_context.hxx +83 -4
- data/ext/couchbase/couchbase/transactions/attempt_context.hxx +68 -1
- data/ext/couchbase/couchbase/transactions/transaction_get_result.hxx +2 -0
- data/ext/couchbase/couchbase/transactions/transaction_keyspace.hxx +11 -1
- data/ext/couchbase/couchbase/transactions/transaction_options.hxx +79 -8
- data/ext/couchbase/couchbase/transactions/transaction_query_options.hxx +128 -15
- data/ext/couchbase/couchbase/transactions/transaction_query_result.hxx +4 -0
- data/ext/couchbase/couchbase/transactions/transaction_result.hxx +1 -1
- data/ext/couchbase/couchbase/transactions/transactions_cleanup_config.hxx +5 -3
- data/ext/couchbase/couchbase/transactions/transactions_config.hxx +9 -5
- data/ext/couchbase/couchbase/transactions/transactions_query_config.hxx +6 -3
- data/ext/couchbase/couchbase/transactions.hxx +34 -1
- data/ext/couchbase/couchbase/wildcard_query.hxx +83 -0
- data/ext/couchbase/test/CMakeLists.txt +8 -7
- data/ext/couchbase/test/benchmark_helper_integration.hxx +2 -2
- data/ext/couchbase/test/test_helper.hxx +6 -6
- data/ext/couchbase/test/test_integration_analytics.cxx +314 -16
- data/ext/couchbase/test/test_integration_collections.cxx +7 -3
- data/ext/couchbase/test/test_integration_connect.cxx +7 -3
- data/ext/couchbase/test/test_integration_crud.cxx +19 -2
- data/ext/couchbase/test/test_integration_diagnostics.cxx +11 -5
- data/ext/couchbase/test/test_integration_durability.cxx +12 -7
- data/ext/couchbase/test/test_integration_examples.cxx +324 -11
- data/ext/couchbase/test/test_integration_management.cxx +162 -94
- data/ext/couchbase/test/test_integration_query.cxx +68 -10
- data/ext/couchbase/test/test_integration_range_scan.cxx +12 -12
- data/ext/couchbase/test/test_integration_read_replica.cxx +48 -11
- data/ext/couchbase/test/test_integration_search.cxx +621 -0
- data/ext/couchbase/test/test_integration_subdoc.cxx +62 -11
- data/ext/couchbase/test/test_integration_tracer.cxx +5 -0
- data/ext/couchbase/test/test_integration_transcoders.cxx +13 -5
- data/ext/couchbase/test/{test_transaction_transaction_context.cxx → test_transaction_context.cxx} +1 -1
- data/ext/couchbase/test/test_transaction_examples.cxx +195 -0
- data/ext/couchbase/test/{test_transaction_transaction_simple.cxx → test_transaction_simple.cxx} +90 -5
- data/ext/couchbase/test/{test_transaction_transaction_simple_async.cxx → test_transaction_simple_async.cxx} +19 -21
- data/ext/couchbase/test/test_unit_config_profiles.cxx +13 -13
- data/ext/couchbase/test/test_unit_connection_string.cxx +35 -0
- data/ext/couchbase/test/test_unit_json_transcoder.cxx +4 -0
- data/ext/couchbase/test/test_unit_search.cxx +427 -0
- data/ext/couchbase/test/test_unit_transaction_utils.cxx +10 -1
- data/ext/couchbase/test/test_unit_utils.cxx +8 -4
- data/ext/couchbase/third_party/snappy/CMakeLists.txt +150 -27
- data/ext/couchbase/third_party/snappy/cmake/config.h.in +28 -24
- data/ext/couchbase/third_party/snappy/snappy-internal.h +189 -25
- data/ext/couchbase/third_party/snappy/snappy-sinksource.cc +26 -9
- data/ext/couchbase/third_party/snappy/snappy-sinksource.h +11 -11
- data/ext/couchbase/third_party/snappy/snappy-stubs-internal.cc +1 -1
- data/ext/couchbase/third_party/snappy/snappy-stubs-internal.h +227 -308
- data/ext/couchbase/third_party/snappy/snappy-stubs-public.h.in +0 -11
- data/ext/couchbase/third_party/snappy/snappy.cc +1176 -410
- data/ext/couchbase/third_party/snappy/snappy.h +19 -4
- data/ext/couchbase.cxx +85 -22
- data/ext/revisions.rb +3 -3
- data/lib/couchbase/authenticator.rb +0 -1
- data/lib/couchbase/cluster.rb +13 -13
- data/lib/couchbase/cluster_registry.rb +7 -2
- data/lib/couchbase/config_profiles.rb +1 -1
- data/lib/couchbase/configuration.rb +3 -4
- data/lib/couchbase/json_transcoder.rb +12 -5
- data/lib/couchbase/management/collection_query_index_manager.rb +54 -15
- data/lib/couchbase/management/query_index_manager.rb +70 -5
- data/lib/couchbase/options.rb +85 -2
- data/lib/couchbase/raw_binary_transcoder.rb +37 -0
- data/lib/couchbase/raw_json_transcoder.rb +38 -0
- data/lib/couchbase/raw_string_transcoder.rb +40 -0
- data/lib/couchbase/search_options.rb +163 -240
- data/lib/couchbase/transcoder_flags.rb +62 -0
- data/lib/couchbase/version.rb +1 -1
- metadata +151 -12
- data/ext/couchbase/core/CMakeLists.txt +0 -0
- /data/ext/couchbase/test/{test_transaction_transaction_public_async_api.cxx → test_transaction_public_async_api.cxx} +0 -0
- /data/ext/couchbase/test/{test_transaction_transaction_public_blocking_api.cxx → test_transaction_public_blocking_api.cxx} +0 -0
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
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
|
+
|
|
18
|
+
#include "test_helper_integration.hxx"
|
|
19
|
+
|
|
20
|
+
#include <catch2/matchers/catch_matchers_string.hpp>
|
|
21
|
+
|
|
22
|
+
#include "core/operations/management/collection_create.hxx"
|
|
23
|
+
#include "core/operations/management/search_index_drop.hxx"
|
|
24
|
+
#include "core/operations/management/search_index_upsert.hxx"
|
|
25
|
+
|
|
26
|
+
#include <couchbase/query_string_query.hxx>
|
|
27
|
+
|
|
28
|
+
using Catch::Matchers::StartsWith;
|
|
29
|
+
|
|
30
|
+
TEST_CASE("integration: search query")
|
|
31
|
+
{
|
|
32
|
+
test::utils::integration_test_guard integration;
|
|
33
|
+
|
|
34
|
+
if (!integration.cluster_version().supports_search()) {
|
|
35
|
+
SKIP("cluster does not support search");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
test::utils::open_bucket(integration.cluster, integration.ctx.bucket);
|
|
39
|
+
|
|
40
|
+
{
|
|
41
|
+
auto sample_data =
|
|
42
|
+
couchbase::core::utils::json::parse(couchbase::core::json_string(test::utils::read_test_data("search_beers_dataset.json")));
|
|
43
|
+
auto const& o = sample_data.get_object();
|
|
44
|
+
for (const auto& [key, value] : o) {
|
|
45
|
+
couchbase::core::document_id id(integration.ctx.bucket, "_default", "_default", key);
|
|
46
|
+
couchbase::core::operations::upsert_request req{ id, couchbase::core::utils::json::generate_binary(value) };
|
|
47
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
48
|
+
REQUIRE_SUCCESS(resp.ctx.ec());
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
std::string index_name = test::utils::uniq_id("beer-search-index");
|
|
53
|
+
|
|
54
|
+
{
|
|
55
|
+
auto params = test::utils::read_test_data("search_beers_index_params.json");
|
|
56
|
+
|
|
57
|
+
couchbase::core::management::search::index index{};
|
|
58
|
+
index.name = index_name;
|
|
59
|
+
index.params_json = params;
|
|
60
|
+
index.type = "fulltext-index";
|
|
61
|
+
index.source_name = integration.ctx.bucket;
|
|
62
|
+
index.source_type = "couchbase";
|
|
63
|
+
if (integration.cluster_version().requires_search_replicas()) {
|
|
64
|
+
index.plan_params_json = couchbase::core::utils::json::generate({
|
|
65
|
+
{ "indexPartitions", 1 },
|
|
66
|
+
{ "numReplicas", 1 },
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
couchbase::core::operations::management::search_index_upsert_request req{};
|
|
70
|
+
req.index = index;
|
|
71
|
+
|
|
72
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
73
|
+
REQUIRE((!resp.ctx.ec || resp.ctx.ec == couchbase::errc::common::index_exists));
|
|
74
|
+
if (index_name != resp.name) {
|
|
75
|
+
CB_LOG_INFO("update index name \"{}\" -> \"{}\"", index_name, resp.name);
|
|
76
|
+
}
|
|
77
|
+
index_name = resp.name;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
couchbase::core::json_string simple_query(R"({"query": "description:belgian"})");
|
|
81
|
+
|
|
82
|
+
std::uint64_t beer_sample_doc_count = 5;
|
|
83
|
+
// Wait until expected documents are indexed
|
|
84
|
+
{
|
|
85
|
+
REQUIRE(test::utils::wait_until_indexed(integration.cluster, index_name, beer_sample_doc_count));
|
|
86
|
+
auto ok = test::utils::wait_until(
|
|
87
|
+
[&]() {
|
|
88
|
+
couchbase::core::operations::search_request req{};
|
|
89
|
+
req.index_name = index_name;
|
|
90
|
+
req.query = simple_query;
|
|
91
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
92
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
93
|
+
return resp.rows.size() == beer_sample_doc_count;
|
|
94
|
+
},
|
|
95
|
+
std::chrono::minutes(5));
|
|
96
|
+
REQUIRE(ok);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
SECTION("simple query")
|
|
100
|
+
{
|
|
101
|
+
couchbase::core::operations::search_request req{};
|
|
102
|
+
req.index_name = index_name;
|
|
103
|
+
req.query = simple_query;
|
|
104
|
+
req.sort_specs.emplace_back(couchbase::core::utils::json::generate("_id"));
|
|
105
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
106
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
107
|
+
REQUIRE(resp.rows.size() == 5);
|
|
108
|
+
REQUIRE(resp.rows[0].id == "avery_brewing_company-reverend_the");
|
|
109
|
+
REQUIRE(resp.rows[0].score > 0);
|
|
110
|
+
REQUIRE_THAT(resp.rows[0].index, StartsWith(index_name));
|
|
111
|
+
REQUIRE(resp.rows[0].locations.empty());
|
|
112
|
+
REQUIRE(resp.rows[0].explanation.empty());
|
|
113
|
+
REQUIRE(resp.rows[0].fields.empty());
|
|
114
|
+
REQUIRE(resp.rows[0].fragments.empty());
|
|
115
|
+
REQUIRE(resp.meta.metrics.max_score > 0);
|
|
116
|
+
REQUIRE(resp.meta.metrics.total_rows == 5);
|
|
117
|
+
REQUIRE(resp.meta.metrics.took > std::chrono::nanoseconds(0));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
SECTION("limit")
|
|
121
|
+
{
|
|
122
|
+
couchbase::core::operations::search_request req{};
|
|
123
|
+
req.index_name = index_name;
|
|
124
|
+
req.query = simple_query;
|
|
125
|
+
req.limit = 1;
|
|
126
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
127
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
128
|
+
REQUIRE(resp.rows.size() == 1);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
SECTION("skip")
|
|
132
|
+
{
|
|
133
|
+
couchbase::core::operations::search_request req{};
|
|
134
|
+
req.index_name = index_name;
|
|
135
|
+
req.query = simple_query;
|
|
136
|
+
req.skip = 1;
|
|
137
|
+
req.sort_specs.emplace_back(couchbase::core::utils::json::generate("_id"));
|
|
138
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
139
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
140
|
+
REQUIRE(resp.rows.size() == beer_sample_doc_count - 1);
|
|
141
|
+
REQUIRE(resp.rows[0].id == "bear_republic_brewery-red_rocket_ale");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
SECTION("explain")
|
|
145
|
+
{
|
|
146
|
+
couchbase::core::operations::search_request req{};
|
|
147
|
+
req.index_name = index_name;
|
|
148
|
+
req.query = simple_query;
|
|
149
|
+
req.explain = true;
|
|
150
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
151
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
152
|
+
REQUIRE_FALSE(resp.rows[0].explanation.empty());
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (integration.cluster_version().supports_search_disable_scoring()) {
|
|
156
|
+
SECTION("disable scoring")
|
|
157
|
+
{
|
|
158
|
+
couchbase::core::operations::search_request req{};
|
|
159
|
+
req.index_name = index_name;
|
|
160
|
+
req.query = simple_query;
|
|
161
|
+
req.disable_scoring = true;
|
|
162
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
163
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
164
|
+
REQUIRE(resp.rows[0].score == 0);
|
|
165
|
+
REQUIRE(resp.meta.metrics.max_score == 0);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
SECTION("include locations")
|
|
170
|
+
{
|
|
171
|
+
couchbase::core::operations::search_request req{};
|
|
172
|
+
req.index_name = index_name;
|
|
173
|
+
req.query = simple_query;
|
|
174
|
+
req.sort_specs.emplace_back(couchbase::core::utils::json::generate("_id"));
|
|
175
|
+
req.include_locations = true;
|
|
176
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
177
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
178
|
+
REQUIRE(resp.rows[0].locations.size() == 1);
|
|
179
|
+
REQUIRE(resp.rows[0].locations[0].field == "description");
|
|
180
|
+
REQUIRE(resp.rows[0].locations[0].term == "belgian");
|
|
181
|
+
REQUIRE(resp.rows[0].locations[0].position == 1);
|
|
182
|
+
REQUIRE(resp.rows[0].locations[0].start_offset == 0);
|
|
183
|
+
REQUIRE(resp.rows[0].locations[0].end_offset == 7);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
SECTION("highlight fields default highlight style")
|
|
187
|
+
{
|
|
188
|
+
couchbase::core::operations::search_request req{};
|
|
189
|
+
req.index_name = index_name;
|
|
190
|
+
req.query = simple_query;
|
|
191
|
+
req.sort_specs.emplace_back(couchbase::core::utils::json::generate("_id"));
|
|
192
|
+
req.highlight_fields = { "description" };
|
|
193
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
194
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
195
|
+
REQUIRE(resp.rows[0].fragments["description"][0] == "<mark>Belgian</mark>-Style Quadrupel Ale");
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
SECTION("highlight style")
|
|
199
|
+
{
|
|
200
|
+
{
|
|
201
|
+
couchbase::core::operations::search_request req{};
|
|
202
|
+
req.index_name = index_name;
|
|
203
|
+
req.query = simple_query;
|
|
204
|
+
req.sort_specs.emplace_back(couchbase::core::utils::json::generate("_id"));
|
|
205
|
+
req.highlight_fields = { "description" };
|
|
206
|
+
req.highlight_style = couchbase::core::search_highlight_style::html;
|
|
207
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
208
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
209
|
+
REQUIRE(resp.rows[0].fragments["description"][0] == "<mark>Belgian</mark>-Style Quadrupel Ale");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
{
|
|
213
|
+
couchbase::core::operations::search_request req{};
|
|
214
|
+
req.index_name = index_name;
|
|
215
|
+
req.query = simple_query;
|
|
216
|
+
req.sort_specs.emplace_back(couchbase::core::utils::json::generate("_id"));
|
|
217
|
+
req.highlight_fields = { "description" };
|
|
218
|
+
req.highlight_style = couchbase::core::search_highlight_style::ansi;
|
|
219
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
220
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
221
|
+
// TODO: is there a better way to compare ansi strings?
|
|
222
|
+
std::string snippet = resp.rows[0].fragments["description"][0];
|
|
223
|
+
std::string open = "\x1b[43m";
|
|
224
|
+
std::string close = "\x1b[0m";
|
|
225
|
+
snippet.replace(snippet.find(open), open.size(), "<mark>");
|
|
226
|
+
snippet.replace(snippet.find(close), close.size(), "</mark>");
|
|
227
|
+
REQUIRE(snippet == "<mark>Belgian</mark>-Style Quadrupel Ale");
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
SECTION("fields")
|
|
232
|
+
{
|
|
233
|
+
couchbase::core::operations::search_request req{};
|
|
234
|
+
req.index_name = index_name;
|
|
235
|
+
req.query = simple_query;
|
|
236
|
+
req.sort_specs.emplace_back(couchbase::core::utils::json::generate("_id"));
|
|
237
|
+
req.fields.emplace_back("description");
|
|
238
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
239
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
240
|
+
auto fields = couchbase::core::utils::json::parse(resp.rows[0].fields).get_object();
|
|
241
|
+
REQUIRE(fields.at("description").get_string() == "Belgian-Style Quadrupel Ale");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
SECTION("sort")
|
|
245
|
+
{
|
|
246
|
+
couchbase::core::operations::search_request req{};
|
|
247
|
+
req.index_name = index_name;
|
|
248
|
+
req.query = simple_query;
|
|
249
|
+
req.sort_specs.emplace_back(couchbase::core::utils::json::generate("_score"));
|
|
250
|
+
req.timeout = std::chrono::seconds(1);
|
|
251
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
252
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
253
|
+
REQUIRE(resp.rows[0].id == "bear_republic_brewery-red_rocket_ale");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
SECTION("term facet")
|
|
257
|
+
{
|
|
258
|
+
couchbase::core::operations::search_request req{};
|
|
259
|
+
req.index_name = index_name;
|
|
260
|
+
req.query = simple_query;
|
|
261
|
+
req.facets.insert(std::make_pair("type", R"({"field": "type", "size": 1})"));
|
|
262
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
263
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
264
|
+
REQUIRE(resp.facets.size() == 1);
|
|
265
|
+
REQUIRE(resp.facets[0].name == "type");
|
|
266
|
+
REQUIRE(resp.facets[0].field == "type");
|
|
267
|
+
REQUIRE(resp.facets[0].total == 5);
|
|
268
|
+
REQUIRE(resp.facets[0].missing == 0);
|
|
269
|
+
REQUIRE(resp.facets[0].other == 0);
|
|
270
|
+
REQUIRE(resp.facets[0].terms.size() == 1);
|
|
271
|
+
REQUIRE(resp.facets[0].terms[0].term == "beer");
|
|
272
|
+
REQUIRE(resp.facets[0].terms[0].count == 5);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
SECTION("date range facet")
|
|
276
|
+
{
|
|
277
|
+
couchbase::core::operations::search_request req{};
|
|
278
|
+
req.index_name = index_name;
|
|
279
|
+
req.query = simple_query;
|
|
280
|
+
req.facets.insert(std::make_pair(
|
|
281
|
+
"updated",
|
|
282
|
+
R"({"field": "updated", "size": 2, "date_ranges": [{"name": "old", "end": "2010-08-01"},{"name": "new", "start": "2010-08-01"}]})"));
|
|
283
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
284
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
285
|
+
REQUIRE(resp.facets.size() == 1);
|
|
286
|
+
REQUIRE(resp.facets[0].name == "updated");
|
|
287
|
+
REQUIRE(resp.facets[0].field == "updated");
|
|
288
|
+
REQUIRE(resp.facets[0].total == 5);
|
|
289
|
+
REQUIRE(resp.facets[0].missing == 0);
|
|
290
|
+
REQUIRE(resp.facets[0].other == 0);
|
|
291
|
+
REQUIRE(resp.facets[0].date_ranges.size() == 2);
|
|
292
|
+
REQUIRE(resp.facets[0].date_ranges[0].name == "old");
|
|
293
|
+
REQUIRE(resp.facets[0].date_ranges[0].count == 4);
|
|
294
|
+
REQUIRE_FALSE(resp.facets[0].date_ranges[0].start.has_value());
|
|
295
|
+
REQUIRE(resp.facets[0].date_ranges[0].end == "2010-08-01T00:00:00Z");
|
|
296
|
+
REQUIRE(resp.facets[0].date_ranges[1].name == "new");
|
|
297
|
+
REQUIRE(resp.facets[0].date_ranges[1].count == 1);
|
|
298
|
+
REQUIRE(resp.facets[0].date_ranges[1].start == "2010-08-01T00:00:00Z");
|
|
299
|
+
REQUIRE_FALSE(resp.facets[0].date_ranges[1].end.has_value());
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
SECTION("numeric range facet")
|
|
303
|
+
{
|
|
304
|
+
couchbase::core::operations::search_request req{};
|
|
305
|
+
req.index_name = index_name;
|
|
306
|
+
req.query = simple_query;
|
|
307
|
+
req.facets.insert(std::make_pair(
|
|
308
|
+
"abv", R"({"field": "abv", "size": 2, "numeric_ranges": [{"name": "high", "min": 7},{"name": "low", "max": 7}]})"));
|
|
309
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
310
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
311
|
+
REQUIRE(resp.facets.size() == 1);
|
|
312
|
+
REQUIRE(resp.facets[0].name == "abv");
|
|
313
|
+
REQUIRE(resp.facets[0].field == "abv");
|
|
314
|
+
REQUIRE(resp.facets[0].total == 5);
|
|
315
|
+
REQUIRE(resp.facets[0].missing == 0);
|
|
316
|
+
REQUIRE(resp.facets[0].other == 0);
|
|
317
|
+
REQUIRE(resp.facets[0].numeric_ranges.size() == 2);
|
|
318
|
+
auto high_range = std::find_if(resp.facets[0].numeric_ranges.begin(), resp.facets[0].numeric_ranges.end(), [](const auto& range) {
|
|
319
|
+
return range.name == "high";
|
|
320
|
+
});
|
|
321
|
+
REQUIRE(high_range != resp.facets[0].numeric_ranges.end());
|
|
322
|
+
REQUIRE(high_range->count == 2);
|
|
323
|
+
REQUIRE(std::get<std::uint64_t>(high_range->min) == 7);
|
|
324
|
+
REQUIRE(std::holds_alternative<std::monostate>(high_range->max));
|
|
325
|
+
auto low_range = std::find_if(resp.facets[0].numeric_ranges.begin(), resp.facets[0].numeric_ranges.end(), [](const auto& range) {
|
|
326
|
+
return range.name == "low";
|
|
327
|
+
});
|
|
328
|
+
REQUIRE(low_range != resp.facets[0].numeric_ranges.end());
|
|
329
|
+
REQUIRE(low_range->count == 3);
|
|
330
|
+
REQUIRE(std::holds_alternative<std::monostate>(low_range->min));
|
|
331
|
+
REQUIRE(std::get<std::uint64_t>(low_range->max) == 7);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
SECTION("raw")
|
|
335
|
+
{
|
|
336
|
+
couchbase::core::operations::search_request req{};
|
|
337
|
+
req.index_name = index_name;
|
|
338
|
+
req.query = simple_query;
|
|
339
|
+
std::map<std::string, couchbase::core::json_string> raw{};
|
|
340
|
+
raw.insert(std::make_pair("size", couchbase::core::json_string("1")));
|
|
341
|
+
req.raw = raw;
|
|
342
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
343
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
344
|
+
REQUIRE(resp.rows.size() == 1);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
{
|
|
348
|
+
couchbase::core::operations::management::search_index_drop_request req{};
|
|
349
|
+
req.index_name = index_name;
|
|
350
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
351
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
TEST_CASE("integration: search query consistency", "[integration]")
|
|
356
|
+
{
|
|
357
|
+
test::utils::integration_test_guard integration;
|
|
358
|
+
|
|
359
|
+
if (integration.ctx.deployment == test::utils::deployment_type::elixir) {
|
|
360
|
+
SKIP("elixir deployment is incompatible with parts of this test");
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (!integration.cluster_version().supports_search()) {
|
|
364
|
+
SKIP("cluster does not support search");
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
test::utils::open_bucket(integration.cluster, integration.ctx.bucket);
|
|
368
|
+
|
|
369
|
+
const std::string params =
|
|
370
|
+
R"(
|
|
371
|
+
{
|
|
372
|
+
"mapping": {
|
|
373
|
+
"default_mapping": {
|
|
374
|
+
"enabled": true,
|
|
375
|
+
"dynamic": true
|
|
376
|
+
},
|
|
377
|
+
"default_type": "_default",
|
|
378
|
+
"default_analyzer": "standard",
|
|
379
|
+
"default_field": "_all"
|
|
380
|
+
},
|
|
381
|
+
"doc_config": {
|
|
382
|
+
"mode": "type_field",
|
|
383
|
+
"type_field": "_type"
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
)";
|
|
387
|
+
|
|
388
|
+
auto index_name = test::utils::uniq_id("search_index");
|
|
389
|
+
|
|
390
|
+
{
|
|
391
|
+
couchbase::core::management::search::index index{};
|
|
392
|
+
index.name = index_name;
|
|
393
|
+
index.params_json = params;
|
|
394
|
+
index.type = "fulltext-index";
|
|
395
|
+
index.source_name = integration.ctx.bucket;
|
|
396
|
+
index.source_type = "couchbase";
|
|
397
|
+
if (integration.cluster_version().requires_search_replicas()) {
|
|
398
|
+
index.plan_params_json = couchbase::core::utils::json::generate({
|
|
399
|
+
{ "indexPartitions", 1 },
|
|
400
|
+
{ "numReplicas", 1 },
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
couchbase::core::operations::management::search_index_upsert_request req{};
|
|
404
|
+
req.index = index;
|
|
405
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
406
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
407
|
+
if (index_name != resp.name) {
|
|
408
|
+
CB_LOG_INFO("update index name \"{}\" -> \"{}\"", index_name, resp.name);
|
|
409
|
+
}
|
|
410
|
+
index_name = resp.name;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
REQUIRE(test::utils::wait_for_search_pindexes_ready(integration.cluster, integration.ctx.bucket, index_name));
|
|
414
|
+
|
|
415
|
+
auto value = test::utils::uniq_id("value");
|
|
416
|
+
auto id = couchbase::core::document_id(integration.ctx.bucket, "_default", "_default", test::utils::uniq_id("key"));
|
|
417
|
+
|
|
418
|
+
// FIXME: MB-55920, consistency checks is broken in all known versions of the servers at the moment,
|
|
419
|
+
// it might return empty results without waiting for the mutation. We cannot workaround it in any way.
|
|
420
|
+
// We know that doing a mutation, and then query with consistency checks in the loop is not proper test,
|
|
421
|
+
// but at least it will check the payload format for now, and later when the issue is fixed, the loop
|
|
422
|
+
// has to be removed.
|
|
423
|
+
couchbase::mutation_token token;
|
|
424
|
+
{
|
|
425
|
+
// now update the document and use its mutation token in query later
|
|
426
|
+
auto resp = test::utils::execute(integration.cluster,
|
|
427
|
+
couchbase::core::operations::upsert_request{
|
|
428
|
+
id,
|
|
429
|
+
couchbase::core::utils::json::generate_binary(tao::json::value{
|
|
430
|
+
{ "_type", "test_doc" },
|
|
431
|
+
{ "value", value },
|
|
432
|
+
}),
|
|
433
|
+
});
|
|
434
|
+
REQUIRE_SUCCESS(resp.ctx.ec());
|
|
435
|
+
token = resp.token;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/*
|
|
439
|
+
* Retry query with consistency check until it will succeed or reach 20 attempts.
|
|
440
|
+
*
|
|
441
|
+
* FTS might return empty results. See MB-55920.
|
|
442
|
+
*/
|
|
443
|
+
int attempt = 0;
|
|
444
|
+
bool done = false;
|
|
445
|
+
while (!done) {
|
|
446
|
+
const tao::json::value query{ { "query", fmt::format("value:{}", value) } };
|
|
447
|
+
auto query_json = couchbase::core::json_string(couchbase::core::utils::json::generate(query));
|
|
448
|
+
|
|
449
|
+
{
|
|
450
|
+
couchbase::core::operations::search_request req{};
|
|
451
|
+
req.index_name = index_name;
|
|
452
|
+
req.query = query_json;
|
|
453
|
+
req.mutation_state.emplace_back(token);
|
|
454
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
455
|
+
if (resp.ctx.ec == couchbase::errc::search::consistency_mismatch) {
|
|
456
|
+
// FIXME(MB-55920): ignore "err: bleve: pindex_consistency mismatched partition"
|
|
457
|
+
CB_LOG_INFO("ignore consistency_mismatch: {}", resp.ctx.http_body);
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
INFO(resp.ctx.http_body);
|
|
461
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
462
|
+
switch (resp.rows.size()) {
|
|
463
|
+
case 1:
|
|
464
|
+
done = true;
|
|
465
|
+
break;
|
|
466
|
+
|
|
467
|
+
case 0:
|
|
468
|
+
if (attempt > 20) {
|
|
469
|
+
FAIL("Unable to use search query with consistency. Giving up.");
|
|
470
|
+
}
|
|
471
|
+
++attempt;
|
|
472
|
+
break;
|
|
473
|
+
|
|
474
|
+
default:
|
|
475
|
+
REQUIRE(resp.rows.size() == 1);
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
{
|
|
482
|
+
couchbase::core::operations::management::search_index_drop_request req{};
|
|
483
|
+
req.index_name = index_name;
|
|
484
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
485
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
TEST_CASE("integration: search query collections")
|
|
490
|
+
{
|
|
491
|
+
test::utils::integration_test_guard integration;
|
|
492
|
+
|
|
493
|
+
if (!integration.cluster_version().supports_search()) {
|
|
494
|
+
SKIP("cluster does not support search");
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
if (!integration.cluster_version().supports_collections()) {
|
|
498
|
+
SKIP("cluster does not support collections");
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
test::utils::open_bucket(integration.cluster, integration.ctx.bucket);
|
|
502
|
+
|
|
503
|
+
auto index_name = test::utils::uniq_id("search_index");
|
|
504
|
+
auto collection1_name = test::utils::uniq_id("collection");
|
|
505
|
+
auto collection2_name = test::utils::uniq_id("collection");
|
|
506
|
+
std::string doc = R"({"name": "test"})";
|
|
507
|
+
|
|
508
|
+
for (const auto& collection : { collection1_name, collection2_name }) {
|
|
509
|
+
{
|
|
510
|
+
couchbase::core::operations::management::collection_create_request req{ integration.ctx.bucket, "_default", collection };
|
|
511
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
512
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
513
|
+
auto created = test::utils::wait_until_collection_manifest_propagated(integration.cluster, integration.ctx.bucket, resp.uid);
|
|
514
|
+
REQUIRE(created);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
{
|
|
518
|
+
auto key = test::utils::uniq_id("key");
|
|
519
|
+
auto id = couchbase::core::document_id(integration.ctx.bucket, "_default", collection, key);
|
|
520
|
+
couchbase::core::operations::upsert_request req{ id, couchbase::core::utils::to_binary(doc) };
|
|
521
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
522
|
+
REQUIRE_SUCCESS(resp.ctx.ec());
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
{
|
|
527
|
+
// clang-format off
|
|
528
|
+
std::string params =
|
|
529
|
+
R"(
|
|
530
|
+
{
|
|
531
|
+
"mapping": {
|
|
532
|
+
"types": {
|
|
533
|
+
"_default.)" + collection1_name + R"(": {
|
|
534
|
+
"enabled": true,
|
|
535
|
+
"dynamic": true
|
|
536
|
+
},
|
|
537
|
+
"_default.)" + collection2_name + R"(": {
|
|
538
|
+
"enabled": true,
|
|
539
|
+
"dynamic": true
|
|
540
|
+
}
|
|
541
|
+
},
|
|
542
|
+
"default_mapping": {
|
|
543
|
+
"enabled": false
|
|
544
|
+
},
|
|
545
|
+
"default_type": "_default",
|
|
546
|
+
"default_analyzer": "standard",
|
|
547
|
+
"default_field": "_all"
|
|
548
|
+
},
|
|
549
|
+
"doc_config": {
|
|
550
|
+
"mode": "scope.collection.type_field"
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
)";
|
|
554
|
+
// clang-format on
|
|
555
|
+
|
|
556
|
+
couchbase::core::management::search::index index{};
|
|
557
|
+
index.name = index_name;
|
|
558
|
+
index.params_json = params;
|
|
559
|
+
index.type = "fulltext-index";
|
|
560
|
+
index.source_name = integration.ctx.bucket;
|
|
561
|
+
index.source_type = "couchbase";
|
|
562
|
+
if (integration.cluster_version().requires_search_replicas()) {
|
|
563
|
+
index.plan_params_json = couchbase::core::utils::json::generate({
|
|
564
|
+
{ "indexPartitions", 1 },
|
|
565
|
+
{ "numReplicas", 1 },
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
couchbase::core::operations::management::search_index_upsert_request req{};
|
|
569
|
+
req.index = index;
|
|
570
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
571
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
572
|
+
if (index_name != resp.name) {
|
|
573
|
+
CB_LOG_INFO("update index name \"{}\" -> \"{}\"", index_name, resp.name);
|
|
574
|
+
}
|
|
575
|
+
index_name = resp.name;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
REQUIRE(test::utils::wait_until_indexed(integration.cluster, index_name, 2));
|
|
579
|
+
|
|
580
|
+
couchbase::core::json_string simple_query(R"({"query": "name:test"})");
|
|
581
|
+
|
|
582
|
+
// no collection parameter - both docs returned
|
|
583
|
+
{
|
|
584
|
+
couchbase::core::operations::search_request req{};
|
|
585
|
+
req.index_name = index_name;
|
|
586
|
+
req.query = simple_query;
|
|
587
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
588
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
589
|
+
REQUIRE(resp.rows.size() == 2);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// one collection - only docs from that collection returned
|
|
593
|
+
{
|
|
594
|
+
couchbase::core::operations::search_request req{};
|
|
595
|
+
req.index_name = index_name;
|
|
596
|
+
req.query = simple_query;
|
|
597
|
+
req.collections.emplace_back(collection1_name);
|
|
598
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
599
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
600
|
+
REQUIRE(resp.rows.size() == 1);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// two collections - both docs returned
|
|
604
|
+
{
|
|
605
|
+
couchbase::core::operations::search_request req{};
|
|
606
|
+
req.index_name = index_name;
|
|
607
|
+
req.query = simple_query;
|
|
608
|
+
req.collections.emplace_back(collection1_name);
|
|
609
|
+
req.collections.emplace_back(collection2_name);
|
|
610
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
611
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
612
|
+
REQUIRE(resp.rows.size() == 2);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
{
|
|
616
|
+
couchbase::core::operations::management::search_index_drop_request req{};
|
|
617
|
+
req.index_name = index_name;
|
|
618
|
+
auto resp = test::utils::execute(integration.cluster, req);
|
|
619
|
+
REQUIRE_SUCCESS(resp.ctx.ec);
|
|
620
|
+
}
|
|
621
|
+
}
|