Creating an advanced searcher, getting files of a library

Charlie Martharper 205 Reputation points
2025-12-18T08:11:55.3333333+00:00

Hi!

So I am using PNP Modern search in a sharepoint site, but I want to search the files of one library with multiple folders and files. So when typing words in the search box, appear filters in the left with the choice column type.

So when nothing is type in the search box, I want nothing to appear in the search results.

And when something is searched, it appears the filters from the columns in that library.

How could I achieve that? I should create 3 or 4 more advanced searchers, one for main library, and then for specific folders in a library.

User's image

Microsoft 365 and Office | SharePoint | Development
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michelle-N 10,895 Reputation points Microsoft External Staff Moderator
    2025-12-18T12:51:52.36+00:00

    Hi @Charlie Martharper

    Thank you for posting your question in the Microsoft Q&A forum.

    Based on the information you provided, I understand that you are using PnP Modern Search to search within a specific library containing multiple folders. You have two main requirements:

    -When the search box is empty, no results should be displayed.

    -When a search is performed, results should appear along with filters (refiners) on the left based on your Choice columns.

    Here is how you can achieve this configuration based on my test environment:

    1. Hiding Results When the Search Box is Empty

    To ensure the Search Results web part shows nothing until a user types a keyword, you need to modify the Query Template. Please follow these steps:

    Go to your site > Click Edit > See all web parts > Add Document library.

    Then, in the Edit Search Results settings (for the web part you are configuring), change the Query template to the following format: {?{searchTerms} path:"https://yourtenant.sharepoint.com/sites/yoursite/yourlibrary"}

    User's image

    Then, to configure the connections, you must ensure that the Search Results web part is listening to the Search Box > Go to page Connections in the web part settings > Connect it to the PnP - Search Box as shown in the image below:User's image

    In my test environment, this configuration ensures that the results area remains blank initially. If you want to clear the search box and return to the empty state, you can simply click the "X" in the search box, and the results will disappear as shown below:User's image

    Displaying Filters (Refiners) from Columns

    To have your Choice columns appear as filters on the left after searching, you need to use the PnP - Search Filters web part. Please refer to the official documentation here:

    https://microsoft-search.github.io/pnp-modern-search/scenarios/page-with-filters/

    https://microsoft-search.github.io/pnp-modern-search/usage/search-filters/

    Let me know if you need help mapping those properties!


    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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.