microsoft-search / pnp-modern-search

Home of PnP Modern Search solutions, helping you move from classic to modern SharePoint and beyond
https://microsoft-search.github.io/pnp-modern-search
Other
387 stars 340 forks source link

Issue with Filtering Search Results by Domain in PnP Modern Search Web Part #4043

Closed Fady-Mikhael closed 2 weeks ago

Fady-Mikhael commented 2 weeks ago

Hello, I am working on a project using the PnP Modern Search Web Part with Microsoft Graph to query user information. My goal is to filter the search results to only show users with email addresses from a specific domain (e.g., @mycompany.com). I am using version 4.8.0 of the Web Part.

Problem: Despite applying a filter in the queryTemplate configuration of the PnP Search Web Part, the results still include users with email addresses from other domains (e.g., gmail.com, example.com), in addition to those from the specified domain. The queryTemplate contains the filter resource.userPrincipalName:*@mycompany.com, but results from other domains continue to appear.

Steps Taken: I tried removing the queryString to see if that would allow the userPrincipalName filter to be applied properly, but the issue persists. I manually filtered the results client-side using a conditional check (if statement) on userPrincipalName, and it works as expected. However, the goal is to have the filtering done via the query to avoid manual filtering post-query. I would prefer that the filtering happens at the query level through Microsoft Graph so that the results returned are already filtered by domain.

Environment: PnP Search Version: 4.8.0 API: Microsoft Graph (Beta)

Question: How can I ensure that the userPrincipalName filter is properly applied to exclude users from other domains? Could this be related to how the queryTemplate and queryString interact, or is it a bug with the Web Part? The manual filtering works, but I'd like to achieve the desired behavior directly through the query.

Thank you in advance for your assistance.

kasperbolarsen commented 2 weeks ago

As per the Q&A section in the documentation , https://microsoft-search.github.io/pnp-modern-search/QnA/ we recommend using SharePoint search where possible, and especially for People search as Microsoft search just isn't at par yet.

As per making sure the query only returns your specific domain, please see https://microsoft-search.github.io/pnp-modern-search/scenarios/Create-a-useful-People-Search/

On Sun, Oct 13, 2024, 15:31 Fady-Mikhael @.***> wrote:

Hello, I am working on a project using the PnP Modern Search Web Part with Microsoft Graph to query user information. My goal is to filter the search results to only show users with email addresses from a specific domain (e.g., @mycompany.com). I am using version 4.8.0 of the Web Part.

Problem: Despite applying a filter in the queryTemplate configuration of the PnP Search Web Part, the results still include users with email addresses from other domains (e.g., gmail.com, example.com), in addition to those from the specified domain. The queryTemplate contains the filter resource.userPrincipalName:*@ mycompany.com, but results from other domains continue to appear.

Steps Taken: I tried removing the queryString to see if that would allow the userPrincipalName filter to be applied properly, but the issue persists. I manually filtered the results client-side using a conditional check (if statement) on userPrincipalName, and it works as expected. However, the goal is to have the filtering done via the query to avoid manual filtering post-query. I would prefer that the filtering happens at the query level through Microsoft Graph so that the results returned are already filtered by domain.

— Reply to this email directly, view it on GitHub https://github.com/microsoft-search/pnp-modern-search/issues/4043, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE5DXITPTPVSNAOUA3RMV6DZ3JY4JAVCNFSM6AAAAABP3OHUJOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGU4DGOJWHE3TOOI . You are receiving this because you are subscribed to this thread.Message ID: @.***>