// matches all objects where 'age' field has value as 30 and
// 'name' field has value as John Doe
repository.find(and(eq("age", 30), eq("name", "John Doe")));
public final class ObjectFilters
extends java.lang.Object
A helper class to create all type of ObjectFilter
s.
Modifier and Type | Field and Description |
---|---|
static ObjectFilter |
ALL
A filter to select all elements.
|
Modifier and Type | Method and Description |
---|---|
static ObjectFilter |
and(ObjectFilter... filters)
Creates an and filter which performs a logical AND operation on two filters and selects
the objects that satisfy both filters.
|
static ObjectFilter |
elemMatch(java.lang.String field,
ObjectFilter filter)
Creates an element match filter that matches objects that contain an array
value with at least one element that matches the specified
filter . |
static ObjectFilter |
eq(java.lang.String field,
java.lang.Object value)
Creates an equality filter which matches objects where the value
of a field equals the specified value.
|
static ObjectFilter |
gt(java.lang.String field,
java.lang.Object value)
Creates a greater than filter which matches those objects where the value
of the field is greater than (i.e.
|
static ObjectFilter |
gte(java.lang.String field,
java.lang.Object value)
Creates a greater equal filter which matches those objects where the value
of the field is greater than or equals to (i.e.
|
static ObjectFilter |
in(java.lang.String field,
java.lang.Object... values)
Creates an in filter which matches the objects where
the value of a field equals any value in the specified array.
|
static ObjectFilter |
lt(java.lang.String field,
java.lang.Object value)
Creates a lesser than filter which matches those objects where the value
of the field is less than (i.e.
|
static ObjectFilter |
lte(java.lang.String field,
java.lang.Object value)
Creates a lesser equal filter which matches those objects where the value
of the field is lesser than or equals to (i.e.
|
static ObjectFilter |
not(ObjectFilter filter)
Creates a not filter which performs a logical NOT operation on a
filter and selects
the objects that do not satisfy the filter . |
static ObjectFilter |
or(ObjectFilter... filters)
Creates an or filter which performs a logical OR operation on two filters and selects
the objects that satisfy at least one of the filter.
|
static ObjectFilter |
regex(java.lang.String field,
java.lang.String value)
Creates a string filter which provides regular expression capabilities
for pattern matching strings in objects.
|
static ObjectFilter |
text(java.lang.String field,
java.lang.String value)
Creates a text filter which performs a text search on the content of the fields
indexed with a full-text index.
|
public static final ObjectFilter ALL
A filter to select all elements.
public static ObjectFilter and(ObjectFilter... filters)
Creates an and filter which performs a logical AND operation on two filters and selects the objects that satisfy both filters.
// matches all objects where 'age' field has value as 30 and
// 'name' field has value as John Doe
repository.find(and(eq("age", 30), eq("name", "John Doe")));
filters
- operand filterspublic static ObjectFilter or(ObjectFilter... filters)
Creates an or filter which performs a logical OR operation on two filters and selects the objects that satisfy at least one of the filter.
// matches all objects where 'age' field has value as 30 or
// 'name' field has value as John Doe
repository.find(or(eq("age", 30), eq("name", "John Doe")));
filters
- operand filterspublic static ObjectFilter not(ObjectFilter filter)
Creates a not filter which performs a logical NOT operation on a filter
and selects
the objects that do not satisfy the filter
. This also includes objects
that do not contain the value.
// matches all objects where 'age' field has value not equals to 30
repository.find(not(eq("age", 30)));
filter
- the filterpublic static ObjectFilter eq(java.lang.String field, java.lang.Object value)
Creates an equality filter which matches objects where the value of a field equals the specified value.
// matches all objects where 'age' field has value as 30
repository.find(eq("age", 30));
field
- the valuevalue
- the valuepublic static ObjectFilter gt(java.lang.String field, java.lang.Object value)
Creates a greater than filter which matches those objects where the value of the field is greater than (i.e. >) the specified value.
// matches all objects where 'age' field has value greater than 30
repository.find(gt("age", 30));
field
- the valuevalue
- the valuepublic static ObjectFilter gte(java.lang.String field, java.lang.Object value)
Creates a greater equal filter which matches those objects where the value of the field is greater than or equals to (i.e. >=) the specified value.
// matches all objects where 'age' field has value greater than or equal to 30
repository.find(gte("age", 30));
field
- the valuevalue
- the valuepublic static ObjectFilter lt(java.lang.String field, java.lang.Object value)
Creates a lesser than filter which matches those objects where the value of the field is less than (i.e. <) the specified value.
// matches all objects where 'age' field has value less than 30
repository.find(lt("age", 30));
field
- the valuevalue
- the valuepublic static ObjectFilter lte(java.lang.String field, java.lang.Object value)
Creates a lesser equal filter which matches those objects where the value of the field is lesser than or equals to (i.e. ⇐) the specified value.
// matches all objects where 'age' field has value lesser than or equal to 30
repository.find(lte("age", 30));
field
- the valuevalue
- the valuepublic static ObjectFilter text(java.lang.String field, java.lang.String value)
Creates a text filter which performs a text search on the content of the fields indexed with a full-text index.
// matches all objects where 'address' field has value 'roads'.
repository.find(text("address", "roads"));
field
- the valuevalue
- the text valueTextIndexingService
,
TextTokenizer
public static ObjectFilter regex(java.lang.String field, java.lang.String value)
Creates a string filter which provides regular expression capabilities for pattern matching strings in objects.
// matches all objects where 'name' value starts with 'jim' or 'joe'.
repository.find(regex("name", "^(jim|joe).*"));
field
- the valuevalue
- the regular expressionpublic static ObjectFilter in(java.lang.String field, java.lang.Object... values)
Creates an in filter which matches the objects where the value of a field equals any value in the specified array.
// matches all objects where 'age' field has value in [20, 30, 40]
repository.find(in("age", 20, 30, 40));
field
- the valuevalues
- the range valuespublic static ObjectFilter elemMatch(java.lang.String field, ObjectFilter filter)
Creates an element match filter that matches objects that contain an array
value with at least one element that matches the specified filter
.
// matches all objects which has an array field - 'color' and the array
// contains a value - 'red'.
repository.find(elemMatch("color", eq("$", "red"));
field
- the valuefilter
- the filter to satisfy