Couchbase C++ SDK 1.0.4 (rev. 5355b0f)
Loading...
Searching...
No Matches
boolean_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
25
26#include <cstdint>
27#include <memory>
28#include <vector>
29
30namespace couchbase
31{
63{
64public:
76 {
77 must_ = std::move(query);
78 return *this;
79 }
80
92 template<typename... SearchQuery>
93 auto must(SearchQuery... queries) -> boolean_query&
94 {
95 must_ = conjunction_query(queries...);
96 return *this;
97 }
98
109 {
110 if (!must_) {
111 must_ = conjunction_query();
112 }
113 return must_.value();
114 }
115
127 {
128 should_ = std::move(query);
129 return *this;
130 }
131
143 template<typename... SearchQuery>
144 auto should(SearchQuery... queries) -> boolean_query&
145 {
146 should_ = disjunction_query(queries...);
147 return *this;
148 }
149
161 {
162 if (!should_) {
163 should_ = disjunction_query();
164 }
165 return should_.value();
166 }
167
179 {
180 must_not_ = std::move(query);
181 return *this;
182 }
183
195 template<typename... SearchQuery>
196 auto must_not(SearchQuery... queries) -> boolean_query&
197 {
198 must_not_ = disjunction_query(queries...);
199 return *this;
200 }
201
212 {
213 if (!must_not_) {
214 must_not_ = disjunction_query();
215 }
216 return must_not_.value();
217 }
218
225 [[nodiscard]] auto encode() const -> encoded_search_query override;
226
227private:
228 std::optional<conjunction_query> must_{};
229 std::optional<disjunction_query> should_{};
230 std::optional<disjunction_query> must_not_{};
231};
232} // namespace couchbase
The boolean query is a useful combination of conjunction and disjunction queries.
Definition boolean_query.hxx:63
auto must(conjunction_query query) -> boolean_query &
Set conjunction_query that groups all queries the documents must satisfy.
Definition boolean_query.hxx:75
auto must_not(SearchQuery... queries) -> boolean_query &
Create disjunction_query with given queries and set it as must not query.
Definition boolean_query.hxx:196
auto must_not(disjunction_query query) -> boolean_query &
Set disjunction_query that groups queries the documents must not satisfy.
Definition boolean_query.hxx:178
auto encode() const -> encoded_search_query override
auto must() -> conjunction_query &
Returns conjunction_query that groups all queries the documents must satisfy.
Definition boolean_query.hxx:108
auto should(disjunction_query query) -> boolean_query &
Set disjunction_query that groups queries the documents should satisfy.
Definition boolean_query.hxx:126
auto should(SearchQuery... queries) -> boolean_query &
Create disjunction_query with given queries and set it as should query.
Definition boolean_query.hxx:144
auto should() -> disjunction_query &
Returns disjunction_query that groups queries the documents should satisfy.
Definition boolean_query.hxx:160
auto must(SearchQuery... queries) -> boolean_query &
Create conjunction_query with given queries and set it as must query.
Definition boolean_query.hxx:93
auto must_not() -> disjunction_query &
Returns disjunction_query that groups queries the documents should satisfy.
Definition boolean_query.hxx:211
The conjunction query is a compound query.
Definition conjunction_query.hxx:44
The disjunction query is a compound query.
Definition disjunction_query.hxx:47
Base class for full text search queries.
Definition search_query.hxx:33
Represents a single item from the result of collection::scan()
Definition allow_querying_search_index_options.hxx:28
@ query
The Query service (SQL++)