SharePoint PNP Search Function

Olivia 0 Reputation points
2024-06-05T04:43:56.7766667+00:00

I need to set up a PNP search function to only search a specific site, only shows documents, and doesn't show any results when no criteria is entered. 

The below query works how I want it to search, however it shows results when I haven't entered in any criteria.

{searchTerms} IsDocument:1 -fileextension:aspx Path:"https://yourtenant.sharepoint.com/sites/yoursite*"

By just entering in:

{inputQueryText}

it only shows results when I have entered in a search criterion, however it doesn't allow me to restrict my results to 1 site and document type. 

Any help would be appreciated. Thanks 

Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 51,836 Reputation points Microsoft External Staff
    2024-06-05T08:56:18.22+00:00

    Try to use following search query.

    {?{searchTerms} IsDocument:1 -fileextension:aspx Path:"https://yourtenant.sharepoint.com/sites/yoursite*"}


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.