Modify Search Query
IMPORTANT : The methods within this article are being replaced! Please review the following updated guides for efficient customization:



To modify a search, the outgoing query to the indexed catalog is intercepted and any of the available Klevu API parameters are available to be inserted, or adjusted as needed.
There are two steps:
- Reference the API to understand what parameters are available to meet the objective
- Attach the override to the appropriate outgoing query (or queries)

Please see Custom Overrides for the prerequisite details on preparing for Klevu JS overriding.
Any of the Klevu API paramters are available to be applied as needed or otherwise to override any default values.
For example, the following example snippet modifies the outgoing productList API Query by assigning the value of "20" as the number of filter options to return.
The object path notation corresponds to that used in the outgoing JSON API query
See : Klevu API documentation on Retrieving Filters for more details and options

Please see Custom Overrides for details on preparing for Klevu query overriding.
The query parameters are accessible by attaching to the query request.control within a previously established custom event listener.

Now the query override can be applied
Any of the Klevu API parameters are available to be applied as needed or otherwise override any default values.
Landing page search query override to change the max filter options to retrieve for display:
Note that the action in the above example requires definition within the corresponding scope of the override.
Scope | Description |
---|---|
quick | QuickSearch module |
landing | SRLP module |
catnav | Category module |
See an example below for establishing a common function that can be used to apply shared query modifications across multiple scope.

Often query modifications are intended to be applied to any search query. For this reason a common function can be created in which to apply the override. This is a useful strategy to apply override parameters to every query across quick, landing, and catnav scope.
Please see Custom Overrides for details on preparing for Klevu query overriding.
The query parameters are accessible by attaching to the query request.control within a previously established custom event listener.
In this example we are passing the arguments to a common function object reference as myCommonQueryOverride
Now, we will define the new common function myCommonQueryOverride that is called from the custom event listener in the previous step.
This function will loop through all outgoing queries and apply the override.
Note the use of a dynamic query.id used in the loop
Any of the Klevu API parameters are available to be applied as needed or otherwise override any default values.
Landing page and Quick search query common function override to change the Currency used for pricing.




. . . . . . . . . . . .






.