couchbase 4.2.3 → 4.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (199) hide show
  1. package/deps/couchbase-cxx-client/CMakeLists.txt +54 -4
  2. package/deps/couchbase-cxx-client/README.md +1 -0
  3. package/deps/couchbase-cxx-client/bin/create-search-index +164 -0
  4. package/deps/couchbase-cxx-client/bin/init-cluster +55 -10
  5. package/deps/couchbase-cxx-client/bin/run-unit-tests +62 -6
  6. package/deps/couchbase-cxx-client/bin/travel-sample-index-v6.json +184 -0
  7. package/deps/couchbase-cxx-client/bin/travel-sample-index.json +188 -0
  8. package/deps/couchbase-cxx-client/cmake/Documentation.cmake +0 -1
  9. package/deps/couchbase-cxx-client/cmake/OpenSSL.cmake +98 -3
  10. package/deps/couchbase-cxx-client/cmake/Testing.cmake +8 -0
  11. package/deps/couchbase-cxx-client/cmake/build_config.hxx.in +3 -0
  12. package/deps/couchbase-cxx-client/core/bucket.cxx +183 -152
  13. package/deps/couchbase-cxx-client/core/bucket.hxx +17 -4
  14. package/deps/couchbase-cxx-client/core/cluster.hxx +18 -1
  15. package/deps/couchbase-cxx-client/core/cluster_options.hxx +1 -0
  16. package/deps/couchbase-cxx-client/core/error_context/key_value.cxx +2 -1
  17. package/deps/couchbase-cxx-client/core/error_context/key_value.hxx +10 -12
  18. package/deps/couchbase-cxx-client/core/error_context/search.hxx +1 -1
  19. package/deps/couchbase-cxx-client/core/impl/analytics.cxx +1 -0
  20. package/deps/couchbase-cxx-client/core/impl/boolean_field_query.cxx +40 -0
  21. package/deps/couchbase-cxx-client/core/impl/boolean_query.cxx +62 -0
  22. package/deps/couchbase-cxx-client/core/impl/cluster.cxx +1 -0
  23. package/deps/couchbase-cxx-client/core/impl/conjunction_query.cxx +51 -0
  24. package/deps/couchbase-cxx-client/core/impl/date_range.cxx +89 -0
  25. package/deps/couchbase-cxx-client/core/impl/date_range_facet.cxx +54 -0
  26. package/deps/couchbase-cxx-client/core/impl/date_range_facet_result.cxx +64 -0
  27. package/deps/couchbase-cxx-client/core/impl/date_range_query.cxx +125 -0
  28. package/deps/couchbase-cxx-client/core/impl/disjunction_query.cxx +51 -0
  29. package/deps/couchbase-cxx-client/core/impl/encoded_search_facet.hxx +29 -0
  30. package/deps/couchbase-cxx-client/core/impl/encoded_search_query.hxx +29 -0
  31. package/deps/couchbase-cxx-client/core/impl/encoded_search_sort.hxx +29 -0
  32. package/deps/couchbase-cxx-client/core/impl/geo_bounding_box_query.cxx +46 -0
  33. package/deps/couchbase-cxx-client/core/impl/geo_distance_query.cxx +43 -0
  34. package/deps/couchbase-cxx-client/core/impl/geo_polygon_query.cxx +46 -0
  35. package/deps/couchbase-cxx-client/core/impl/internal_date_range_facet_result.cxx +80 -0
  36. package/deps/couchbase-cxx-client/core/impl/internal_date_range_facet_result.hxx +48 -0
  37. package/deps/couchbase-cxx-client/core/impl/internal_numeric_range_facet_result.cxx +80 -0
  38. package/deps/couchbase-cxx-client/core/impl/internal_numeric_range_facet_result.hxx +48 -0
  39. package/deps/couchbase-cxx-client/core/impl/internal_search_error_context.cxx +141 -0
  40. package/deps/couchbase-cxx-client/core/impl/internal_search_error_context.hxx +61 -0
  41. package/deps/couchbase-cxx-client/core/impl/internal_search_meta_data.cxx +60 -0
  42. package/deps/couchbase-cxx-client/core/impl/internal_search_meta_data.hxx +41 -0
  43. package/deps/couchbase-cxx-client/core/impl/internal_search_result.cxx +84 -0
  44. package/deps/couchbase-cxx-client/core/impl/internal_search_result.hxx +43 -0
  45. package/deps/couchbase-cxx-client/core/impl/internal_search_row.cxx +82 -0
  46. package/deps/couchbase-cxx-client/core/impl/internal_search_row.hxx +56 -0
  47. package/deps/couchbase-cxx-client/core/impl/internal_search_row_location.hxx +32 -0
  48. package/deps/couchbase-cxx-client/core/impl/internal_search_row_locations.cxx +137 -0
  49. package/deps/couchbase-cxx-client/core/impl/internal_search_row_locations.hxx +45 -0
  50. package/deps/couchbase-cxx-client/core/impl/internal_term_facet_result.cxx +80 -0
  51. package/deps/couchbase-cxx-client/core/impl/internal_term_facet_result.hxx +48 -0
  52. package/deps/couchbase-cxx-client/core/impl/key_value_error_context.cxx +98 -0
  53. package/deps/couchbase-cxx-client/core/impl/match_all_query.cxx +35 -0
  54. package/deps/couchbase-cxx-client/core/impl/match_none_query.cxx +35 -0
  55. package/deps/couchbase-cxx-client/core/impl/match_phrase_query.cxx +43 -0
  56. package/deps/couchbase-cxx-client/core/impl/match_query.cxx +59 -0
  57. package/deps/couchbase-cxx-client/core/impl/numeric_range.cxx +49 -0
  58. package/deps/couchbase-cxx-client/core/impl/numeric_range_facet.cxx +54 -0
  59. package/deps/couchbase-cxx-client/core/impl/numeric_range_facet_result.cxx +64 -0
  60. package/deps/couchbase-cxx-client/core/impl/numeric_range_query.cxx +56 -0
  61. package/deps/couchbase-cxx-client/core/impl/phrase_query.cxx +42 -0
  62. package/deps/couchbase-cxx-client/core/impl/prefix_query.cxx +40 -0
  63. package/deps/couchbase-cxx-client/core/impl/query_error_context.cxx +75 -0
  64. package/deps/couchbase-cxx-client/core/impl/query_string_query.cxx +37 -0
  65. package/deps/couchbase-cxx-client/core/impl/regexp_query.cxx +40 -0
  66. package/deps/couchbase-cxx-client/core/impl/search.cxx +191 -0
  67. package/deps/couchbase-cxx-client/core/impl/search_error_context.cxx +147 -0
  68. package/deps/couchbase-cxx-client/core/impl/search_meta_data.cxx +46 -0
  69. package/deps/couchbase-cxx-client/core/impl/search_result.cxx +66 -0
  70. package/deps/couchbase-cxx-client/core/impl/search_row.cxx +74 -0
  71. package/deps/couchbase-cxx-client/core/impl/search_row_location.cxx +64 -0
  72. package/deps/couchbase-cxx-client/core/impl/search_row_locations.cxx +66 -0
  73. package/deps/couchbase-cxx-client/core/impl/search_sort_field.cxx +104 -0
  74. package/deps/couchbase-cxx-client/core/impl/search_sort_id.cxx +43 -0
  75. package/deps/couchbase-cxx-client/core/impl/search_sort_score.cxx +43 -0
  76. package/deps/couchbase-cxx-client/core/impl/term_facet.cxx +36 -0
  77. package/deps/couchbase-cxx-client/core/impl/term_facet_result.cxx +64 -0
  78. package/deps/couchbase-cxx-client/core/impl/term_query.cxx +56 -0
  79. package/deps/couchbase-cxx-client/core/impl/term_range_query.cxx +57 -0
  80. package/deps/couchbase-cxx-client/core/impl/wildcard_query.cxx +40 -0
  81. package/deps/couchbase-cxx-client/core/io/mcbp_command.hxx +9 -2
  82. package/deps/couchbase-cxx-client/core/io/mcbp_session.cxx +54 -37
  83. package/deps/couchbase-cxx-client/core/io/mcbp_session.hxx +4 -3
  84. package/deps/couchbase-cxx-client/core/json_string.hxx +5 -0
  85. package/deps/couchbase-cxx-client/core/meta/version.cxx +18 -4
  86. package/deps/couchbase-cxx-client/core/mozilla_ca_bundle.hxx +39 -0
  87. package/deps/couchbase-cxx-client/core/operations/document_search.cxx +3 -1
  88. package/deps/couchbase-cxx-client/core/operations/document_search.hxx +1 -1
  89. package/deps/couchbase-cxx-client/core/protocol/client_request.hxx +11 -2
  90. package/deps/couchbase-cxx-client/core/protocol/client_response.hxx +1 -0
  91. package/deps/couchbase-cxx-client/core/utils/connection_string.cxx +59 -46
  92. package/deps/couchbase-cxx-client/core/utils/connection_string.hxx +1 -0
  93. package/deps/couchbase-cxx-client/couchbase/analytics_error_context.hxx +1 -1
  94. package/deps/couchbase-cxx-client/couchbase/boolean_field_query.hxx +77 -0
  95. package/deps/couchbase-cxx-client/couchbase/boolean_query.hxx +223 -0
  96. package/deps/couchbase-cxx-client/couchbase/cluster.hxx +39 -0
  97. package/deps/couchbase-cxx-client/couchbase/conjunction_query.hxx +88 -0
  98. package/deps/couchbase-cxx-client/couchbase/date_range.hxx +69 -0
  99. package/deps/couchbase-cxx-client/couchbase/date_range_facet.hxx +56 -0
  100. package/deps/couchbase-cxx-client/couchbase/date_range_facet_result.hxx +55 -0
  101. package/deps/couchbase-cxx-client/couchbase/date_range_query.hxx +265 -0
  102. package/deps/couchbase-cxx-client/couchbase/disjunction_query.hxx +109 -0
  103. package/deps/couchbase-cxx-client/couchbase/doc_id_query.hxx +111 -0
  104. package/deps/couchbase-cxx-client/couchbase/error_context.hxx +17 -8
  105. package/deps/couchbase-cxx-client/couchbase/fmt/analytics_scan_consistency.hxx +52 -0
  106. package/deps/couchbase-cxx-client/{core/topology/error_map_fmt.hxx → couchbase/fmt/key_value_error_map_attribute.hxx} +21 -21
  107. package/deps/couchbase-cxx-client/couchbase/fmt/search_scan_consistency.hxx +49 -0
  108. package/deps/couchbase-cxx-client/couchbase/geo_bounding_box_query.hxx +107 -0
  109. package/deps/couchbase-cxx-client/couchbase/geo_distance_query.hxx +109 -0
  110. package/deps/couchbase-cxx-client/couchbase/geo_point.hxx +32 -0
  111. package/deps/couchbase-cxx-client/couchbase/geo_polygon_query.hxx +85 -0
  112. package/deps/couchbase-cxx-client/couchbase/highlight_style.hxx +45 -0
  113. package/deps/couchbase-cxx-client/couchbase/key_value_error_context.hxx +7 -2
  114. package/deps/couchbase-cxx-client/couchbase/manager_error_context.hxx +1 -1
  115. package/deps/couchbase-cxx-client/couchbase/match_all_query.hxx +43 -0
  116. package/deps/couchbase-cxx-client/couchbase/match_none_query.hxx +43 -0
  117. package/deps/couchbase-cxx-client/couchbase/match_operator.hxx +45 -0
  118. package/deps/couchbase-cxx-client/couchbase/match_phrase_query.hxx +108 -0
  119. package/deps/couchbase-cxx-client/couchbase/match_query.hxx +163 -0
  120. package/deps/couchbase-cxx-client/couchbase/numeric_range.hxx +58 -0
  121. package/deps/couchbase-cxx-client/couchbase/numeric_range_facet.hxx +56 -0
  122. package/deps/couchbase-cxx-client/couchbase/numeric_range_facet_result.hxx +55 -0
  123. package/deps/couchbase-cxx-client/couchbase/numeric_range_query.hxx +143 -0
  124. package/deps/couchbase-cxx-client/couchbase/phrase_query.hxx +93 -0
  125. package/deps/couchbase-cxx-client/couchbase/prefix_query.hxx +82 -0
  126. package/deps/couchbase-cxx-client/couchbase/query_error_context.hxx +3 -1
  127. package/deps/couchbase-cxx-client/couchbase/query_string_query.hxx +72 -0
  128. package/deps/couchbase-cxx-client/couchbase/regexp_query.hxx +82 -0
  129. package/deps/couchbase-cxx-client/couchbase/scope.hxx +39 -0
  130. package/deps/couchbase-cxx-client/couchbase/search_date_range.hxx +68 -0
  131. package/deps/couchbase-cxx-client/couchbase/search_error_context.hxx +138 -0
  132. package/deps/couchbase-cxx-client/couchbase/search_facet.hxx +60 -0
  133. package/deps/couchbase-cxx-client/couchbase/search_facet_result.hxx +50 -0
  134. package/deps/couchbase-cxx-client/couchbase/search_meta_data.hxx +85 -0
  135. package/deps/couchbase-cxx-client/couchbase/search_metrics.hxx +127 -0
  136. package/deps/couchbase-cxx-client/couchbase/search_numeric_range.hxx +69 -0
  137. package/deps/couchbase-cxx-client/couchbase/search_options.hxx +509 -0
  138. package/deps/couchbase-cxx-client/couchbase/search_query.hxx +69 -0
  139. package/deps/couchbase-cxx-client/couchbase/search_result.hxx +77 -0
  140. package/deps/couchbase-cxx-client/couchbase/search_row.hxx +104 -0
  141. package/deps/couchbase-cxx-client/couchbase/search_row_location.hxx +55 -0
  142. package/deps/couchbase-cxx-client/couchbase/search_row_locations.hxx +86 -0
  143. package/deps/couchbase-cxx-client/couchbase/search_scan_consistency.hxx +34 -0
  144. package/deps/couchbase-cxx-client/couchbase/search_sort.hxx +58 -0
  145. package/deps/couchbase-cxx-client/couchbase/search_sort_field.hxx +117 -0
  146. package/deps/couchbase-cxx-client/couchbase/search_sort_field_missing.hxx +26 -0
  147. package/deps/couchbase-cxx-client/couchbase/search_sort_field_mode.hxx +27 -0
  148. package/deps/couchbase-cxx-client/couchbase/search_sort_field_type.hxx +28 -0
  149. package/deps/couchbase-cxx-client/couchbase/search_sort_id.hxx +60 -0
  150. package/deps/couchbase-cxx-client/couchbase/search_sort_score.hxx +60 -0
  151. package/deps/couchbase-cxx-client/couchbase/search_term_range.hxx +51 -0
  152. package/deps/couchbase-cxx-client/couchbase/security_options.hxx +3 -0
  153. package/deps/couchbase-cxx-client/couchbase/subdocument_error_context.hxx +4 -2
  154. package/deps/couchbase-cxx-client/couchbase/term_facet.hxx +48 -0
  155. package/deps/couchbase-cxx-client/couchbase/term_facet_result.hxx +55 -0
  156. package/deps/couchbase-cxx-client/couchbase/term_query.hxx +151 -0
  157. package/deps/couchbase-cxx-client/couchbase/term_range_query.hxx +142 -0
  158. package/deps/couchbase-cxx-client/couchbase/transactions/transaction_options.hxx +1 -1
  159. package/deps/couchbase-cxx-client/couchbase/transactions/transaction_query_options.hxx +2 -1
  160. package/deps/couchbase-cxx-client/couchbase/transactions/transaction_result.hxx +1 -1
  161. package/deps/couchbase-cxx-client/couchbase/transactions.hxx +3 -3
  162. package/deps/couchbase-cxx-client/couchbase/wildcard_query.hxx +83 -0
  163. package/deps/couchbase-cxx-client/docs/Doxyfile.in +1 -1
  164. package/deps/couchbase-cxx-client/docs/cbc-analytics.md +2 -2
  165. package/deps/couchbase-cxx-client/docs/cbc-get.md +3 -2
  166. package/deps/couchbase-cxx-client/docs/cbc-pillowfight.md +7 -2
  167. package/deps/couchbase-cxx-client/docs/cbc-query.md +2 -2
  168. package/deps/couchbase-cxx-client/docs/cbc.md +3 -3
  169. package/deps/couchbase-cxx-client/docs/cli.hxx +5 -5
  170. package/deps/couchbase-cxx-client/docs/mainpage.hxx +42 -5
  171. package/deps/couchbase-cxx-client/test/CMakeLists.txt +1 -0
  172. package/deps/couchbase-cxx-client/test/test_integration_analytics.cxx +28 -6
  173. package/deps/couchbase-cxx-client/test/test_integration_collections.cxx +7 -3
  174. package/deps/couchbase-cxx-client/test/test_integration_connect.cxx +7 -3
  175. package/deps/couchbase-cxx-client/test/test_integration_crud.cxx +13 -3
  176. package/deps/couchbase-cxx-client/test/test_integration_diagnostics.cxx +8 -2
  177. package/deps/couchbase-cxx-client/test/test_integration_durability.cxx +12 -7
  178. package/deps/couchbase-cxx-client/test/test_integration_examples.cxx +283 -11
  179. package/deps/couchbase-cxx-client/test/test_integration_management.cxx +140 -88
  180. package/deps/couchbase-cxx-client/test/test_integration_query.cxx +67 -9
  181. package/deps/couchbase-cxx-client/test/test_integration_range_scan.cxx +12 -12
  182. package/deps/couchbase-cxx-client/test/test_integration_read_replica.cxx +48 -11
  183. package/deps/couchbase-cxx-client/test/test_integration_search.cxx +19 -1
  184. package/deps/couchbase-cxx-client/test/test_integration_subdoc.cxx +60 -9
  185. package/deps/couchbase-cxx-client/test/test_integration_tracer.cxx +3 -0
  186. package/deps/couchbase-cxx-client/test/test_integration_transcoders.cxx +4 -0
  187. package/deps/couchbase-cxx-client/test/test_transaction_examples.cxx +100 -85
  188. package/deps/couchbase-cxx-client/test/test_unit_connection_string.cxx +29 -0
  189. package/deps/couchbase-cxx-client/test/test_unit_search.cxx +427 -0
  190. package/deps/couchbase-cxx-client/test/utils/integration_test_guard.cxx +2 -1
  191. package/deps/couchbase-cxx-client/test/utils/logger.cxx +3 -1
  192. package/deps/couchbase-cxx-client/test/utils/server_version.hxx +31 -15
  193. package/deps/couchbase-cxx-client/test/utils/test_context.cxx +8 -0
  194. package/deps/couchbase-cxx-client/tools/get.cxx +9 -8
  195. package/deps/couchbase-cxx-client/tools/pillowfight.cxx +175 -75
  196. package/deps/couchbase-cxx-client/tools/version.cxx +4 -2
  197. package/dist/binding.d.ts +1 -1
  198. package/package.json +1 -1
  199. package/src/jstocbpp_autogen.hpp +3 -2
