Comparable filtering
All attribute data types in evitaDB have mutually comparable values - it is always possible to unambiguously tell whether two values are the same, one is smaller than the other, or vice versa. This fact underlies the basic set of filtering constraints that you will commonly use when building queries.
In the context of the limitations described in this chapter, you might be interested in the general rules for handling
data types and arrays described in the query language basics.
When you compare two
data types, the strings are compared alphabetically from the beginning of the string. For example, Walther is greater
than Adam, but Jasmine is not greater than Joanna. The correct is used to compare the localized attribute string, so that the order is consistent with the national customs of
the language.
When you compare two Range data types, the larger one is the one whose left
boundary is greater than the left boundary of the other value. If both left boundaries are equal, the greater is the
one with the greater right boundary.
The data type is compared as
a numeric value, where the true is 1, and false is 0.
Attribute equals
- argument:string!
- the name of the entity attribute whose value will be compared to the value in the second argument
- argument:comparable!
- the arbitrary value that will be compared to entity attribute for equality
The attributeEquals compares filterable or unique entity attribute
for strict equality with the passed value.
Returns exactly one product with code equal to apple-iphone-13-pro-3.
Attribute greater than
- argument:string!
- the name of the entity attribute whose value will be compared to the value in the second argument
- argument:comparable!
- the arbitrary value that will be compared to entity attribute to be greater than the attribute of the examined entity
The attributeGreaterThan compares the filterable or unique entity attribute
with the value in the second argument and is satisfied only if the entity attribute is greater than the value.
Returns exactly several products with battery-life greater than 40 hours.
Attribute greater than, equals
- argument:string!
- the name of the entity attribute whose value will be compared to the value in the second argument
- argument:comparable!
- the arbitrary value that will be compared to entity attribute to be greater than or equal to the attribute of the examined entity
The attributeGreaterThanEquals compares the filterable or unique entity attribute
with the value in the second argument and is satisfied only if the entity attribute is greater than or equal to
the value.
Returns exactly several products with battery-life greater than or equal to 40 hours.
Attribute less than
- argument:string!
- the name of the entity attribute whose value will be compared to the value in the second argument
- argument:comparable!
- the arbitrary value that will be compared to entity attribute to be less than the attribute of the examined entity
The attributeLessThan compares the filterable or unique entity attribute
with the value in the second argument and is satisfied only if the entity attribute is less than the value.
Returns exactly several products with battery-capacity less than 125 mWH.
Attribute less than, equals
- argument:string!
- the name of the entity attribute whose value will be compared to the value in the second argument
- argument:comparable!
- the arbitrary value that will be compared to entity attribute to be less than or equal to the attribute of the examined entity
The attributeLessThanEquals compares the filterable or unique entity attribute
with the value in the second argument and is satisfied only if the entity attribute is less than or equal to the value.
Returns exactly several products with battery-capacity less than or equal to 125 mWH.
Attribute between
- argument:string!
- the name of the entity attribute whose value will be compared to the value in the second argument
- argument:comparable!
- the arbitrary value that will be compared to entity attribute to be greater than or equal to the attribute of the examined entity
- argument:comparable!
- the arbitrary value that will be compared to entity attribute to be less than or equal to the attribute of the examined entity
The attributeBetween compares the filterable or unique entity attribute
and is satisfied only if the entity attribute is less than or equal to the first argument and at the same time greater
than or equal to the second argument of the constraint.
Returns exactly several products with battery-capacity between 125 and 160 mWH.
Attribute in set
- argument:string!
- the name of the entity attribute whose value will be compared to the value in the second argument
- argument:comparable+
- one or more values that will be compared to entity attribute for equality
The attributeInSet compares filterable or unique entity attribute
for strict equality with any of the passed values.
Returns exactly three product with code matching one of the arguments. Last of the products was not found
in the database and is missing in the result.
Attribute is
- argument:string!
- the name of the entity attribute whose value will be checked for (non) existence
The attributeIs can be used to test for the existence of an entity
attribute of a given name.
Returns hundreds of products with the catalogNumber attribute set.
When you try to list products without such attribute:
... you will get a single one: