Reputation: 211
I am passing in a search filter with a category that has a space in it. It returns the correct result if there is no space.
So, if Person2
is passed as Person 2
below then it gives the wrong result:
string filter =
String.Format("\"category <> 'Person' AND category <> 'Person2', subject: testsubject\"");
List<QueryOption> options = new List<QueryOption>
{
new QueryOption("$search", filter)
};
var messages = graphClient.Me
.MailFolders
.Inbox
.Messages
.Request(options)
.Select("id, Categories, Subject")
.Top(500)
.GetAsync()
.Result;
Upvotes: 1
Views: 685
Reputation: 33094
The $search
query parameter using Keyword Query Language (KQL). According to the documentation, phrases need to be double-quoted:
Free text KQL queries are case-insensitive but the operators must be in uppercase. You can construct KQL queries by using one or more of the following as free-text expressions:
A word (includes one or more characters without spaces or punctuation)
A phrase (includes two or more words together, separated by spaces; however, the words must be enclosed in double quotation marks)
Try enclosing your category strings in double-quotes:
string filter = "\"category <> \\\"Person\\\" AND category <> \\\"Person 2\\\", subject: testsubject\""
Note that in order to send the quote through the API it needs to be escaped (\"
). In order to have C# include the escaped sequence in the string, the escape character must ALSO be escaped (\\
+ \"
). This is why you end up with the odd-looking triple slash (\\\"
).
Upvotes: 1