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.

Copy
GET https://example.com/OData.svc/Root/Content/Cars?$filter=Price gt 1000000
🛈 Special characters should be URL encoded

The following example returns true if the DisplayName field (given as second param) contains the given string.

Copy
GET https://example.com/OData.svc/Root/Content/Cars?$filter=substringof('Supra', DisplayName) eq true
🛈 Special characters should be URL encoded

The following example returns true if the DisplayName field starts with the given string.

Copy
GET https://example.com/OData.svc/Root/Content/Cars?$filter=startswith(DisplayName, 'Toyota') eq true
🛈 Special characters should be URL encoded

The following example returns true if the given DisplayName field ends with the given string.

Copy
GET https://example.com/OData.svc/Root/Content/Cars?$filter=endswith(DisplayName, 'Octavia') eq true
🛈 Special characters should be URL encoded
  

Filtering by Date

The following example returns documents that have StartingDate field greater value than the specified date.

Copy
GET https://example.com/OData.svc/Root/Content/Cars?$filter=StartingDate gt datetime'2020-01-12T03:55:00'
🛈 Special characters should be URL encoded

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.

Copy
GET https://example.com/OData.svc/Root/Content/Cars?metadata=no&$filter=ContentType eq 'Car'
🛈 Special characters should be URL encoded

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.

Copy
GET https://example.com/OData.svc/Root/Content/Cars?$filter=isof('Folder')
🛈 Special characters should be URL encoded

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.