OrderBy
Describes the OrderBy parameter, part of the GraphQL API used for the Optimizely querying service, when retrieving content in Optimizely solutions.
The orderBy
parameter enables the ordering (sorting) of the result list. You can order by:
- Relevance – Scores with
_ranking
usingRELEVANCE
, which uses BM25 for best matching, and always sorted in descending order (most relevant top). If you only sort byRELEVANCE
and the scores are the same, then the index order is used as a secondary sort. - Boost Only – Scores with
_ranking
usingBOOST_ONLY
. Sort by only using the query clauses that have aboost
, and other clauses will only match but not affect the scores. This is useful to take full control over the ranking using only boosts. Non-boosted clauses will be ordered by index order, but it is possible to override this with a secondary (and more) sorting criteria like lexographical sorting of a field in ascending direction. - Index order – Sort by index order using
DOC
(the order in which theitems
are synchronized with_ranking
. Recommended in combination withcursor
. - Field values – Sorted in DESC (descending) or ASC (ascending) order.
The orderBy
can have one or more sorting criteria. If there is a tie-breaker, the next sorting criteria is used, and so on. If there are null
values, these are ranked after the non-null values.
If you have multi-valued (list) fields, then Content Graph sorts by the highest value in the list when in DESC order and by the lowest value in the list when in ASC order. For string values, the lexicographic order determines the highest and lowest value, such as B
is a higher value than A
.
Examples
To sort by relevance, and when the scores are the same, then by a field called created
in descending order (newest in top):
orderBy: {
_ranking: RELEVANCE
created: DESC
}
You can order nested fields like this:
{
BiographyPage(
orderBy: {
_ranking: RELEVANCE
ContentLink: {
GuidValue: ASC
}
}) {
items {
ContentLink {
GuidValue
}
}
}
}
As explained above, when you have a field like MetaKeywords
that is multi-valued (list of strings), this query sorts the items
by the lowest value of the field in each item because the sort direction is ASC.
{
BiographyPage(
orderBy: {
MetaKeywords: ASC
}) {
items {
MetaKeywords
}
}
}
Updated about 1 month ago