Issue
- Blueprints offer static filtering by field values, but a dynamic approach is needed where search fields enable filtering based on user-provided values for specific structure fields, Is possible to provide custom parameters to Search Blueprints?
- How can I create a search experience that allows filtering content from a specific structure based on the values of its fields, using a dedicated search input for each field?
Environment
- Quarterly Releases 2024.Q3+
Resolution
Dynamic filtering by structure fields can be achieved using Blueprints and the Search headless API:
-
Create the Blueprint:
- Add a parameter in the Blueprint configuration, prefixed with
search.experiences.*
(e.g.,search.experiences.fieldName
). This parameter will hold the value entered by the user in the search input. - In the Query Builder, under "Paste Any Elasticsearch Query" or "JSON element", insert
${search.experiences.fieldName}
in the code as a variable.- This integrates the parameter's value into the search query.
- Adjust "Query Settings" as needed to refine the search behavior.
- Test the Blueprint by setting the variable directly within the Blueprint preview.
- Configure and copy the External Reference Code (ERC) for API usage.
- Add a parameter in the Blueprint configuration, prefixed with
-
Access the Search Headless API:
- Enable the Release Feature Flag
LPS-179669
. - Use the
postSearchPage
endpoint of the Search headless API (ensure the feature flag is enabled). This endpoint allows executing searches based on Blueprints. - Include the parameter
nestedFields=embedded
to retrieve embedded objects (content). This ensures that the structure's fields are included in the search results. - In the request body, provide a JSON structure containing the variable with the value to filter by (e.g.,
{"fieldName": "your_value"}
). ReplacefieldName
with the actual name you used in the Blueprint configuration andyour_value
with the desired filter value. - The API response will return search results filtered based on your provided parameter.
- Enable the Release Feature Flag
Alternative Approaches:
-
Headless Delivery API for Web Content Filtering: Explore the headless APIs specifically designed for filtering web content by structure fields, like headless delivery API.
-
Nested Custom Filters: Consider using nested Custom Filters for a more integrated approach to filtering within the search interface.
-
Custom Facets: Utilize Custom Facets to provide users with interactive filtering options based on structure field values.