Package com.mongodb.client.model.search
Interface SearchOperator
- All Superinterfaces:
Bson
- All Known Subinterfaces:
AutocompleteSearchOperator
,CompoundSearchOperator
,DateNearSearchOperator
,DateRangeSearchOperator
,ExistsSearchOperator
,FilterCompoundSearchOperator
,GeoNearSearchOperator
,MustCompoundSearchOperator
,MustNotCompoundSearchOperator
,NumberNearSearchOperator
,NumberRangeSearchOperator
,ShouldCompoundSearchOperator
,TextSearchOperator
The core part of the
$search
pipeline stage of an aggregation pipeline.- Since:
- 4.7
- MongoDB Atlas documentation
- Search operators
-
Field Summary
Fields inherited from interface org.bson.conversions.Bson
DEFAULT_CODEC_REGISTRY
-
Method Summary
Modifier and TypeMethodDescriptionstatic AutocompleteSearchOperator
autocomplete
(FieldSearchPath path, Iterable<String> queries) Returns aSearchOperator
that may be used to implement search-as-you-type functionality.static AutocompleteSearchOperator
autocomplete
(FieldSearchPath path, String query, String... queries) Returns aSearchOperator
that may be used to implement search-as-you-type functionality.static CompoundSearchOperatorBase
compound()
Returns a base for aSearchOperator
that may combine multipleSearchOperator
s.static DateRangeSearchOperatorBase
dateRange
(FieldSearchPath path, FieldSearchPath... paths) Returns a base for aSearchOperator
that tests if the BSONDate
values of the specified fields are within an interval.static DateRangeSearchOperatorBase
dateRange
(Iterable<? extends FieldSearchPath> paths) Returns a base for aSearchOperator
that tests if the BSONDate
values of the specified fields are within an interval.static ExistsSearchOperator
exists
(FieldSearchPath path) Returns aSearchOperator
that tests if thepath
exists in a document.static GeoNearSearchOperator
near
(Point origin, Number pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.static GeoNearSearchOperator
near
(Point origin, Number pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.static NumberNearSearchOperator
near
(Number origin, Number pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.static NumberNearSearchOperator
near
(Number origin, Number pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.static DateNearSearchOperator
near
(Instant origin, Duration pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.static DateNearSearchOperator
near
(Instant origin, Duration pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.numberRange
(FieldSearchPath path, FieldSearchPath... paths) Returns a base for aSearchOperator
that tests if the BSON32-bit integer
/64-bit integer
/Double
values of the specified fields are within an interval.numberRange
(Iterable<? extends FieldSearchPath> paths) Returns a base for aSearchOperator
that tests if the BSON32-bit integer
/64-bit integer
/Double
values of the specified fields are within an interval.static SearchOperator
Creates aSearchOperator
from aBson
in situations when there is no builder method that better satisfies your needs.score
(SearchScore modifier) Creates a newSearchOperator
with the scoring modifier specified.static TextSearchOperator
text
(SearchPath path, String query) Returns aSearchOperator
that performs a full-text search.static TextSearchOperator
text
(Iterable<? extends SearchPath> paths, Iterable<String> queries) Returns aSearchOperator
that performs a full-text search.Methods inherited from interface org.bson.conversions.Bson
toBsonDocument, toBsonDocument
-
Method Details
-
score
Creates a newSearchOperator
with the scoring modifier specified.- Parameters:
modifier
- The scoring modifier.- Returns:
- A new
SearchOperator
.
-
compound
Returns a base for aSearchOperator
that may combine multipleSearchOperator
s. CombiningSearchOperator
s affects calculation of the relevance score.- Returns:
- A base for a
CompoundSearchOperator
. - MongoDB Atlas documentation
- compound operator
-
exists
Returns aSearchOperator
that tests if thepath
exists in a document.- Parameters:
path
- The path to test.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- exists operator
-
text
Returns aSearchOperator
that performs a full-text search.- Parameters:
path
- The field to be searched.query
- The string to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- text operator
-
text
Returns aSearchOperator
that performs a full-text search.- Parameters:
paths
- The non-empty fields to be searched.queries
- The non-empty strings to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- text operator
-
autocomplete
static AutocompleteSearchOperator autocomplete(FieldSearchPath path, String query, String... queries) Returns aSearchOperator
that may be used to implement search-as-you-type functionality.- Parameters:
path
- The field to be searched.query
- The string to search for.queries
- More strings to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- autocomplete operator
-
autocomplete
Returns aSearchOperator
that may be used to implement search-as-you-type functionality.- Parameters:
path
- The field to be searched.queries
- The non-empty strings to search for.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- autocomplete operator
-
numberRange
Returns a base for aSearchOperator
that tests if the BSON32-bit integer
/64-bit integer
/Double
values of the specified fields are within an interval.- Parameters:
path
- The field to be searched.paths
- More fields to be searched.- Returns:
- A base for a
NumberRangeSearchOperator
. - MongoDB Atlas documentation
- range operator
-
numberRange
Returns a base for aSearchOperator
that tests if the BSON32-bit integer
/64-bit integer
/Double
values of the specified fields are within an interval.- Parameters:
paths
- The non-empty fields to be searched.- Returns:
- A base for a
NumberRangeSearchOperator
. - MongoDB Atlas documentation
- range operator
-
dateRange
Returns a base for aSearchOperator
that tests if the BSONDate
values of the specified fields are within an interval.- Parameters:
path
- The field to be searched.paths
- More fields to be searched.- Returns:
- A base for a
DateRangeSearchOperator
. - MongoDB Atlas documentation
- range operator
-
dateRange
Returns a base for aSearchOperator
that tests if the BSONDate
values of the specified fields are within an interval.- Parameters:
paths
- The non-empty fields to be searched.- Returns:
- A base for a
DateRangeSearchOperator
. - MongoDB Atlas documentation
- range operator
-
near
static NumberNearSearchOperator near(Number origin, Number pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.- Parameters:
origin
- The origin from which the proximity of the results is measured. The relevance score is 1 if the values of the fields areorigin
.pivot
- The distance from theorigin
at which the relevance score drops in half.path
- The field to be searched.paths
- More fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- near operator
-
near
static NumberNearSearchOperator near(Number origin, Number pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.- Parameters:
origin
- The origin from which the proximity of the results is measured. The relevance score is 1 if the values of the fields areorigin
.pivot
- The distance from theorigin
at which the relevance score drops in half.paths
- The non-empty fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- near operator
-
near
static DateNearSearchOperator near(Instant origin, Duration pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.- Parameters:
origin
- The origin from which the proximity of the results is measured. The relevance score is 1 if the values of the fields areorigin
.pivot
- The distance from theorigin
at which the relevance score drops in half. Data is extracted viaDuration.toMillis()
.path
- The field to be searched.paths
- More fields to be searched.- Returns:
- The requested
SearchOperator
. - See Also:
- MongoDB Atlas documentation
- near operator
-
near
static DateNearSearchOperator near(Instant origin, Duration pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.- Parameters:
origin
- The origin from which the proximity of the results is measured. The relevance score is 1 if the values of the fields areorigin
.pivot
- The distance from theorigin
at which the relevance score drops in half. Data is extracted viaDuration.toMillis()
.paths
- The non-empty fields to be searched.- Returns:
- The requested
SearchOperator
. - See Also:
- MongoDB Atlas documentation
- near operator
-
near
static GeoNearSearchOperator near(Point origin, Number pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.- Parameters:
origin
- The origin from which the proximity of the results is measured. The relevance score is 1 if the values of the fields areorigin
.pivot
- The distance in meters from theorigin
at which the relevance score drops in half.path
- The field to be searched.paths
- More fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- near operator
-
near
static GeoNearSearchOperator near(Point origin, Number pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperator
that allows finding results that are near the specifiedorigin
.- Parameters:
origin
- The origin from which the proximity of the results is measured. The relevance score is 1 if the values of the fields areorigin
.pivot
- The distance in meters from theorigin
at which the relevance score drops in half.paths
- The non-empty fields to be searched.- Returns:
- The requested
SearchOperator
. - MongoDB Atlas documentation
- near operator
-
of
Creates aSearchOperator
from aBson
in situations when there is no builder method that better satisfies your needs. This method cannot be used to validate the syntax.Example
The following code creates two functionally equivalentSearchOperator
s, though they may not be equal.SearchOperator operator1 = SearchOperator.exists( SearchPath.fieldPath("fieldName")); SearchOperator operator2 = SearchOperator.of(new Document("exists", new Document("path", SearchPath.fieldPath("fieldName").toValue())));
- Parameters:
operator
- ABson
representing the requiredSearchOperator
.- Returns:
- The requested
SearchOperator
.
-