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 an Index greater than 11.

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content/IT/Document_Library?$filter=Index gt 11

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

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content/IT/Document_Library?$filter=substringof('Lorem', Description) eq true

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

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content/IT/Document_Library?$filter=startswith(Name, 'Document') eq true

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

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content/IT/Document_Library?$filter=endswith(Name, 'Library') eq true
  

Filtering by Date

Following example returns the documents that were uploaded after the given date.

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content/IT/Document_Library?$filter=CreationDate gt datetime'2019-03-26T03: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.

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content/IT/Document_Library?$filter=ContentType eq 'Folder'

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
https://dev.demo.sensenet.com/OData.svc/Root/Content/IT/Document_Library?$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.