The search API calls as described at the link here (i.e. https://docs.klevu.com/apis/), provide developers with a way to query our servers and obtain search results either in XML or JSON format. On this page, we provide tips and tricks to optimize API responses.
Using the appropriate API call
Unless you need product information other than the product IDs, where possible, we request you to use the idsearch API call. Since the call only returns IDs of the relevant products, it is much faster than the record search call.
By default, our search API call returns many fields. If you are not going to use all the fields in your UI, we recommend that you use the fl parameter to tell us which fields (comma separated) you want us to return (e.g. fl=id,name,url,image,price,salePrice).
It is the calculations around facet values that takes the most time. Unless you want us to produce facets, we strongly advise that you keep the enableFilters parameter to false. If you want our system to return facets anyway, we recommend keeping the number of values per facet to a low number (e.g. maxNoOfValuesInAFilter=10). If obtaining counts for each facet value is not needed, please let us know as we can introduce a certain parameter in the backend to speed up the calls.
Using a slider for Price Ranges
Set the fetchMinMaxPrice=true and it will return the min and the max price values relevant to the search results set.
Pagination and Sorting Calls
Instead of asking for many products at a time, we recommend that you set the noOfResults to a low value (e.g. 10 or 12 at the most) and then utilise the pagination functionality to fetch more products.
If you are going to need filters for your UI and you are going to utilise the pagination functionality, we suggest you set enableFilters=true only for the first set of results for every new query. For any subsequent calls (e.g. to obtain results for any other page or obtaining results with a different sorting order) you should set the enableFilters=false and utilise the filters information obtained in the first call.
Using the "lsqt" Parameter to Speed Up Execution
Please, add the parameter called lsqt in your query request. It stands for Last Searched Query Type. When you fire a query, our system tries various combinations of queries (e.g. WILDCARD_AND, FUZZY_AND, OR) to make sure you get at least one result. Whatever the method used by our system, Klevu returns it back in the response (see the typeOfQuery element in the response).
When you fire the first query (i.e. paginationStartsFrom=0), look at the value of the typeOfQuery element under the metaData section. For any subsequent query (e.g. to apply additional filters, or to obtain results for the subsequent pages (i.e. paginationStartsFrom > 0), or to obtain results using different sorting method), please pass this value as the value of the lsqt parameter. This will ensure the system does not try different queries but only the one provided in the lsqt parameter. It will speed up the execution.