Hound Query Language

Sort

Sort allows you to explicitly order results.

sort is constructed inside a JSON payload and passed as the POST body. sort is accepted by the Explore endpoint.

Overview

Sort is pretty much what it sounds like. As opposed to Factors, which generate results in a recommended order, Sort lets you explicitly order results and is used instead of Factors. Sort is an array of sort objects.

The order is important because each sort type after the first is used as a tie breaker for the previous sort type. There is a default sort of popularity for the explore endpoint, if none is supplied.

Below is an example of a popularity sort, followed by an alphabetical sort as a tie breaker for popularity:

{
"sort": [
{
"type": "popularity",
"order": "descending"
},
{
"type": "property",
"property": "name",
"order": "ascending"
}
]
}

Sort Fields

Field NameOptions (some require additional fields)
typepopularity, property, collectionOrder, likeOrder, followOrder, idsOrder, and random.
orderascending, descending

How it fits into the rest of the Hound Query Language

As stated at the top of the page, sort is accepted by the Explore endpoint. Below is a sample layout of the JSON as it would be sent to that endpoint, as the query parameter params.

Explore

When used in an Explore call, you would also utilize filters and components to filter the results, and to control what metadata you get back, respectively. This would be laid out like so:

{
"filters": FILTERS_OBJECT,
"sort": SORT_ARRAY,
"components": COMPONENTS_ARRAY
}

Popularity

popularity ranks results according to MediaHound's own rating system, but should reflect a sense of the content's popularity in the general public. Default order is descending.

{
"sort": [
{
"type": "popularity"
}
]
}

Property

The property type accepts an additional field called property which can accept one of two different values: name or releaseDate:

Sort by the content's name field. Default order is ascending.

{
"sort": [
{
"type": "property",
"property": "name"
}
]
}

Sort by the content's releaseDate field. Default order is descending.

{
"sort": [
{
"type": "property",
"property": "releaseDate"
}
]
}

IdsOrder

The idsOrder sort type takes a list of MHIDs in a property called ids which accepts an array of strings and returns values according to their presence in this list. It can be used to form something like an adhoc collection, since it doesn't require writes to the MediaHound API and you can order things arbitrarily. Elements in your results which are not described in the ids sort are placed at the end for both ascending and descending sort. Default order is ascending.

{
"sort": [
{
"type": "idsOrder",
"ids": ["mhmov-pulp-fiction", "mhmov-reservoir-dogs"]
}
]
}

Random

The random sort returns elements in a random, unpreserved order. This means it doesn't work well with paging since no guarantee is made about repeated elements between one page and the next. It is useful for cases when you don't intend to page and you want repeat viewings of the same request to appear fresh and different. Order is ignored for this type.

{
"sort": [
{
"type": "random"
}
]
}

Ascending and Descending

Specifies the directional order of elements which is contextual for the Sort Type.