Couchbase C++ SDK 1.0.4 (rev. 5355b0f)
Loading...
Searching...
No Matches
boolean_query Class Reference

The boolean query is a useful combination of conjunction and disjunction queries. More...

#include <couchbase/boolean_query.hxx>

Inheritance diagram for boolean_query:
Inheritance graph

Public Member Functions

auto must (conjunction_query query) -> boolean_query &
 Set conjunction_query that groups all queries the documents must satisfy.
 
template<typename... SearchQuery>
auto must (SearchQuery... queries) -> boolean_query &
 Create conjunction_query with given queries and set it as must query.
 
auto must () -> conjunction_query &
 Returns conjunction_query that groups all queries the documents must satisfy.
 
auto should (disjunction_query query) -> boolean_query &
 Set disjunction_query that groups queries the documents should satisfy.
 
template<typename... SearchQuery>
auto should (SearchQuery... queries) -> boolean_query &
 Create disjunction_query with given queries and set it as should query.
 
auto should () -> disjunction_query &
 Returns disjunction_query that groups queries the documents should satisfy.
 
auto must_not (disjunction_query query) -> boolean_query &
 Set disjunction_query that groups queries the documents must not satisfy.
 
template<typename... SearchQuery>
auto must_not (SearchQuery... queries) -> boolean_query &
 Create disjunction_query with given queries and set it as must not query.
 
auto must_not () -> disjunction_query &
 Returns disjunction_query that groups queries the documents should satisfy.
 
auto encode () const -> encoded_search_query override
 
- Public Member Functions inherited from search_query
virtual ~search_query ()=default
 
template<typename derived_query = search_query, std::enable_if_t< std::is_base_of_v< search_query, derived_query >, bool > = true>
auto boost (double boost) -> derived_query &
 The boost parameter is used to increase the relative weight of a clause (with a boost greater than 1) or decrease the relative weight (with a boost between 0 and 1).
 

Additional Inherited Members

- Protected Member Functions inherited from search_query
 search_query ()=default
 
- Protected Attributes inherited from search_query
std::optional< double > boost_ {}
 

Detailed Description

The boolean query is a useful combination of conjunction and disjunction queries.

A boolean query takes three lists of queries:

  • must - result documents must satisfy all of these queries.
  • should - result documents should satisfy these queries.
  • must not - result documents must not satisfy any of these queries.

At execution, a boolean query that has no child queries in any 3 categories is not allowed and will fail fast.

The inner representation of child queries in the must/must_not/should sections are respectively a conjunction_query and two disjunction_query.

In the example below the following rules enforced by the boolean query:

  • retrieved documents MUST match "hostel room" in their reviews.content field AND have true in free_breakfast field.
  • also the documents SHOULD have EITHER reviews.ratings.Overall > 4 OR reviews.ratings.Service <blockquote>&zwj;5.
  • and finally, exclude documents with city "Padfield" or "Gilingham".
query.must(couchbase::match_query("hostel room").field("reviews.content"),
couchbase::boolean_field_query(true).field("free_breakfast"));
query.should(couchbase::numeric_range_query().field("reviews.ratings.Overall").min(4),
couchbase::numeric_range_query().field("reviews.ratings.Service").min(5));
query.must_not(couchbase::match_query("Padfield Gilingham").field("city"));
See also
https://docs.couchbase.com/server/current/fts/fts-supported-queries-boolean-field-query.html server documentation
Since
1.0.0
Committed
Generally available API and should be preferred in production

Member Function Documentation

◆ encode()

auto encode ( ) const -> encoded_search_query
nodiscardoverridevirtual
Returns
encoded representation of the query.
Since
1.0.0
Internal
Internal interface

Implements search_query.

◆ must() [1/3]

auto must ( ) -> conjunction_query&
inline

Returns conjunction_query that groups all queries the documents must satisfy.

Use it to add more queries.

Returns
must-query
Since
1.0.0
Committed
Generally available API and should be preferred in production

◆ must() [2/3]

auto must ( conjunction_query query) -> boolean_query&
inline

Set conjunction_query that groups all queries the documents must satisfy.

Parameters
querymust-query
Returns
this query for chaining purposes.
Since
1.0.0
Committed
Generally available API and should be preferred in production

◆ must() [3/3]

template<typename... SearchQuery>
auto must ( SearchQuery... queries) -> boolean_query&
inline

Create conjunction_query with given queries and set it as must query.

Template Parameters
SearchQueryany subclass of search_query
Parameters
queries
Returns
this query for chaining purposes.
Since
1.0.0
Committed
Generally available API and should be preferred in production

◆ must_not() [1/3]

auto must_not ( ) -> disjunction_query&
inline

Returns disjunction_query that groups queries the documents should satisfy.

Use it to add more queries.

Returns
must_not-query
Since
1.0.0
Committed
Generally available API and should be preferred in production

◆ must_not() [2/3]

auto must_not ( disjunction_query query) -> boolean_query&
inline

Set disjunction_query that groups queries the documents must not satisfy.

Parameters
querymust_not-query
Returns
this query for chaining purposes.
Since
1.0.0
Committed
Generally available API and should be preferred in production

◆ must_not() [3/3]

template<typename... SearchQuery>
auto must_not ( SearchQuery... queries) -> boolean_query&
inline

Create disjunction_query with given queries and set it as must not query.

Template Parameters
SearchQueryany subclass of search_query
Parameters
queries
Returns
this query for chaining purposes.
Since
1.0.0
Committed
Generally available API and should be preferred in production

◆ should() [1/3]

auto should ( ) -> disjunction_query&
inline

Returns disjunction_query that groups queries the documents should satisfy.

Use it to add more queries or change disjunction_query::min.

Returns
should-query
Since
1.0.0
Committed
Generally available API and should be preferred in production

◆ should() [2/3]

auto should ( disjunction_query query) -> boolean_query&
inline

Set disjunction_query that groups queries the documents should satisfy.

Parameters
queryshould-query
Returns
this query for chaining purposes.
Since
1.0.0
Committed
Generally available API and should be preferred in production

◆ should() [3/3]

template<typename... SearchQuery>
auto should ( SearchQuery... queries) -> boolean_query&
inline

Create disjunction_query with given queries and set it as should query.

Template Parameters
SearchQueryany subclass of search_query
Parameters
queries
Returns
this query for chaining purposes.
Since
1.0.0
Committed
Generally available API and should be preferred in production

The documentation for this class was generated from the following file: