V1 (deprecated)
4 min
The v1 APIs are now deprecated! If you are building a new implementation, we strongly recommend using API version 2 by going through V2 Overview
Depending on what details you want Klevu Search servers to return in response, you can use one of the following API methods to search in your index.
- For the “search as you type” sort of interface where you need query suggestions, matching categories, CMS pages and product suggestions, please use the “Search As You Type” method.
- For the search results landing page, if you only need a list of IDs of records relevant to your query, use the ID Search method.
- In addition to record IDs, if you want Klevu Search to return other details such as name, description, price, etc., use the Record Search method.
Both the ID Search and the Record Search methods have parameters that allow you to fetch filters/facets as well.
Search As You Type
Search as you type
Use this API endpoint to build a search as you type solution. It produces query suggestions, category suggestions, CMS page suggestions and products matching the customer query.
GET
https://<cloudSearchURL>/cloud-search/n-search/search
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://eucs15.ksearchnet.com/cloud-search/n-search/search?ticket=klevu-156925593843210765&term=r&sv=20.0.0&autoComplete=false&autoCompleteFilters=category:cms&noOfResults=2&showOutOfStockProducts=false&responseType=json',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Record Search
Record search
Use this API method if you want not only the record IDs but also other details associated with the matching records. The method allows you to retrieve facets and autosuggestions as well.
GET
https://<cloudSearchURL>/cloud-search/n-search/search
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://eucs15.ksearchnet.com/cloud-search/n-search/search?ticket=klevu-156925593843210765&term=a&sv=20.0.0&paginationStartsFrom=0&noOfResults=2&enablePartialSearch=false&category=KLEVU_PRODUCT&enableFilters=false&enableMultiSelectFilters=false&showOutOfStockProducts=true&responseType=json',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
ID search
ID search
Use this API method if you require only the IDs of the records matching your query. The method also allows you to retrieve facets associated with the search results.
GET
https://<cloudSearchURL>/cloud-search/n-search/idsearch
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://eucs15.ksearchnet.com/cloud-search/n-search/idsearch?ticket=klevu-156925593843210765&term=r&sv=20.0.0&paginationStartsFrom=0&noOfResults=2&enablePartialSearch=false&category=KLEVU_PRODUCT&enableFilters=false&enableMultiSelectFilters=false&showOutOfStockProducts=false&responseType=json',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;