@@ -21,9 +21,14 @@
21
21
  #include "core/operations/management/query_index_create.hxx"
22
22
  #include "core/operations/management/query_index_get_all.hxx"
23
23
 
24
+ #include <couchbase/boolean_query.hxx>
24
25
  #include <couchbase/cluster.hxx>
25
26
  #include <couchbase/fmt/cas.hxx>
26
27
  #include <couchbase/fmt/mutation_token.hxx>
28
+ #include <couchbase/match_query.hxx>
29
+ #include <couchbase/numeric_range_query.hxx>
30
+ #include <couchbase/query_string_query.hxx>
31
+ #include <couchbase/term_facet.hxx>
27
32
 
28
33
  #include <tao/json.hpp>
29
34
 
@@ -44,9 +49,9 @@ main(int argc, const char* argv[])
44
49
  return 1;
45
50
  }
46
51
 
47
- std::string connection_string{ argv[1] };
48
- std::string username{ argv[2] };
49
- std::string password{ argv[3] };
52
+ std::string connection_string{ argv[1] }; // "couchbase://127.0.0.1"
53
+ std::string username{ argv[2] }; // "Administrator"
54
+ std::string password{ argv[3] }; // "password"
50
55
  std::string bucket_name{ "travel-sample" };
51
56
 
