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 

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 44,311 Reputation points Microsoft Vendor
    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.