Hi @Hemant Kabra ,
Thank you for posting the thread on our forum.
In the context of using the Highlighted Content Webpart with KQL, it appears that dynamic parameters like {Page.FileLeafRef}
may not be supported directly within the KQL queries for filtering content. Instead, you might want to consider using other methods to achieve your goal.
Here is a workaround for your reference:
Using PnP Modern Search Webparts to achieve dynamic filtering based on the current page properties.
1. Install the PnP Modern Search Webparts
First, you need to install the PnP Modern Search Webparts to your SharePoint site collection. This will give you more flexible and powerful search functionality.
Steps to Install:
- Download the PnP Modern Search Webparts package: Go to the PnP Modern Search GitHub repository and download the latest release package.
- Upload the Package to the App Catalog:
- Go to your SharePoint Admin Center.
- Navigate to Apps -> App Catalog.
- Upload the downloaded package to the Apps for SharePoint library.
- Add the Webparts to your Site:
- Go to the site collection where you want to use the web parts.
- Click on the gear icon and select Add an app.
- Find the PnP Modern Search Webparts app and add it to your site.
2. Configure the PnP Modern Search Webparts
Now that you have the webparts installed, you can configure them to achieve dynamic filtering based on the page properties.
Steps to Configure:
- Edit the Page where you want to add the web part.
- Add the PnP Search Webpart to your page:
- Click on the
+
icon to add a web part. - Search for "PnP" and select the appropriate search webpart (e.g., “PnP Search Results”, “PnP Search Box”, etc.).
- Click on the
- Configure the Webpart:
- Click on the webpart to edit its properties.
- In the Search query settings, you can now build a dynamic query.
- Use the
{{Page.<PropertyName>}}
token to substitute page properties dynamically in your KQL query.- For example, assuming you want to filter by the page filename, you could use:
filename:"{{Page.FileLeafRef}}"
.
- For example, assuming you want to filter by the page filename, you could use:
- Link the Search Box (if needed):
- If you are using a
PnP Search Box
web part, configure it to pass the query to thePnP Search Results
web part.
- If you are using a
- Configure Results Layout:
- Customize how the search results should be displayed according to your needs.
- Save your Changes: Once you’ve configured the webparts, save your page.
3. Verify Dynamic Filtering
To ensure everything is working correctly:
- Navigate to a different page with different properties.
- Verify that the search results change dynamically based on the current page’s properties.
Additional Tips:
- Debugging: If your query is not returning the expected results, double-check the property names and ensure they match exactly with the metadata on the pages.
- Documentation & Samples: Refer to the PnP Modern Search documentation for more examples and detailed configuration options.
Using PnP Modern Search Webparts provides a flexible and robust solution that empowers you to build complex search experiences tailored to your needs with dynamic data.
I hope this information helps. Please do let us know if you have any further queries.
Kindly consider accepting the answer if the information provided is helpful. This can assist other community members in resolving similar issues.