title | perex | date | author | proofreading | preferredLang |
---|---|---|---|---|---|
Constant ordering |
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.
|
17.1.2023 |
Ing. Jan Novotný |
needed |
evitaql |
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).
entityPrimaryKeyInFilter()
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.
Entities sorted by order of the filtered primary keys
The sample query returns exactly 4 products, which maintain the order of the filtered primary keys in the query that was issued.
Entities sorted by order of the filtered primary keys
Entities sorted by order of the filtered primary keys
Entities sorted by order of the filtered primary keys
entityPrimaryKeyExact(
argument:int+
)
- 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.
Entities sorted by the specified order of the primary keys
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.
Entities sorted by the specified order of the primary keys
Entities sorted by the specified order of the primary keys
Entities sorted by the specified order of the primary keys
attributeSetInFilter(
argument:string!
)
- argument:string!
- a mandatory name of the [attribute name](../../use/schema.md#attributes) 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.
Entities sorted by order code
attribute of the filtered entities
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.
Entities sorted by order code
attribute of the filtered entities
Entities sorted by order code
attribute of the filtered entities
Entities sorted by order code
attribute of the filtered entities
attributeSetExact(
argument:string!,
argument:comparable+
)
- argument:string!
- a mandatory name of the [attribute name](../../use/schema.md#attributes) that control the order of the query result
- argument:comparable+
- a mandatory set of attribute values whose data type matches [attribute data type](../../use/schema.md#attributes), 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.
Entities sorted by the specified order of the attribute code
values
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.
Entities sorted by the specified order of the attribute code
values
Entities sorted by the specified order of the attribute code
values
Entities sorted by the specified order of the attribute code
values