In addition to other OData query parameters, Microsoft Graph supports the $search query parameter to restrict the results of a request to match a search criterion.
The support for the $search query parameter varies by entity, with some, such as Azure AD resources that derive from directoryObject, supporting $search only in advanced queries.
Note
The $search query parameter is currently not available in Azure AD B2C tenants.
Using $search on message collections
You can search messages based on a value in specific message properties. The results of the search are sorted by the date and time that the message was sent. A $search request returns up to 1000 results.
If you do a search on messages and specify only a value without specific message properties, the search is carried out on the default search properties of from, subject, and body.
The following example returns all messages in the signed-in user's Inbox that contains "pizza" in any of the three default search properties:
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestConfiguration = new MessagesRequestBuilderGetRequestConfiguration();
$queryParameters = new MessagesRequestBuilderGetQueryParameters();
$queryParameters->search = "\"pizza\"";
$requestConfiguration->queryParameters = $queryParameters;
$requestResult = $graphServiceClient->me()->messages()->get($requestConfiguration);
GET https://graph.microsoft.com/v1.0/groups/?$filter=mailEnabled eq true&$search="displayName:OneVideo"
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var queryOptions = new List<QueryOption>()
{
new QueryOption("$search", "\"displayName:OneVideo\"")
};
var groups = await graphClient.Groups
.Request( queryOptions )
.Filter("mailEnabled eq true")
.GetAsync();
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestConfiguration = new GroupsRequestBuilderGetRequestConfiguration();
$queryParameters = new GroupsRequestBuilderGetQueryParameters();
$queryParameters->filter = "mailEnabled eq true";
$queryParameters->search = "\"displayName:OneVideo\"";
$requestConfiguration->queryParameters = $queryParameters;
$requestResult = $graphServiceClient->groups()->get($requestConfiguration);
This looks for all mail-enabled groups with display names that look like "OneVideo".
The results are restricted based on a logical conjunction (an "AND") of the $filter and the entire query in the $search.
Any number of clauses is supported. Parentheses for precedence is also supported.
The syntax for each clause is: "<property>:<text to search>".
The property name must be specified in the clause. Any property that can be used in $filter can also be used inside $search. Depending on the property, the search behavior is either "search" or "startsWith" if search is not supported on the property.
The whole clause must be declared inside double quotes. If it contains double quotes or backslash, it should be escaped with a backslash. All the other special characters must be URL encoded.
Logical AND and OR operators must be put outside double quotes and they must be in upper case.
Both the string inputs you provide in $search, as well as the searchable properties, are split up into parts by spaces, different casing, and character types (numbers and special characters).