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 AutocompleteSearchOperatorautocomplete(FieldSearchPath path, Iterable<String> queries) Returns aSearchOperatorthat may be used to implement search-as-you-type functionality.static AutocompleteSearchOperatorautocomplete(FieldSearchPath path, String query, String... queries) Returns aSearchOperatorthat may be used to implement search-as-you-type functionality.static CompoundSearchOperatorBasecompound()Returns a base for aSearchOperatorthat may combine multipleSearchOperators.static DateRangeSearchOperatorBasedateRange(FieldSearchPath path, FieldSearchPath... paths) Returns a base for aSearchOperatorthat tests if the BSONDatevalues of the specified fields are within an interval.static DateRangeSearchOperatorBasedateRange(Iterable<? extends FieldSearchPath> paths) Returns a base for aSearchOperatorthat tests if the BSONDatevalues of the specified fields are within an interval.static ExistsSearchOperatorexists(FieldSearchPath path) Returns aSearchOperatorthat tests if thepathexists in a document.static GeoNearSearchOperatornear(Point origin, Number pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperatorthat allows finding results that are near the specifiedorigin.static GeoNearSearchOperatornear(Point origin, Number pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperatorthat allows finding results that are near the specifiedorigin.static NumberNearSearchOperatornear(Number origin, Number pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperatorthat allows finding results that are near the specifiedorigin.static NumberNearSearchOperatornear(Number origin, Number pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperatorthat allows finding results that are near the specifiedorigin.static DateNearSearchOperatornear(Instant origin, Duration pivot, FieldSearchPath path, FieldSearchPath... paths) Returns aSearchOperatorthat allows finding results that are near the specifiedorigin.static DateNearSearchOperatornear(Instant origin, Duration pivot, Iterable<? extends FieldSearchPath> paths) Returns aSearchOperatorthat allows finding results that are near the specifiedorigin.numberRange(FieldSearchPath path, FieldSearchPath... paths) Returns a base for aSearchOperatorthat tests if the BSON32-bit integer/64-bit integer/Doublevalues of the specified fields are within an interval.numberRange(Iterable<? extends FieldSearchPath> paths) Returns a base for aSearchOperatorthat tests if the BSON32-bit integer/64-bit integer/Doublevalues of the specified fields are within an interval.static SearchOperatorCreates aSearchOperatorfrom aBsonin situations when there is no builder method that better satisfies your needs.score(SearchScore modifier) Creates a newSearchOperatorwith the scoring modifier specified.static TextSearchOperatortext(SearchPath path, String query) Returns aSearchOperatorthat performs a full-text search.static TextSearchOperatortext(Iterable<? extends SearchPath> paths, Iterable<String> queries) Returns aSearchOperatorthat performs a full-text search.Methods inherited from interface org.bson.conversions.Bson
toBsonDocument, toBsonDocument
-
Method Details
-
score
Creates a newSearchOperatorwith the scoring modifier specified.- Parameters:
modifier- The scoring modifier.- Returns:
- A new
SearchOperator.
-
compound
Returns a base for aSearchOperatorthat may combine multipleSearchOperators. CombiningSearchOperators affects calculation of the relevance score.- Returns:
- A base for a
CompoundSearchOperator. - MongoDB Atlas documentation
- compound operator
-
exists
Returns aSearchOperatorthat tests if thepathexists in a document.- Parameters:
path- The path to test.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- exists operator
-
text
Returns aSearchOperatorthat 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 aSearchOperatorthat 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 aSearchOperatorthat 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 aSearchOperatorthat 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 aSearchOperatorthat tests if the BSON32-bit integer/64-bit integer/Doublevalues 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 aSearchOperatorthat tests if the BSON32-bit integer/64-bit integer/Doublevalues 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 aSearchOperatorthat tests if the BSONDatevalues 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 aSearchOperatorthat tests if the BSONDatevalues 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 aSearchOperatorthat 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 theoriginat 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 aSearchOperatorthat 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 theoriginat 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 aSearchOperatorthat 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 theoriginat 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 aSearchOperatorthat 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 theoriginat 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 aSearchOperatorthat 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 theoriginat 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 aSearchOperatorthat 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 theoriginat 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 aSearchOperatorfrom aBsonin 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 equivalentSearchOperators, 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- ABsonrepresenting the requiredSearchOperator.- Returns:
- The requested
SearchOperator.
-