libcouchbase 1.3.0 → 1.3.2
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 +5 -5
- data/.travis.yml +2 -2
- data/ext/libcouchbase/CMakeLists.txt +51 -25
- data/ext/libcouchbase/CONTRIBUTING.md +46 -65
- data/ext/libcouchbase/RELEASE_NOTES.markdown +163 -0
- data/ext/libcouchbase/cmake/Modules/DownloadLcbDep.cmake +9 -11
- data/ext/libcouchbase/cmake/Modules/FindProfiler.cmake +16 -0
- data/ext/libcouchbase/cmake/Modules/GetVersionInfo.cmake +6 -6
- data/ext/libcouchbase/cmake/config-cmake.h.in +2 -0
- data/ext/libcouchbase/cmake/configure +16 -0
- data/ext/libcouchbase/example/CMakeLists.txt +17 -2
- data/ext/libcouchbase/example/analytics/.gitignore +1 -0
- data/ext/libcouchbase/example/analytics/analytics.c +158 -0
- data/ext/libcouchbase/example/analytics/build-queries.rb +34 -0
- data/ext/libcouchbase/example/analytics/cJSON.c +1 -0
- data/ext/libcouchbase/example/analytics/cJSON.h +1 -0
- data/ext/libcouchbase/example/analytics/queries.h +113 -0
- data/ext/libcouchbase/example/analytics/queries/00-show-dataverse.json +5 -0
- data/ext/libcouchbase/example/analytics/queries/01-setup-dataset-breweries.json +6 -0
- data/ext/libcouchbase/example/analytics/queries/02-setup-dataset-beers.json +6 -0
- data/ext/libcouchbase/example/analytics/queries/03-initiate-shadow.json +6 -0
- data/ext/libcouchbase/example/analytics/queries/04-list-datasets.json +7 -0
- data/ext/libcouchbase/example/analytics/queries/05-count-breweries.json +5 -0
- data/ext/libcouchbase/example/analytics/queries/06-first-brewery.json +6 -0
- data/ext/libcouchbase/example/analytics/queries/07-key-based-lookup.json +6 -0
- data/ext/libcouchbase/example/analytics/queries/08-exact-match-lookup.json +7 -0
- data/ext/libcouchbase/example/analytics/queries/09-exact-match-lookup-different-shape.json +6 -0
- data/ext/libcouchbase/example/analytics/queries/10-other-query-filters.json +6 -0
- data/ext/libcouchbase/example/analytics/queries/11-equijoin.json +9 -0
- data/ext/libcouchbase/example/analytics/queries/12-equijoin-select-star.json +10 -0
- data/ext/libcouchbase/example/analytics/queries/13-ansi-join.json +8 -0
- data/ext/libcouchbase/example/analytics/queries/14-join-select-values.json +8 -0
- data/ext/libcouchbase/example/analytics/queries/15-nested-outer-join.json +7 -0
- data/ext/libcouchbase/example/analytics/queries/16-theta-join.json +8 -0
- data/ext/libcouchbase/example/analytics/queries/17-existential-quantification.json +9 -0
- data/ext/libcouchbase/example/analytics/queries/18-universal-quantification.json +7 -0
- data/ext/libcouchbase/example/analytics/queries/19-simple-aggregation.json +6 -0
- data/ext/libcouchbase/example/analytics/queries/20-simple-aggregation-unwrapped-value.json +6 -0
- data/ext/libcouchbase/example/analytics/queries/21-simple-aggregation-explicit.json +6 -0
- data/ext/libcouchbase/example/analytics/queries/22-grouping-and-aggregation.json +6 -0
- data/ext/libcouchbase/example/analytics/queries/23-grouping-and-aggregation-with-hint.json +7 -0
- data/ext/libcouchbase/example/analytics/queries/24-grouping-and-limits.json +7 -0
- data/ext/libcouchbase/example/analytics/queries/25-named-parameters.json +7 -0
- data/ext/libcouchbase/example/analytics/queries/26-positional-parameters.json +7 -0
- data/ext/libcouchbase/example/crypto/common_provider.c +2 -0
- data/ext/libcouchbase/example/crypto/common_provider.h +2 -0
- data/ext/libcouchbase/example/crypto/openssl_symmetric_decrypt.c +5 -0
- data/ext/libcouchbase/example/crypto/openssl_symmetric_encrypt.c +0 -1
- data/ext/libcouchbase/example/crypto/openssl_symmetric_provider.c +16 -26
- data/ext/libcouchbase/example/db/db.c +10 -6
- data/ext/libcouchbase/example/fts/.gitignore +1 -0
- data/ext/libcouchbase/example/fts/build-queries.rb +33 -0
- data/ext/libcouchbase/example/fts/fts.c +142 -0
- data/ext/libcouchbase/example/fts/queries.h +61 -0
- data/ext/libcouchbase/example/fts/queries/00-simple-text-query.json +12 -0
- data/ext/libcouchbase/example/fts/queries/01-simple-text-query-on-non-default-index.json +9 -0
- data/ext/libcouchbase/example/fts/queries/02-simple-text-query-on-stored-field.json +13 -0
- data/ext/libcouchbase/example/fts/queries/03-match-query-with-facet.json +19 -0
- data/ext/libcouchbase/example/fts/queries/04-docid-query.json +11 -0
- data/ext/libcouchbase/example/fts/queries/05-unanalyzed-term-query-with-fuzziness-level-of-0.json +13 -0
- data/ext/libcouchbase/example/fts/queries/06-unanalyzed-term-query-with-fuzziness-level-of-2.json +14 -0
- data/ext/libcouchbase/example/fts/queries/07-match-phrase-query.json +13 -0
- data/ext/libcouchbase/example/fts/queries/08-phrase-query.json +16 -0
- data/ext/libcouchbase/example/fts/queries/09-query-string-query.json +9 -0
- data/ext/libcouchbase/example/fts/queries/10-conjunction-query.json +21 -0
- data/ext/libcouchbase/example/fts/queries/11-wild-card-query.json +13 -0
- data/ext/libcouchbase/example/fts/queries/12-numeric-range-query.json +11 -0
- data/ext/libcouchbase/example/fts/queries/13-regexp-query.json +13 -0
- data/ext/libcouchbase/example/minimal/.gitignore +1 -0
- data/ext/libcouchbase/example/minimal/query.c +185 -0
- data/ext/libcouchbase/example/subdoc/subdoc-xattrs.c +2 -2
- data/ext/libcouchbase/example/tracing/cJSON.c +1 -1
- data/ext/libcouchbase/example/tracing/cJSON.h +1 -1
- data/ext/libcouchbase/include/libcouchbase/cbft.h +38 -4
- data/ext/libcouchbase/include/libcouchbase/cntl-private.h +8 -97
- data/ext/libcouchbase/include/libcouchbase/cntl.h +288 -8
- data/ext/libcouchbase/include/libcouchbase/couchbase.h +47 -10
- data/ext/libcouchbase/include/libcouchbase/crypto.h +214 -48
- data/ext/libcouchbase/include/libcouchbase/deprecated.h +12 -0
- data/ext/libcouchbase/include/libcouchbase/error.h +33 -2
- data/ext/libcouchbase/include/libcouchbase/ixmgmt.h +1 -1
- data/ext/libcouchbase/include/libcouchbase/n1ql.h +87 -13
- data/ext/libcouchbase/include/libcouchbase/subdoc.h +3 -7
- data/ext/libcouchbase/include/libcouchbase/tracing.h +174 -56
- data/ext/libcouchbase/include/libcouchbase/vbucket.h +21 -1
- data/ext/libcouchbase/include/libcouchbase/views.h +49 -4
- data/ext/libcouchbase/packaging/deb/control +2 -3
- data/ext/libcouchbase/packaging/parse-git-describe.pl +1 -1
- data/ext/libcouchbase/plugins/io/libev/CMakeLists.txt +7 -5
- data/ext/libcouchbase/plugins/io/libevent/CMakeLists.txt +7 -5
- data/ext/libcouchbase/plugins/io/libuv/CMakeLists.txt +14 -12
- data/ext/libcouchbase/plugins/io/libuv/libuv_compat.h +3 -0
- data/ext/libcouchbase/plugins/io/libuv/plugin-libuv.c +14 -6
- data/ext/libcouchbase/plugins/io/select/CMakeLists.txt +7 -5
- data/ext/libcouchbase/src/bootstrap.cc +6 -1
- data/ext/libcouchbase/src/bucketconfig/bc_cccp.cc +2 -7
- data/ext/libcouchbase/src/bucketconfig/bc_file.cc +1 -1
- data/ext/libcouchbase/src/bucketconfig/bc_http.cc +4 -11
- data/ext/libcouchbase/src/bucketconfig/clconfig.h +29 -36
- data/ext/libcouchbase/src/bucketconfig/confmon.cc +4 -2
- data/ext/libcouchbase/src/cntl.cc +181 -151
- data/ext/libcouchbase/src/config_static.h +1 -1
- data/ext/libcouchbase/src/connspec.cc +5 -1
- data/ext/libcouchbase/src/connspec.h +3 -1
- data/ext/libcouchbase/src/crypto.cc +93 -80
- data/ext/libcouchbase/src/dns-srv.cc +1 -1
- data/ext/libcouchbase/src/handler.cc +0 -1
- data/ext/libcouchbase/src/http/http-priv.h +1 -0
- data/ext/libcouchbase/src/http/http.cc +1 -2
- data/ext/libcouchbase/src/instance.cc +21 -2
- data/ext/libcouchbase/src/internal.h +1 -0
- data/ext/libcouchbase/src/lcbio/ctx.c +24 -3
- data/ext/libcouchbase/src/lcbio/ioutils.cc +1 -1
- data/ext/libcouchbase/src/lcbio/rw-inl.h +22 -1
- data/ext/libcouchbase/src/lcbio/ssl.h +2 -0
- data/ext/libcouchbase/src/mc/compress.cc +18 -11
- data/ext/libcouchbase/src/mc/mcreq.c +2 -0
- data/ext/libcouchbase/src/mc/mcreq.h +1 -1
- data/ext/libcouchbase/src/mcserver/mcserver.cc +163 -6
- data/ext/libcouchbase/src/mcserver/negotiate.cc +17 -7
- data/ext/libcouchbase/src/n1ql/n1ql.cc +12 -3
- data/ext/libcouchbase/src/newconfig.cc +4 -3
- data/ext/libcouchbase/src/nodeinfo.cc +1 -7
- data/ext/libcouchbase/src/operations/observe.cc +1 -0
- data/ext/libcouchbase/src/operations/ping.cc +5 -3
- data/ext/libcouchbase/src/retryq.cc +22 -0
- data/ext/libcouchbase/src/retryq.h +2 -1
- data/ext/libcouchbase/src/rnd.cc +5 -12
- data/ext/libcouchbase/src/settings.c +4 -7
- data/ext/libcouchbase/src/settings.h +6 -2
- data/ext/libcouchbase/src/strcodecs/base64.c +59 -0
- data/ext/libcouchbase/src/strcodecs/strcodecs.h +2 -0
- data/ext/libcouchbase/src/trace.h +2 -2
- data/ext/libcouchbase/src/tracing/span.cc +177 -45
- data/ext/libcouchbase/src/tracing/threshold_logging_tracer.cc +70 -28
- data/ext/libcouchbase/src/tracing/tracing-internal.h +33 -48
- data/ext/libcouchbase/src/vbucket/vbucket.c +146 -30
- data/ext/libcouchbase/src/wait.cc +1 -1
- data/ext/libcouchbase/tests/CMakeLists.txt +13 -4
- data/ext/libcouchbase/tests/iotests/mock-environment.cc +1 -1
- data/ext/libcouchbase/tests/iotests/t_misc.cc +2 -2
- data/ext/libcouchbase/tests/iotests/t_views.cc +1 -1
- data/ext/libcouchbase/tests/iotests/testutil.cc +3 -2
- data/ext/libcouchbase/tests/vbucket/confdata/map_node_present_nodesext_missing_nodes.json +94 -0
- data/ext/libcouchbase/tests/vbucket/t_config.cc +15 -0
- data/ext/libcouchbase/tools/CMakeLists.txt +11 -6
- data/ext/libcouchbase/tools/cbc-handlers.h +9 -0
- data/ext/libcouchbase/tools/cbc-proxy.cc +1 -1
- data/ext/libcouchbase/tools/cbc.cc +33 -5
- data/ext/libcouchbase/tools/common/options.cc +1 -1
- data/ext/libcouchbase/tools/extract-packets.rb +110 -0
- data/lib/libcouchbase/connection.rb +13 -5
- data/lib/libcouchbase/ext/tasks.rb +1 -1
- data/lib/libcouchbase/version.rb +1 -1
- metadata +62 -7
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2018 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
|
+
/**
|
|
19
|
+
|
|
20
|
+
CFLAGS="-I$(realpath ../../include) -I$(realpath ../../build/generated)"
|
|
21
|
+
LDFLAGS="-L$(realpath ../../build/lib) -lcouchbase -Wl,-rpath=$(realpath ../../build/lib)"
|
|
22
|
+
make fts
|
|
23
|
+
|
|
24
|
+
The example assumes the existence of "travel-sample" bucket and three
|
|
25
|
+
specific Full Text Indexes, defined for it. These are:
|
|
26
|
+
|
|
27
|
+
- "travel-sample-index-unstored": Uses only the default settings.
|
|
28
|
+
|
|
29
|
+
- "travel-sample-index-stored": Uses default settings, with one exception:
|
|
30
|
+
dynamic fields are stored, for the whole index.
|
|
31
|
+
|
|
32
|
+
- "travel-sample-index-hotel-description": Indexes only the description
|
|
33
|
+
fields of hotel documents, and disables the default type mapping. The index
|
|
34
|
+
has a custom analyzer named myUnicodeAnalyzer defined on it: the analyzer's
|
|
35
|
+
main characteristic is that it uses the unicode tokenizer.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
#include <unistd.h>
|
|
39
|
+
#include <stdio.h>
|
|
40
|
+
#include <stdlib.h>
|
|
41
|
+
#include <string.h>
|
|
42
|
+
|
|
43
|
+
#include <libcouchbase/couchbase.h>
|
|
44
|
+
#include <libcouchbase/cbft.h>
|
|
45
|
+
|
|
46
|
+
#include "queries.h"
|
|
47
|
+
|
|
48
|
+
static void fail(const char *msg)
|
|
49
|
+
{
|
|
50
|
+
printf("[\x1b[31mERROR\x1b[0m] %s\n", msg);
|
|
51
|
+
exit(EXIT_FAILURE);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static void check(lcb_error_t err, const char *msg)
|
|
55
|
+
{
|
|
56
|
+
if (err != LCB_SUCCESS) {
|
|
57
|
+
char buf[1024] = {0};
|
|
58
|
+
snprintf(buf, sizeof(buf), "%s: %s\n", msg, lcb_strerror_short(err));
|
|
59
|
+
fail(buf);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static int err2color(lcb_error_t err)
|
|
64
|
+
{
|
|
65
|
+
switch (err) {
|
|
66
|
+
case LCB_SUCCESS:
|
|
67
|
+
return 49;
|
|
68
|
+
default:
|
|
69
|
+
return 31;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static void ln2space(const void *buf, size_t nbuf)
|
|
74
|
+
{
|
|
75
|
+
size_t ii;
|
|
76
|
+
char *str = (char *)buf;
|
|
77
|
+
for (ii = 0; ii < nbuf; ii++) {
|
|
78
|
+
if (str[ii] == '\n') {
|
|
79
|
+
str[ii] = ' ';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static void row_callback(lcb_t instance, int type, const lcb_RESPFTS *resp)
|
|
85
|
+
{
|
|
86
|
+
ln2space(resp->row, resp->nrow);
|
|
87
|
+
if (resp->rc != LCB_SUCCESS) {
|
|
88
|
+
printf("\x1b[31m%s\x1b[0m: ", lcb_strerror_short(resp->rc));
|
|
89
|
+
}
|
|
90
|
+
printf("%.*s\n", (int)resp->nrow, (char *)resp->row);
|
|
91
|
+
if (resp->rflags & LCB_RESP_F_FINAL) {
|
|
92
|
+
printf("\n");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
int main(int argc, char *argv[])
|
|
97
|
+
{
|
|
98
|
+
lcb_error_t err;
|
|
99
|
+
lcb_t instance;
|
|
100
|
+
char *bucket = NULL;
|
|
101
|
+
size_t ii;
|
|
102
|
+
|
|
103
|
+
if (argc < 2) {
|
|
104
|
+
printf("Usage: %s couchbase://host/bucket [ password [ username ] ]\n", argv[0]);
|
|
105
|
+
exit(EXIT_FAILURE);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
{
|
|
109
|
+
struct lcb_create_st create_options = {0};
|
|
110
|
+
create_options.version = 3;
|
|
111
|
+
create_options.v.v3.connstr = argv[1];
|
|
112
|
+
if (argc > 2) {
|
|
113
|
+
create_options.v.v3.passwd = argv[2];
|
|
114
|
+
}
|
|
115
|
+
if (argc > 3) {
|
|
116
|
+
create_options.v.v3.username = argv[3];
|
|
117
|
+
}
|
|
118
|
+
check(lcb_create(&instance, &create_options), "create couchbase handle");
|
|
119
|
+
check(lcb_connect(instance), "schedule connection");
|
|
120
|
+
lcb_wait(instance);
|
|
121
|
+
check(lcb_get_bootstrap_status(instance), "bootstrap from cluster");
|
|
122
|
+
check(lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_BUCKETNAME, &bucket), "get bucket name");
|
|
123
|
+
if (strcmp(bucket, "travel-sample") != 0) {
|
|
124
|
+
fail("expected bucket to be \"travel-sample\"");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
for (ii = 0; ii < num_queries; ii++) {
|
|
129
|
+
lcb_CMDFTS cmd = {0};
|
|
130
|
+
cmd.callback = row_callback;
|
|
131
|
+
cmd.query = queries[ii].query;
|
|
132
|
+
cmd.nquery = queries[ii].query_len;
|
|
133
|
+
check(lcb_fts_query(instance, NULL, &cmd), "schedule FTS index creation operation");
|
|
134
|
+
printf("----> \x1b[1m%s\x1b[0m\n", queries[ii].comment);
|
|
135
|
+
printf("----> \x1b[32m%.*s\x1b[0m\n", (int)queries[ii].query_len, queries[ii].query);
|
|
136
|
+
lcb_wait(instance);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/* Now that we're all done, close down the connection handle */
|
|
140
|
+
lcb_destroy(instance);
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// This file was generated by queries.rb
|
|
2
|
+
typedef struct fts_query_str { const char *comment; size_t query_len; const char *query; } fts_query_str;
|
|
3
|
+
size_t num_queries = 14;
|
|
4
|
+
fts_query_str queries[15] = {
|
|
5
|
+
{"Simple Text Query on a single word, targeting an index with dynamic fields not stored.",
|
|
6
|
+
110,
|
|
7
|
+
"{\"indexName\":\"travel-sample-index-unstored\",\"size\":10,\"highlight\":{\"style\":\"html\"},\"query\":{\"match\":\"swanky\"}}"},
|
|
8
|
+
|
|
9
|
+
{"Simple Text Query on Non-Default Index, specifying an index that consists only of content derived from a specific field from a specific document-type.",
|
|
10
|
+
90,
|
|
11
|
+
"{\"indexName\":\"travel-sample-index-hotel-description\",\"size\":10,\"query\":{\"match\":\"swanky\"}}"},
|
|
12
|
+
|
|
13
|
+
{"Simple Text Query on Stored Field, specifying the field to be searched; targeting an index with dynamic fields stored, to ensure that field-content is included in the return object.",
|
|
14
|
+
134,
|
|
15
|
+
"{\"indexName\":\"travel-sample-index-stored\",\"size\":10,\"highlight\":{\"style\":\"html\"},\"query\":{\"field\":\"destinationairport\",\"match\":\"MDG\"}}"},
|
|
16
|
+
|
|
17
|
+
{"Match Query with Facet, showing how query-results can be displayed either by row or by hits; and demonstrating use of a facet, which provides aggregation-data.",
|
|
18
|
+
211,
|
|
19
|
+
"{\"indexName\":\"travel-sample-index-stored\",\"highlight\":{\"style\":\"html\"},\"size\":10,\"query\":{\"field\":\"reviews.content\",\"match\":\"La Rue Saint Denis!!\"},\"facets\":{\"Countries Referenced\":{\"size\":5,\"field\":\"country\"}}}"},
|
|
20
|
+
|
|
21
|
+
{"DocId Query, showing results of a query on two document IDs.",
|
|
22
|
+
90,
|
|
23
|
+
"{\"indexName\":\"travel-sample-index-unstored\",\"query\":{\"ids\":[\"hotel_26223\",\"hotel_28960\"]}}"},
|
|
24
|
+
|
|
25
|
+
{"Unanalyzed Term Query with Fuzziness Level of 0, demonstrating how to query on a term with no analysis. Zero fuzziness is specified, to ensure that matches are exact.",
|
|
26
|
+
132,
|
|
27
|
+
"{\"indexName\":\"travel-sample-index-stored\",\"size\":50,\"highlight\":{\"style\":\"html\"},\"query\":{\"field\":\"reviews.content\",\"term\":\"sushi\"}}"},
|
|
28
|
+
|
|
29
|
+
{"Unanalyzed Term Query with Fuzziness Level of 2, which is almost identical to the immediately preceding query; but which this time specifies a fuzziness factor of 2, allowing partial matches to be made. The output from this query can be compared to that of the one immediately preceding.",
|
|
30
|
+
146,
|
|
31
|
+
"{\"indexName\":\"travel-sample-index-stored\",\"size\":50,\"highlight\":{\"style\":\"html\"},\"query\":{\"field\":\"reviews.content\",\"fuzziness\":2,\"term\":\"sushi\"}}"},
|
|
32
|
+
|
|
33
|
+
{"Match Phrase Query, using Analysis, for searching on a phrase.",
|
|
34
|
+
143,
|
|
35
|
+
"{\"indexName\":\"travel-sample-index-stored\",\"size\":10,\"highlight\":{\"style\":\"html\"},\"query\":{\"field\":\"description\",\"match_phrase\":\"Eiffel Tower\"}}"},
|
|
36
|
+
|
|
37
|
+
{"Phrase Query, without Analysis, for searching on a phrase without analysis supported.",
|
|
38
|
+
138,
|
|
39
|
+
"{\"indexName\":\"travel-sample-index-stored\",\"size\":10,\"highlight\":{\"style\":\"html\"},\"query\":{\"field\":\"description\",\"terms\":[\"dorm\",\"rooms\"]}}"},
|
|
40
|
+
|
|
41
|
+
{"Query String Query, showing how a query string is specified as search-input.",
|
|
42
|
+
96,
|
|
43
|
+
"{\"indexName\":\"travel-sample-index-unstored\",\"size\":10,\"query\":{\"query\":\"description: Imperial\"}}"},
|
|
44
|
+
|
|
45
|
+
{"Conjunction Query, whereby two separate queries are defined and then run as part of the search, with only the matches returned by both included in the result-object.",
|
|
46
|
+
207,
|
|
47
|
+
"{\"indexName\":\"travel-sample-index-stored\",\"size\":10,\"highlight\":{\"style\":\"html\"},\"query\":{\"conjuncts\":[{\"field\":\"reviews.content\",\"match\":\"La Rue Saint Denis!!\"},{\"field\":\"description\",\"match\":\"boutique\"}]}}"},
|
|
48
|
+
|
|
49
|
+
{"Wild Card Query, whereby a wildcard is used in the string submitted for the search.",
|
|
50
|
+
135,
|
|
51
|
+
"{\"indexName\":\"travel-sample-index-stored\",\"size\":10,\"highlight\":{\"style\":\"html\"},\"query\":{\"field\":\"description\",\"wildcard\":\"bouti*ue\"}}"},
|
|
52
|
+
|
|
53
|
+
{"Numeric Range Query, whereby minimum and maximum numbers are specified, and matches within the range returned.",
|
|
54
|
+
105,
|
|
55
|
+
"{\"indexName\":\"travel-sample-index-unstored\",\"size\":10,\"query\":{\"field\":\"id\",\"max\":10200.0,\"min\":10100.0}}"},
|
|
56
|
+
|
|
57
|
+
{"Regexp Query, whereby a regular expression is submitted, to generate the conditions for successful matches.",
|
|
58
|
+
130,
|
|
59
|
+
"{\"indexName\":\"travel-sample-index-stored\",\"size\":10,\"highlight\":{\"style\":\"html\"},\"query\":{\"field\":\"description\",\"regexp\":\"[a-z]\"}}"},
|
|
60
|
+
|
|
61
|
+
{NULL, 0, NULL}};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// -*- mode: js; -*-
|
|
2
|
+
// Simple Text Query on a single word, targeting an index with dynamic fields not stored.
|
|
3
|
+
{
|
|
4
|
+
"indexName": "travel-sample-index-unstored",
|
|
5
|
+
"size": 10,
|
|
6
|
+
"highlight": {
|
|
7
|
+
"style": "html"
|
|
8
|
+
},
|
|
9
|
+
"query": {
|
|
10
|
+
"match": "swanky"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// -*- mode: js; -*-
|
|
2
|
+
// Simple Text Query on Non-Default Index, specifying an index that consists only of content derived from a specific field from a specific document-type.
|
|
3
|
+
{
|
|
4
|
+
"indexName": "travel-sample-index-hotel-description",
|
|
5
|
+
"size": 10,
|
|
6
|
+
"query": {
|
|
7
|
+
"match": "swanky"
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// -*- mode: js; -*-
|
|
2
|
+
// Simple Text Query on Stored Field, specifying the field to be searched; targeting an index with dynamic fields stored, to ensure that field-content is included in the return object.
|
|
3
|
+
{
|
|
4
|
+
"indexName": "travel-sample-index-stored",
|
|
5
|
+
"size": 10,
|
|
6
|
+
"highlight": {
|
|
7
|
+
"style": "html"
|
|
8
|
+
},
|
|
9
|
+
"query": {
|
|
10
|
+
"field": "destinationairport",
|
|
11
|
+
"match": "MDG"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// -*- mode: js; -*-
|
|
2
|
+
// Match Query with Facet, showing how query-results can be displayed either by row or by hits; and demonstrating use of a facet, which provides aggregation-data.
|
|
3
|
+
{
|
|
4
|
+
"indexName": "travel-sample-index-stored",
|
|
5
|
+
"highlight": {
|
|
6
|
+
"style": "html"
|
|
7
|
+
},
|
|
8
|
+
"size": 10,
|
|
9
|
+
"query": {
|
|
10
|
+
"field": "reviews.content",
|
|
11
|
+
"match": "La Rue Saint Denis!!"
|
|
12
|
+
},
|
|
13
|
+
"facets": {
|
|
14
|
+
"Countries Referenced": {
|
|
15
|
+
"size": 5,
|
|
16
|
+
"field": "country"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
data/ext/libcouchbase/example/fts/queries/05-unanalyzed-term-query-with-fuzziness-level-of-0.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// -*- mode: js; -*-
|
|
2
|
+
// Unanalyzed Term Query with Fuzziness Level of 0, demonstrating how to query on a term with no analysis. Zero fuzziness is specified, to ensure that matches are exact.
|
|
3
|
+
{
|
|
4
|
+
"indexName": "travel-sample-index-stored",
|
|
5
|
+
"size": 50,
|
|
6
|
+
"highlight": {
|
|
7
|
+
"style": "html"
|
|
8
|
+
},
|
|
9
|
+
"query": {
|
|
10
|
+
"field": "reviews.content",
|
|
11
|
+
"term": "sushi"
|
|
12
|
+
}
|
|
13
|
+
}
|
data/ext/libcouchbase/example/fts/queries/06-unanalyzed-term-query-with-fuzziness-level-of-2.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// -*- mode: js; -*-
|
|
2
|
+
// Unanalyzed Term Query with Fuzziness Level of 2, which is almost identical to the immediately preceding query; but which this time specifies a fuzziness factor of 2, allowing partial matches to be made. The output from this query can be compared to that of the one immediately preceding.
|
|
3
|
+
{
|
|
4
|
+
"indexName": "travel-sample-index-stored",
|
|
5
|
+
"size": 50,
|
|
6
|
+
"highlight": {
|
|
7
|
+
"style": "html"
|
|
8
|
+
},
|
|
9
|
+
"query": {
|
|
10
|
+
"field": "reviews.content",
|
|
11
|
+
"fuzziness": 2,
|
|
12
|
+
"term": "sushi"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// -*- mode: js; -*-
|
|
2
|
+
// Match Phrase Query, using Analysis, for searching on a phrase.
|
|
3
|
+
{
|
|
4
|
+
"indexName": "travel-sample-index-stored",
|
|
5
|
+
"size": 10,
|
|
6
|
+
"highlight": {
|
|
7
|
+
"style": "html"
|
|
8
|
+
},
|
|
9
|
+
"query": {
|
|
10
|
+
"field": "description",
|
|
11
|
+
"match_phrase": "Eiffel Tower"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// -*- mode: js; -*-
|
|
2
|
+
// Phrase Query, without Analysis, for searching on a phrase without analysis supported.
|
|
3
|
+
{
|
|
4
|
+
"indexName": "travel-sample-index-stored",
|
|
5
|
+
"size": 10,
|
|
6
|
+
"highlight": {
|
|
7
|
+
"style": "html"
|
|
8
|
+
},
|
|
9
|
+
"query": {
|
|
10
|
+
"field": "description",
|
|
11
|
+
"terms": [
|
|
12
|
+
"dorm",
|
|
13
|
+
"rooms"
|
|
14
|
+
]
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// -*- mode: js; -*-
|
|
2
|
+
// Conjunction Query, whereby two separate queries are defined and then run as part of the search, with only the matches returned by both included in the result-object.
|
|
3
|
+
{
|
|
4
|
+
"indexName": "travel-sample-index-stored",
|
|
5
|
+
"size": 10,
|
|
6
|
+
"highlight": {
|
|
7
|
+
"style": "html"
|
|
8
|
+
},
|
|
9
|
+
"query": {
|
|
10
|
+
"conjuncts": [
|
|
11
|
+
{
|
|
12
|
+
"field": "reviews.content",
|
|
13
|
+
"match": "La Rue Saint Denis!!"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"field": "description",
|
|
17
|
+
"match": "boutique"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// -*- mode: js; -*-
|
|
2
|
+
// Wild Card Query, whereby a wildcard is used in the string submitted for the search.
|
|
3
|
+
{
|
|
4
|
+
"indexName": "travel-sample-index-stored",
|
|
5
|
+
"size": 10,
|
|
6
|
+
"highlight": {
|
|
7
|
+
"style": "html"
|
|
8
|
+
},
|
|
9
|
+
"query": {
|
|
10
|
+
"field": "description",
|
|
11
|
+
"wildcard": "bouti*ue"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// -*- mode: js; -*-
|
|
2
|
+
// Numeric Range Query, whereby minimum and maximum numbers are specified, and matches within the range returned.
|
|
3
|
+
{
|
|
4
|
+
"indexName": "travel-sample-index-unstored",
|
|
5
|
+
"size": 10,
|
|
6
|
+
"query": {
|
|
7
|
+
"field": "id",
|
|
8
|
+
"max": 10200.0,
|
|
9
|
+
"min": 10100.0
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// -*- mode: js; -*-
|
|
2
|
+
// Regexp Query, whereby a regular expression is submitted, to generate the conditions for successful matches.
|
|
3
|
+
{
|
|
4
|
+
"indexName": "travel-sample-index-stored",
|
|
5
|
+
"size": 10,
|
|
6
|
+
"highlight": {
|
|
7
|
+
"style": "html"
|
|
8
|
+
},
|
|
9
|
+
"query": {
|
|
10
|
+
"field": "description",
|
|
11
|
+
"regexp": "[a-z]"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
query
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2018 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
|
+
/**
|
|
19
|
+
|
|
20
|
+
CFLAGS="-I$(realpath ../../include) -I$(realpath ../../build/generated)"
|
|
21
|
+
LDFLAGS="-L$(realpath ../../build/lib) -lcouchbase -Wl,-rpath=$(realpath ../../build/lib)"
|
|
22
|
+
make query
|
|
23
|
+
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <unistd.h>
|
|
27
|
+
#include <stdio.h>
|
|
28
|
+
#include <stdlib.h>
|
|
29
|
+
#include <string.h>
|
|
30
|
+
#include <signal.h>
|
|
31
|
+
|
|
32
|
+
#include <libcouchbase/couchbase.h>
|
|
33
|
+
#include <libcouchbase/n1ql.h>
|
|
34
|
+
#include <libcouchbase/ixmgmt.h>
|
|
35
|
+
|
|
36
|
+
static void check(lcb_error_t err, const char *msg)
|
|
37
|
+
{
|
|
38
|
+
if (err != LCB_SUCCESS) {
|
|
39
|
+
fprintf(stderr, "[\x1b[31mERROR\x1b[0m] %s: %s\n", msg, lcb_strerror_short(err));
|
|
40
|
+
exit(EXIT_FAILURE);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static int err2color(lcb_error_t err)
|
|
45
|
+
{
|
|
46
|
+
switch (err) {
|
|
47
|
+
case LCB_SUCCESS:
|
|
48
|
+
return 32;
|
|
49
|
+
case LCB_KEY_EEXISTS:
|
|
50
|
+
return 33;
|
|
51
|
+
default:
|
|
52
|
+
return 31;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static void ln2space(const void *buf, size_t nbuf)
|
|
57
|
+
{
|
|
58
|
+
size_t ii;
|
|
59
|
+
char *str = (char *)buf;
|
|
60
|
+
for (ii = 0; ii < nbuf; ii++) {
|
|
61
|
+
if (str[ii] == '\n') {
|
|
62
|
+
str[ii] = ' ';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static void row_callback(lcb_t instance, int type, const lcb_RESPN1QL *resp)
|
|
68
|
+
{
|
|
69
|
+
ln2space(resp->row, resp->nrow);
|
|
70
|
+
fprintf(stderr, "[\x1b[%dmQUERY\x1b[0m] %s, (%d) %.*s\n", err2color(resp->rc), lcb_strerror_short(resp->rc),
|
|
71
|
+
(int)resp->nrow, (int)resp->nrow, (char *)resp->row);
|
|
72
|
+
if (resp->rflags & LCB_RESP_F_FINAL) {
|
|
73
|
+
fprintf(stderr, "\n");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static void idx_callback(lcb_t instance, int type, const lcb_RESPN1XMGMT *resp)
|
|
78
|
+
{
|
|
79
|
+
const lcb_RESPN1QL *inner = resp->inner;
|
|
80
|
+
ln2space(inner->row, inner->nrow);
|
|
81
|
+
fprintf(stderr, "[\x1b[%dmINDEX\x1b[0m] %s, (%d) %.*s\n", err2color(resp->rc), lcb_strerror_short(resp->rc),
|
|
82
|
+
(int)inner->nrow, (int)inner->nrow, (char *)inner->row);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
static void kv_callback(lcb_t instance, int type, const lcb_RESPBASE *resp)
|
|
86
|
+
{
|
|
87
|
+
fprintf(stderr, "[\x1b[%dm%-5s\x1b[0m] %s, key=%.*s\n", err2color(resp->rc), lcb_strcbtype(type),
|
|
88
|
+
lcb_strerror_short(resp->rc), (int)resp->nkey, resp->key);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
static int running = 1;
|
|
92
|
+
static void sigint_handler(int unused)
|
|
93
|
+
{
|
|
94
|
+
running = 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
int main(int argc, char *argv[])
|
|
98
|
+
{
|
|
99
|
+
lcb_error_t err;
|
|
100
|
+
lcb_t instance;
|
|
101
|
+
char *bucket = NULL;
|
|
102
|
+
const char *key = "user:king_arthur";
|
|
103
|
+
const char *val = "{"
|
|
104
|
+
" \"email\": \"kingarthur@couchbase.com\","
|
|
105
|
+
" \"interests\": [\"Holy Grail\", \"African Swallows\"]"
|
|
106
|
+
"}";
|
|
107
|
+
|
|
108
|
+
if (argc < 2) {
|
|
109
|
+
fprintf(stderr, "Usage: %s couchbase://host/bucket [ password [ username ] ]\n", argv[0]);
|
|
110
|
+
exit(EXIT_FAILURE);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
{
|
|
114
|
+
struct lcb_create_st create_options = {0};
|
|
115
|
+
create_options.version = 3;
|
|
116
|
+
create_options.v.v3.connstr = argv[1];
|
|
117
|
+
if (argc > 2) {
|
|
118
|
+
create_options.v.v3.passwd = argv[2];
|
|
119
|
+
}
|
|
120
|
+
if (argc > 3) {
|
|
121
|
+
create_options.v.v3.username = argv[3];
|
|
122
|
+
}
|
|
123
|
+
check(lcb_create(&instance, &create_options), "create couchbase handle");
|
|
124
|
+
check(lcb_connect(instance), "schedule connection");
|
|
125
|
+
lcb_wait(instance);
|
|
126
|
+
check(lcb_get_bootstrap_status(instance), "bootstrap from cluster");
|
|
127
|
+
check(lcb_cntl(instance, LCB_CNTL_GET, LCB_CNTL_BUCKETNAME, &bucket), "get bucket name");
|
|
128
|
+
lcb_install_callback3(instance, LCB_CALLBACK_GET, kv_callback);
|
|
129
|
+
lcb_install_callback3(instance, LCB_CALLBACK_STORE, kv_callback);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
{
|
|
133
|
+
lcb_CMDSTORE cmd = {0};
|
|
134
|
+
LCB_CMD_SET_KEY(&cmd, key, strlen(key));
|
|
135
|
+
LCB_CMD_SET_VALUE(&cmd, val, strlen(val));
|
|
136
|
+
cmd.operation = LCB_SET;
|
|
137
|
+
check(lcb_store3(instance, NULL, &cmd), "schedule STORE operation");
|
|
138
|
+
lcb_wait(instance);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
{
|
|
142
|
+
lcb_CMDGET cmd = {0};
|
|
143
|
+
LCB_CMD_SET_KEY(&cmd, key, strlen(key));
|
|
144
|
+
check(lcb_get3(instance, NULL, &cmd), "schedule GET operation");
|
|
145
|
+
lcb_wait(instance);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
{
|
|
149
|
+
lcb_CMDN1XMGMT cmd = {0};
|
|
150
|
+
cmd.callback = idx_callback;
|
|
151
|
+
cmd.spec.flags = LCB_N1XSPEC_F_PRIMARY;
|
|
152
|
+
cmd.spec.ixtype = LCB_N1XSPEC_T_GSI;
|
|
153
|
+
check(lcb_n1x_create(instance, NULL, &cmd), "schedule N1QL index creation operation");
|
|
154
|
+
lcb_wait(instance);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/* setup CTRL-C handler */
|
|
158
|
+
struct sigaction action;
|
|
159
|
+
sigemptyset(&action.sa_mask);
|
|
160
|
+
action.sa_handler = sigint_handler;
|
|
161
|
+
action.sa_flags = 0;
|
|
162
|
+
sigaction(SIGINT, &action, NULL);
|
|
163
|
+
|
|
164
|
+
while (running) {
|
|
165
|
+
lcb_CMDN1QL cmd = {0};
|
|
166
|
+
char query[1024] = {0};
|
|
167
|
+
const char *param = "\"African Swallows\"";
|
|
168
|
+
lcb_N1QLPARAMS *builder = lcb_n1p_new();
|
|
169
|
+
|
|
170
|
+
snprintf(query, sizeof(query), "SELECT * FROM `%s` WHERE $1 in interests LIMIT 1", bucket);
|
|
171
|
+
check(lcb_n1p_setstmtz(builder, query), "set QUERY statement");
|
|
172
|
+
check(lcb_n1p_posparam(builder, param, strlen(param)), "set QUERY positional parameter");
|
|
173
|
+
check(lcb_n1p_setopt(builder, "pretty", strlen("pretty"), "false", strlen("false")),
|
|
174
|
+
"set QUERY 'pretty' option");
|
|
175
|
+
check(lcb_n1p_mkcmd(builder, &cmd), "build QUERY command structure");
|
|
176
|
+
cmd.callback = row_callback;
|
|
177
|
+
check(lcb_n1ql_query(instance, NULL, &cmd), "schedule QUERY operation");
|
|
178
|
+
lcb_n1p_free(builder);
|
|
179
|
+
lcb_wait(instance);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* Now that we're all done, close down the connection handle */
|
|
183
|
+
lcb_destroy(instance);
|
|
184
|
+
return 0;
|
|
185
|
+
}
|