There are situations when the order of entities is specified outside evitaDB. The constant order constraints allow to
control the order of the selected entities by a caller logic.
The constant ordering constraints are particularly useful when you have a sorted set of unique attributes or directly
the entity primary keys provided by an external system that needs to be maintained in the evitaDB output (for example,
it represents a relevance of those entities from the full-text engine).
Exact entity primary key order used in filter
The constraint allows output entities to be sorted by primary key values in the exact order used to filter them.
The constraint requires the presence of exactly one entityPrimaryKeyInSet
constraint in the filter part of the query. It uses the specified array of entity primary keys to sort the result
returned by the query.
The sample query returns exactly 4 products, which maintain the order of the filtered primary keys in the query that
was issued.
Exact entity primary key order
argument:int+
a mandatory set of entity primary keys that control the order of the query result
The constraint allows output entities to be sorted by entity primary keys in the exact order specified in the 2nd through
Nth arguments of this constraint.
The sample query returns all products whose code starts with the string lenovo, but uses the order of the first three
entities in the output as specified by the order constraint entityPrimaryKeyExact. Because the query returns more
results than the order constraint has information for, the rest of the result set is sorted traditionally by
the entity primary key in ascending order. If there is another order constraint in the chain, it would be used to sort
the rest of the query result.
Exact entity attribute value order used in filter
argument:string!
a mandatory name of the attribute name that control the order of
the query result
This constraint allows output entities to be sorted by values of the specified attribute in the exact order in which
they were filtered. The constraint requires the presence of exactly one attribute-in-set
in the filter part of the query, referring to the attribute with the same name as used in the first argument of this
constraint. It uses the specified array of attribute values to sort the result returned by the query.
The sample query returns exactly 3 products, preserving the order of the entity's code attribute used in the filter
constraint of the query that was issued.
Exact entity attribute value order
argument:string!
a mandatory name of the attribute name that control the order of
the query result
argument:comparable+
a mandatory set of attribute values whose data type matches attribute data type,
which define the order of the query result
The constraint allows output entities to be sorted by attribute values in the exact order specified in the 2nd through
Nth arguments of this constraint.
The sample query returns all products whose code starts with the string lenovo, but uses the order of the first three
entities in the output as specified by the order constraint attributeSetExact. Because the query returns more
results than the order constraint has information for, the rest of the result set is sorted traditionally by
the entity primary key in ascending order. If there is another order constraint in the chain, it would be used to sort
the rest of the query result.