YannickRe / spfx-msgraph-peoplesearch

Show and search users from your organization with an SPFx web part, through Microsoft Graph.
40 stars 33 forks source link

Filter and Query #5

Closed sgtdonny closed 3 years ago

sgtdonny commented 3 years ago

Hello,

nice webpart by the way. Tried react directory but that not fits my use case cause there are shown guests and deactivated accounts. On graph the options are there but doesn't work porpertly.

The filter by it's own are working but not in combination. Also my query is not looking in the fields that i want to. I use the office field for product informations and want a search by much more fields.

Please can you tell me if my syntax is wrong.

Cheers Patrick 2020-11-17 14_18_29-Window

YannickRe commented 3 years ago

@sgtdonny Please read the $filter syntax on https://docs.microsoft.com/en-us/graph/query-parameters?context=graph%2Fapi%2F1.0&view=graph-rest-1.0#filter-parameter, it will help you understand better. In essence, you should combine filters by using and and not &

sgtdonny commented 3 years ago

Thanks Yannick,

get the filter and select. Looks like a compare to null for empty field doesn't work. tried on graph explorer. Looks like the search is only done against the displayname, isn't it?

Im looking for a way to search all field that i use on the select.

Thanks

YannickRe commented 3 years ago

As far as I know this is indeed not supported on Graph. Currently search is only done against the displayname, that's correct: https://github.com/YannickRe/spfx-msgraph-peoplesearch/blob/e614c8990ad3ecf47a4317ee8834b1cca5e61bea/src/services/SearchService/SearchService.ts#L60

More information on the $search parameter can be found at: https://docs.microsoft.com/en-us/graph/query-parameters?context=graph%2Fapi%2F1.0&view=graph-rest-1.0#using-search-on-directory-object-collections Full text search is only available on displayName and mail properties, for every other property you define it will do a startsWith search. If you need to search in all properties of $select, you'll need to modify above code to apply the search text on all select parameters and inject it in the search parameter. This is not something I plan to implement, but you could easily make this adjustment in the code for your own deployment.

sgtdonny commented 3 years ago

Thanks a lot. I get the fields working. "displayName:${this.searchParameter}" OR "jobTitle:${this.searchParameter}" OR "department:${this.searchParameter}" OR "officeLocation:${this.searchParameter}" OR "businessPhones:${this.searchParameter}"

Unfortunately it doesn't fit to my needs causing the starts with behavior. I have comma separated products in the office field.

YannickRe commented 3 years ago

Unfortunately that's the current limitation of the $search parameter in Microsoft Graph, and nothing I can change about that... I suggest you post your request to https://microsoftgraph.uservoice.com/ and get many votes to maybe get them to implement it.

sgtdonny commented 3 years ago

Yes. Thanks for your help.

TheMancs commented 1 year ago

Thanks a lot. I get the fields working. "displayName:${this.searchParameter}" OR "jobTitle:${this.searchParameter}" OR "department:${this.searchParameter}" OR "officeLocation:${this.searchParameter}" OR "businessPhones:${this.searchParameter}"

Unfortunately it doesn't fit to my needs causing the starts with behaviour. I have comma separated products in the office field.

@sgtdonny hi, I was just wondering if you were able to work around this issue? I'm currently stuck on the same issue where my query only does "stars with" searches when there are multiple query parameters.

I tried something like this: if (!isEmpty(this.searchParameter)) { const properties = ["displayname", "jobTitle", "mail", "department"]; let promises: PageCollection<ExtendedUser>; properties.forEach(property => promises += resultQuery.query({ $search:"${property}:${this.searchParameter}"}).get() ) return promises;

Which has no effect, still searching with "starts with". Best regards

YannickRe commented 1 year ago

@dlilo As mentioned before in this issue, full text search is only supported in for the mail and displayName properties. If you add properties that do not support this, they will fall back to startsWith behavior. There is nothing to change there, it's a limit of Microsoft Graph 🤷‍♂️