Search and filtering
Search and filtering
You can use a variety of query parameters to search and filter items in the response from any collection including folders, documents, images, content types, users or any other content with built-in or custom content type.
Filtering
The $filter
option defines a subset of the entries from a specified collection. The filter expression can contain global functions and operations according to the OData standard.
Filtering by Field value
The following example returns the items that have a Price greater than 1 000 000.
GET https://example.com/OData.svc/Root/Content/Cars?$filter=Price gt 1000000
The following example returns true if the DisplayName
field (given as second param) contains the given string.
GET https://example.com/OData.svc/Root/Content/Cars?$filter=substringof('Supra', DisplayName) eq true
The following example returns true if the DisplayName
field starts with the given string.
GET https://example.com/OData.svc/Root/Content/Cars?$filter=startswith(DisplayName, 'Toyota') eq true
The following example returns true if the given DisplayName
field ends with the given string.
GET https://example.com/OData.svc/Root/Content/Cars?$filter=endswith(DisplayName, 'Octavia') eq true
Filtering by Date
The following example returns documents that have StartingDate
field greater value than the specified date.
GET https://example.com/OData.svc/Root/Content/Cars?$filter=StartingDate gt datetime'2020-01-12T03:55:00'
Filtering by an exact Type
Since sensenet supports content type inheritance there are two ways to filter items by their types.
The following example shows how to get items with an exact type skipping the contents with one of the inherited types.
GET https://example.com/OData.svc/Root/Content/Cars?metadata=no&$filter=ContentType eq 'Car'
Filtering by Type family
In most of the cases you will use the IsOf()
operation to filter by type family (by a content type and all of its inherited ones).
The response of the following example will return every content with the type Folder
or any inherited type.
GET https://example.com/OData.svc/Root/Content/Cars?$filter=isof('Folder')
Query option
There is a reserved custom query option: query
(without "$" prefix) that helps to get filtered collection of entities with Content Query. The scope of the query is the subtree with requested entity as a root.
Check the next big section of docs about querying in details HERE.