|
| 1 | +#include <libcouchbase/couchbase.h> |
| 2 | +#include <libcouchbase/cbft.h> |
| 3 | +#include <cassert> |
| 4 | +#include <cstdio> |
| 5 | +#include <cstdlib> |
| 6 | +#include <string> |
| 7 | + |
| 8 | +static void rowCallback(lcb_t, int, const lcb_RESPFTS *resp) |
| 9 | +{ |
| 10 | + if (resp->rflags & LCB_RESP_F_FINAL) { |
| 11 | + printf("Status: %d\n", resp->rc); |
| 12 | + printf("Meta: %.*s\n", (int)resp->nrow, resp->row); |
| 13 | + if (resp->htresp) { |
| 14 | + printf("HTTP Response: %.*s\n", (int)resp->htresp->nbody, resp->htresp->body); |
| 15 | + } |
| 16 | + } else { |
| 17 | + printf("Row: %.*s\n", (int)resp->nrow, resp->row); |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +int main(int, char **) |
| 22 | +{ |
| 23 | + lcb_t instance; |
| 24 | + lcb_error_t rc = lcb_create(&instance, NULL); |
| 25 | + assert(rc == LCB_SUCCESS); |
| 26 | + lcb_cntl_string(instance, "detailed_errcodes", "true"); |
| 27 | + lcb_connect(instance); |
| 28 | + lcb_wait(instance); |
| 29 | + assert(lcb_get_bootstrap_status(instance) == LCB_SUCCESS); |
| 30 | + |
| 31 | + // Be sure to include the indexName within the request payload |
| 32 | + std::string encodedQuery( |
| 33 | + "{\"query\":{\"match\":\"hoppy\"},\"indexName\":\"beer-search\",\"size\":10}"); |
| 34 | + lcb_CMDFTS cmd = { 0 }; |
| 35 | + cmd.callback = rowCallback; |
| 36 | + cmd.query = encodedQuery.c_str(); |
| 37 | + cmd.nquery = encodedQuery.size(); |
| 38 | + rc = lcb_fts_query(instance, NULL, &cmd); |
| 39 | + assert(rc == LCB_SUCCESS); |
| 40 | + |
| 41 | + lcb_wait(instance); |
| 42 | + lcb_destroy(instance); |
| 43 | +} |
0 commit comments