52
57
  // run IO context on separate thread
@@ -59,6 +64,7 @@ main(int argc, const char* argv[])
59
64
  // For example, optimize timeouts for WAN
60
65
  options.apply_profile("wan_development");
61
66
 
67
+ // [1] connect to cluster using the given connection string and the options
62
68
  auto [cluster, ec] = couchbase::cluster::connect(io, connection_string, options).get();
63
69
  if (ec) {
64
70
  fmt::print("unable to connect to the cluster: {}\n", ec.message());
@@ -72,8 +78,7 @@ main(int argc, const char* argv[])
72
78
  auto scope = bucket.scope("tenant_agent_00");
73
79
  auto collection = scope.collection("users");
74
80
 
75
- {
76
- // upsert document
81
+ { // [2] upsert document
77
82
  auto [ctx, upsert_result] = collection.upsert("my-document", tao::json::value{ { "name", "mike" } }).get();
78
83
  if (ctx.ec()) {
79
84
  fmt::print("unable to upsert the document \"{}\": {}\n", ctx.id(), ctx.ec().message());
@@ -82,8 +87,7 @@ main(int argc, const char* argv[])
82
87
  fmt::print("saved document \"{}\", cas={}, token={}\n", ctx.id(), upsert_result.cas(), upsert_result.mutation_token().value());
83
88
  }
84
89
 
85
- {
86
- // get document
90
+ { // [3] get document
87
91
  auto [ctx, get_result] = collection.get("my-document").get();
88
92
  if (ctx.ec()) {
89
93
  fmt::print("unable to get the document \"{}\": {}\n", ctx.id(), ctx.ec().message());
@@ -93,8 +97,7 @@ main(int argc, const char* argv[])
93
97
  fmt::print("retrieved document \"{}\", name=\"{}\"\n", ctx.id(), name);
94
98
  }
95
99
 
96
- {
97
- // N1QL query
100
+ { // [4] N1QL query
98
101
  auto inventory_scope = bucket.scope("inventory");
99
102
  auto [ctx, query_result] = inventory_scope.query("SELECT * FROM airline WHERE id = 10").get();
100
103
  if (ctx.ec()) {
@@ -106,7 +109,7 @@ main(int argc, const char* argv[])
106
109
  }
107
110
  }
108
111
 
109
- // close cluster connection
112
+ // [5] close cluster connection
110
113
  cluster.close();
111
114
  guard.reset();
112
115
 
@@ -130,7 +133,10 @@ TEST_CASE("example: start using", "[integration]")
130
133
  {
131
134
  test::utils::integration_test_guard integration;
132
135
  if (!integration.cluster_version().supports_collections()) {
133
- return;
136
+ SKIP("cluster does not support collections");
137
+ }
138
+ if (integration.cluster_version().is_mock()) {
139
+ SKIP("GOCAVES cannot load travel-sample bucket. See https://github.com/couchbaselabs/gocaves/issues/101");
134
140
  }
135
141
 
136
142
  {
@@ -180,3 +186,269 @@ TEST_CASE("example: start using", "[integration]")
180
186
 
181
187
  REQUIRE(start_using::main(4, argv) == 0);
182
188
  }
189
+
190
+ namespace example_search
191
+ {
192
+ //! [example-search]
193
+ #include <couchbase/cluster.hxx>
194
+
195
+ #include <couchbase/boolean_query.hxx>
196
+ #include <couchbase/match_query.hxx>
197
+ #include <couchbase/numeric_range_query.hxx>
198
+ #include <couchbase/query_string_query.hxx>
199
+
200
+ #include <couchbase/fmt/cas.hxx>
201
+ #include <couchbase/fmt/mutation_token.hxx>
202
+
203
+ #include <tao/json.hpp>
204
+
205
+ int
206
+ main(int argc, const char* argv[])
207
+ {
208
+ if (argc != 4) {
209
+ fmt::print("USAGE: ./example_search couchbase://127.0.0.1 Administrator password\n");
210
+ return 1;
211
+ }
212
+
213
+ std::string connection_string{ argv[1] }; // "couchbase://127.0.0.1"
214
+ std::string username{ argv[2] }; // "Administrator"
215
+ std::string password{ argv[3] }; // "password"
216
+ std::string bucket_name{ "travel-sample" };
217
+
218
+ // run IO context on separate thread
219
+ asio::io_context io;
220
+ auto guard = asio::make_work_guard(io);
221
+ std::thread io_thread([&io]() { io.run(); });
222
+
223
+ auto options = couchbase::cluster_options(username, password);
224
+ // customize through the 'options'.
225
+ // For example, optimize timeouts for WAN
226
+ options.apply_profile("wan_development");
227
+
228
+ auto [cluster, ec] = couchbase::cluster::connect(io, connection_string, options).get();
229
+ if (ec) {
230
+ fmt::print("unable to connect to the cluster: {}\n", ec.message());
231
+ return 1;
232
+ }
233
+
234
+ {
235
+ fmt::print("--- simple query\n");
236
+ auto [ctx, result] = cluster.search_query("travel-sample-index", couchbase::query_string_query("nice bar")).get();
237
+
238
+ if (ctx.ec()) {
239
+ fmt::print("unable to perform search query: {}, ({}, {})\n", ctx.ec().message(), ctx.status(), ctx.error());
240
+ return 1;
241
+ }
242
+ fmt::print("{} hits, total: {}\n", result.rows().size(), result.meta_data().metrics().total_rows());
243
+ for (const auto& row : result.rows()) {
244
+ fmt::print("id: {}, score: {}\n", row.id(), row.score());
245
+ }
246
+ }
247
+
248
+ {
249
+ fmt::print("--- simple query with fields\n");
250
+ auto [ctx, result] = cluster
251
+ .search_query("travel-sample-index",
252
+ couchbase::query_string_query("nice bar"),
253
+ couchbase::search_options{}.fields({ "description" }))
254
+ .get();
255
+
256
+ if (ctx.ec()) {
257
+ fmt::print("unable to perform search query: {}, ({}, {})\n", ctx.ec().message(), ctx.status(), ctx.error());
258
+ return 1;
259
+ }
260
+ fmt::print("{} hits, total: {}\n", result.rows().size(), result.meta_data().metrics().total_rows());
261
+ for (const auto& row : result.rows()) {
262
+ auto fields = row.fields_as<couchbase::codec::tao_json_serializer>();
263
+ fmt::print("id: {}, score: {}, description: {}\n", row.id(), row.score(), fields["description"].as<std::string>());
264
+ }
265
+ }
266
+
267
+ {
268
+ fmt::print("--- simple query with limit\n");
269
+ auto [ctx, result] =
270
+ cluster
271
+ .search_query("travel-sample-index", couchbase::query_string_query("nice bar"), couchbase::search_options{}.skip(3).limit(4))
272
+ .get();
273
+
274
+ if (ctx.ec()) {
275
+ fmt::print("unable to perform search query: {}, ({}, {})\n", ctx.ec().message(), ctx.status(), ctx.error());
276
+ return 1;
277
+ }
278
+ fmt::print("{} hits, total: {}\n", result.rows().size(), result.meta_data().metrics().total_rows());
279
+ for (const auto& row : result.rows()) {
280
+ fmt::print("id: {}, score: {}\n", row.id(), row.score());
281
+ }
282
+ }
283
+
284
+ {
285
+ fmt::print("--- simple query with highlight\n");
286
+ auto [ctx, result] =
287
+ cluster
288
+ .search_query("travel-sample-index",
289
+ couchbase::query_string_query("nice bar"),
290
+ couchbase::search_options{}.highlight(couchbase::highlight_style::html, { "description", "title" }))
291
+ .get();
292
+
293
+ if (ctx.ec()) {
294
+ fmt::print("unable to perform search query: {}, ({}, {})\n", ctx.ec().message(), ctx.status(), ctx.error());
295
+ return 1;
296
+ }
297
+ fmt::print("{} hits, total: {}\n", result.rows().size(), result.meta_data().metrics().total_rows());
298
+ for (const auto& row : result.rows()) {
299
+ fmt::print("id: {}, score: {}\n", row.id(), row.score());
300
+ for (const auto& [field, fragments] : row.fragments()) {
301
+ fmt::print("- {}:\n", field);
302
+ for (const auto& fragment : fragments) {
303
+ fmt::print("-- {}\n", fragment);
304
+ }
305
+ }
306
+ }
307
+ }
308
+
309
+ {
310
+ fmt::print("--- simple query with collections\n");
311
+ auto [ctx, result] = cluster
312
+ .search_query("travel-sample-index",
313
+ couchbase::query_string_query("west"),
314
+ couchbase::search_options{}.collections({ "airline" }))
315
+ .get();
316
+
317
+ if (ctx.ec()) {
318
+ fmt::print("unable to perform search query: {}, ({}, {})\n", ctx.ec().message(), ctx.status(), ctx.error());
319
+ return 1;
320
+ }
321
+ fmt::print("{} hits, total: {}\n", result.rows().size(), result.meta_data().metrics().total_rows());
322
+ for (const auto& row : result.rows()) {
323
+ fmt::print("id: {}, score: {}\n", row.id(), row.score());
324
+ }
325
+ }
326
+
327
+ {
328
+ fmt::print("--- query with consistency requirements\n");
329
+
330
+ auto bucket = cluster.bucket(bucket_name);
331
+ auto collection = bucket.scope("inventory").collection("hotel");
332
+
333
+ couchbase::mutation_state state;
334
+
335
+ {
336
+ auto [ctx, upsert_result] =
337
+ collection
338
+ .upsert(
339
+ "prancing-pony",
340
+ tao::json::value{
341
+ { "title", "The Prancing Pony" },
342
+ { "type", "hotel" },
343
+ { "description",
344
+ "The inn was located just where the East Road bent round the foot of Bree-hill, within the dike that stretched "
345
+ "around the town. The building was three stories tall with many windows. Its front faced the Road and it had two "
346
+ "wings that ran back towards the elevated ground of the hill, such that in the rear the second floor was at ground "
347
+ "level. " } })
348
+ .get();
349
+ if (ctx.ec()) {
350
+ fmt::print("unable to upsert the document \"{}\": {}\n", ctx.id(), ctx.ec().message());
351
+ return 1;
352
+ }
353
+ fmt::print("saved document \"{}\", cas={}, token={}\n",
354
+ ctx.id(),
355
+ upsert_result.cas(),
356
+ upsert_result.mutation_token().value_or(couchbase::mutation_token{}));
357
+ state.add(upsert_result);
358
+ }
359
+
360
+ auto [ctx, result] =
361
+ cluster
362
+ .search_query("travel-sample-index", couchbase::query_string_query("bree"), couchbase::search_options{}.consistent_with(state))
363
+ .get();
364
+
365
+ if (ctx.ec()) {
366
+ fmt::print("unable to perform search query: {}, ({}, {})\n", ctx.ec().message(), ctx.status(), ctx.error());
367
+ return 1;
368
+ }
369
+ fmt::print("{} hits, total: {}\n", result.rows().size(), result.meta_data().metrics().total_rows());
370
+ for (const auto& row : result.rows()) {
371
+ fmt::print("id: {}, score: {}\n", row.id(), row.score());
372
+ }
373
+ }
374
+
375
+ {
376
+ fmt::print("--- complex query\n");
377
+ auto [ctx, result] = cluster
378
+ .search_query("travel-sample-index",
379
+ couchbase::boolean_query()
380
+ .must(couchbase::match_query("honeymoon").field("reviews.content"),
381
+ couchbase::numeric_range_query().field("reviews.ratings.Overall").min(4))
382
+ .must_not(couchbase::match_query("San Francisco").field("city")),
383
+ couchbase::search_options{}.collections({ "hotel" }).highlight())
384
+ .get();
385
+ if (ctx.ec()) {
386
+ fmt::print("unable to perform search query: {}, ({}, {})\n", ctx.ec().message(), ctx.status(), ctx.error());
387
+ return 1;
388
+ }
389
+ fmt::print("{} hits, total: {}\n", result.rows().size(), result.meta_data().metrics().total_rows());
390
+ for (const auto& row : result.rows()) {
391
+ fmt::print("id: {}, score: {}\n", row.id(), row.score());
392
+ }
393
+ }
394
+
395
+ {
396
+ fmt::print("--- simple query with facets\n");
397
+ auto [ctx, result] =
398
+ cluster
399
+ .search_query("travel-sample-index",
400
+ couchbase::query_string_query("honeymoon"),
401
+ couchbase::search_options{}.collections({ "hotel" }).facet("by_country", couchbase::term_facet("country", 3)))
402
+ .get();
403
+ if (ctx.ec()) {
404
+ fmt::print("unable to perform search query: {}, ({}, {})\n", ctx.ec().message(), ctx.status(), ctx.error());
405
+ return 1;
406
+ }
407
+ fmt::print("{} hits, total: {}\n", result.rows().size(), result.meta_data().metrics().total_rows());
408
+ for (const auto& [name, facet] : result.facets()) {
409
+ fmt::print("{} facet: total={}, missing={}\n", name, facet->total(), facet->missing());
410
+ if (name == "by_country") {
411
+ auto term_facet = std::static_pointer_cast<couchbase::term_facet_result>(facet);
412
+ for (const auto& group : term_facet->terms()) {
413
+ fmt::print("* {}: {}\n", group.name(), group.count());
414
+ }
415
+ }
416
+ }
417
+ }
418
+
419
+ // close cluster connection
420
+ cluster.close();
421
+ guard.reset();
422
+
423
+ io_thread.join();
424
+ return 0;
425
+ }
426
+
427
+ /*
428
+
429
+ $ ./example_search couchbase://127.0.0.1 Administrator password
430
+ saved document "my-document", cas=17486a1722b20000
431
+ retrieved document "my-document", name="mike"
432
+ row: {"airline":{"callsign":"MILE-AIR","country":"United States","iata":"Q5","icao":"MLA","id":10,"name":"40-Mile Air","type":"airline"}}
433
+
434
+ */
435
+ //! [example-search]
436
+ } // namespace example_search
437
+
438
+ TEST_CASE("example: search", "[integration]")
439
+ {
440
+ test::utils::integration_test_guard integration;
441
+ if (!integration.cluster_version().supports_collections()) {
442
+ return;
443
+ }
444
+
445
+ const auto env = test::utils::test_context::load_from_environment();
446
+ const char* argv[] = {
447
+ "example_search", // name of the "executable"
448
+ env.connection_string.c_str(),
449
+ env.username.c_str(),
450
+ env.password.c_str(),
451
+ };
452
+
453
+ REQUIRE(example_search::main(4, argv) == 0);
454
+ }