Couchbase C++ SDK 1.0.2 (rev. 51f4775)
Loading...
Searching...
No Matches
term_query.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright 2023-Present 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#pragma once
19
22
23#include <cstdint>
24#include <optional>
25#include <stdexcept>
26#include <string>
27
28namespace couchbase
29{
43{
44public:
59 explicit term_query(std::string term)
60 : term_{ std::move(term) }
61 {
62 }
63
80 auto prefix_length(std::uint32_t length) -> term_query&
81 {
82 if (length == 0) {
83 throw std::invalid_argument("prefix_length must be positive");
84 }
85
86 prefix_length_ = length;
87 return *this;
88 }
89
100 auto field(std::string field_name) -> term_query&
101 {
102 field_ = std::move(field_name);
103 return *this;
104 }
105
117 auto fuzziness(std::uint32_t fuzziness) -> term_query&
118 {
119 fuzziness_ = fuzziness;
120 return *this;
121 }
122
133 auto match_operator(couchbase::match_operator concatenation_operator) -> term_query&
134 {
135 operator_ = concatenation_operator;
136 return *this;
137 }
138
145 [[nodiscard]] auto encode() const -> encoded_search_query override;
146
147private:
148 std::string term_;
149 std::optional<std::uint32_t> prefix_length_{};
150 std::optional<std::string> field_{};
151 std::optional<std::uint32_t> fuzziness_{};
152 std::optional<couchbase::match_operator> operator_{};
153};
154} // namespace couchbase
Base class for full text search queries.
Definition search_query.hxx:33
A query that looks for exact matches of the term in the index (no analyzer, no stemming).
Definition term_query.hxx:43
term_query(std::string term)
Create a new term query.
Definition term_query.hxx:59
auto field(std::string field_name) -> term_query &
If a field is specified, only terms in that field will be matched.
Definition term_query.hxx:100
auto match_operator(couchbase::match_operator concatenation_operator) -> term_query &
Defines how the individual match terms should be logically concatenated.
Definition term_query.hxx:133
auto encode() const -> encoded_search_query override
auto prefix_length(std::uint32_t length) -> term_query &
Require that the term also have the same prefix of the specified length (must be positive).
Definition term_query.hxx:80
auto fuzziness(std::uint32_t fuzziness) -> term_query &
Perform fuzzy matching.
Definition term_query.hxx:117
Represents a single item from the result of collection::scan()
Definition allow_querying_search_index_options.hxx:28
match_operator
Defines how the individual match terms should be logically concatenated.
Definition match_operator.hxx:28