Package com.mongodb.client.model.search
Interface SearchOperator
- All Superinterfaces:
org.bson.conversions.Bson
- All Known Subinterfaces:
AutocompleteSearchOperator,CompoundSearchOperator,DateNearSearchOperator,DateRangeSearchOperator,EqualsSearchOperator,ExistsSearchOperator,FilterCompoundSearchOperator,GeoNearSearchOperator,InSearchOperator,MoreLikeThisSearchOperator,MustCompoundSearchOperator,MustNotCompoundSearchOperator,NumberNearSearchOperator,NumberRangeSearchOperator,PhraseSearchOperator,QueryStringSearchOperator,RegexSearchOperator,ShouldCompoundSearchOperator,TextSearchOperator,WildcardSearchOperator
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 EqualsSearchOperatorequals(FieldSearchPath path, boolean value) Returns aSearchOperatorthat searches for documents where a field matches the specified value.static EqualsSearchOperatorequals(FieldSearchPath path, Number value) Returns aSearchOperatorthat searches for documents where a field matches the specified value.static EqualsSearchOperatorequals(FieldSearchPath path, String value) Returns aSearchOperatorthat searches for documents where a field matches the specified value.static EqualsSearchOperatorequals(FieldSearchPath path, Instant value) Returns aSearchOperatorthat searches for documents where a field matches the specified value.static EqualsSearchOperatorequals(FieldSearchPath path, UUID value) Returns aSearchOperatorthat searches for documents where a field matches the specified value.static EqualsSearchOperatorequals(FieldSearchPath path, org.bson.types.ObjectId value) Returns aSearchOperatorthat searches for documents where a field matches the specified value.static EqualsSearchOperatorequalsNull(FieldSearchPath path) Returns aSearchOperatorthat searches for documents where a field matches null.static ExistsSearchOperatorexists(FieldSearchPath path) Returns aSearchOperatorthat tests if thepathexists in a document.static InSearchOperatorin(FieldSearchPath path, boolean value, boolean... values) Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified valuesstatic <T> InSearchOperatorin(FieldSearchPath path, Iterable<? extends T> values) Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified valuesstatic InSearchOperatorin(FieldSearchPath path, Number value, Number... values) Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified valuesstatic InSearchOperatorin(FieldSearchPath path, String value, String... values) Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified valuesstatic InSearchOperatorin(FieldSearchPath path, Instant value, Instant... values) Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified valuesstatic InSearchOperatorin(FieldSearchPath path, UUID value, UUID... values) Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified valuesstatic InSearchOperatorin(FieldSearchPath path, org.bson.types.ObjectId value, org.bson.types.ObjectId... values) Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified valuesstatic MoreLikeThisSearchOperatormoreLikeThis(Iterable<org.bson.BsonDocument> likes) Returns aSearchOperatorthat returns documents similar to input documents.static MoreLikeThisSearchOperatormoreLikeThis(org.bson.BsonDocument like) Returns aSearchOperatorthat returns documents similar to input 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 SearchOperatorof(org.bson.conversions.Bson operator) Creates aSearchOperatorfrom aBsonin situations when there is no builder method that better satisfies your needs.static PhraseSearchOperatorphrase(SearchPath path, String query) Returns aSearchOperatorthat performs a search for documents containing an ordered sequence of terms.static PhraseSearchOperatorphrase(Iterable<? extends SearchPath> paths, Iterable<String> queries) Returns aSearchOperatorthat performs a search for documents containing an ordered sequence of terms.static QueryStringSearchOperatorqueryString(FieldSearchPath defaultPath, String query) Returns aSearchOperatorthat supports querying a combination of indexed fields and values.static RegexSearchOperatorregex(SearchPath path, String query) Returns aSearchOperatorthat performs a search using a regular expression.static RegexSearchOperatorregex(Iterable<? extends SearchPath> paths, Iterable<String> queries) Returns aSearchOperatorthat performs a search using a regular expression.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.static WildcardSearchOperatorwildcard(SearchPath path, String query) Returns aSearchOperatorthat performs a search using a special characters in the search string that can match any character.static WildcardSearchOperatorwildcard(Iterable<String> queries, Iterable<? extends SearchPath> paths) Returns aSearchOperatorthat performs a search using a special characters in the search string that can match any character.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:
-
InstantCodec
- 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:
-
InstantCodec
- 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
-
in
Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified values- Parameters:
path- The indexed field to be searched.value- The boolean value to search for.values- More fields to be searched.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- in operator
-
in
static InSearchOperator in(FieldSearchPath path, org.bson.types.ObjectId value, org.bson.types.ObjectId... values) Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified values- Parameters:
path- The indexed field to be searched.value- The objectId value to search for.values- More fields to be searched.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- in operator
-
in
Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified values- Parameters:
path- The indexed field to be searched.value- The number value to search for.values- More fields to be searched.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- in operator
-
in
Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified values- Parameters:
path- The indexed field to be searched.value- The instant date value to search for.values- More fields to be searched.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- in operator
-
in
Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified values- Parameters:
path- The indexed field to be searched.value- The uuid value to search for.values- More fields to be searched.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- in operator
-
in
Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified values- Parameters:
path- The indexed field to be searched.value- The string value to search for.values- More fields to be searched.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- in operator
-
in
Returns aSearchOperatorthat searches for documents where the value or array of values at a given path contains any of the specified values- Type Parameters:
T- the type of elements invalues.- Parameters:
path- The indexed field to be searched.values- The non-empty values to search for. Value can be either a single value or an array of values of only one of the supported BSON types and can't be a mix of different types.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- in operator
-
equals
Returns aSearchOperatorthat searches for documents where a field matches the specified value.- Parameters:
path- The indexed field to be searched.value- The boolean value to query for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- equals operator
-
equals
Returns aSearchOperatorthat searches for documents where a field matches the specified value.- Parameters:
path- The indexed field to be searched.value- The object id value to query for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- equals operator
-
equals
Returns aSearchOperatorthat searches for documents where a field matches the specified value.- Parameters:
path- The indexed field to be searched.value- The number value to query for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- equals operator
-
equals
Returns aSearchOperatorthat searches for documents where a field matches the specified value.- Parameters:
path- The indexed field to be searched.value- The instant date value to query for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- equals operator
-
equals
Returns aSearchOperatorthat searches for documents where a field matches the specified value.- Parameters:
path- The indexed field to be searched.value- The string value to query for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- equals operator
-
equals
Returns aSearchOperatorthat searches for documents where a field matches the specified value.- Parameters:
path- The indexed field to be searched.value- The uuid value to query for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- equals operator
-
equalsNull
Returns aSearchOperatorthat searches for documents where a field matches null.- Parameters:
path- The indexed field to be searched.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- equals operator
-
moreLikeThis
Returns aSearchOperatorthat returns documents similar to input document.- Parameters:
like- The BSON document that is used to extract representative terms to query for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- moreLikeThis operator
-
moreLikeThis
Returns aSearchOperatorthat returns documents similar to input documents.- Parameters:
likes- The BSON documents that are used to extract representative terms to query for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- moreLikeThis operator
-
queryString
Returns aSearchOperatorthat supports querying a combination of indexed fields and values.- Parameters:
defaultPath- The field to be searched by default.query- One or more indexed fields and values to search.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- queryString operator
-
phrase
Returns aSearchOperatorthat performs a search for documents containing an ordered sequence of terms.- Parameters:
path- The field to be searched.query- The string to search for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- phrase operator
-
phrase
Returns aSearchOperatorthat performs a search for documents containing an ordered sequence of terms.- Parameters:
paths- The non-empty fields to be searched.queries- The non-empty strings to search for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- phrase operator
-
wildcard
Returns aSearchOperatorthat performs a search using a special characters in the search string that can match any character.- Parameters:
path- The indexed field to be searched.query- The string to search for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- wildcard operator
-
wildcard
static WildcardSearchOperator wildcard(Iterable<String> queries, Iterable<? extends SearchPath> paths) Returns aSearchOperatorthat performs a search using a special characters in the search string that can match any character.- Parameters:
queries- The non-empty strings to search for.paths- The non-empty index fields to be searched.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- wildcard operator
-
regex
Returns aSearchOperatorthat performs a search using a regular expression.- Parameters:
path- The field to be searched.query- The string to search for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- regex operator
-
regex
Returns aSearchOperatorthat performs a search using a regular expression.- Parameters:
paths- The non-empty fields to be searched.queries- The non-empty strings to search for.- Returns:
- The requested
SearchOperator. - MongoDB Atlas documentation
- regex 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.
-