John Kim
John Kim

Reputation: 1158

Microsoft Graph API search function doesn't work as expected

I am trying to do a basic search for displayName of my organization using the Microsoft Graph API.

The problem is, the search function doesn't work as expected. Based on my tests the search function doesn't actually do fuzzy searching properly, the logic is obviously based on startsWith and endsWith and not contains. For my needs this doesn't suffice because my organization's displayName contains both Korean name and English name. For example :

A user with displayName : 이선빈(Annie Lee)

https://graph.microsoft.com/v1.0/users/?$search="displayName:이선" returns the correct result. https://graph.microsoft.com/v1.0/users/?$search="displayName:Annie" returns no result. https://graph.microsoft.com/v1.0/users/?$search="displayName:Lee" returns no result https://graph.microsoft.com/v1.0/users/?$search="displayName:Lee)" returns the correct result

What was the point of updating the API with the search function if actual fuzzy searching wasn't supported? $filter using startsWith and endsWith operator has been supported since the beginning, but the reason why people wanted the $search function was to be able to actually query for displayName properly using a contains function. It seems Microsoft essentially "added" a search function when functionally it's basically the $filter with startsWith and endsWith query.

Am I missing something with the API? Is there a possible workaround in my case?

Upvotes: 0

Views: 3740

Answers (2)

Paphnuty
Paphnuty

Reputation: 1

The search implementation does not support "contains" logic. Instead, it uses a tokenization approach that works by extracting words from the property value and the search string using spaces, numbers, different casing, and symbols as shown in the following examples: Different casing: HelloWorld or helloWORLD => hello, world

try to lowercasing $search term 'Annie'=>'annie' or 'Lee'=>'lee'

Upvotes: 0

Luca Spolidoro MSFT
Luca Spolidoro MSFT

Reputation: 61

Thanks for the clarification in your last comment.
You can solve the issue by taking advantage of $search behavior for non-tokenized properties: it will default to startsWith operator.

Your final query should look like this:
/users?$search="displayName:<INPUT>" OR "givenName:<INPUT>" OR "surname:<INPUT>"

Let me know if this works for you.

Upvotes: 0

Related Questions