There are two different possibilities to provide query suggestions:

  • suggest relevant search terms
  • provide matching products while typing

ContentOnTarget supports both methods. A possible realization and layout for this feature might look as following:

Interface

The suggestions can be retrieved by using the suggest API. It is available at

/api/2.2/[userName]/[ccoreName]/[coreApiHash]/suggest/

Possible parameters:

nametyperequireddescription
qStringxthe query term for which a suggestion is wanted
termsBoolean-specifies whether term suggestions should be provided, default=true
documentsBoolean-specifies whether documents (ShopOnnTarget: products) suggestions should be provided, default=true
fieldsString-

JSON array of fiels that should be retrieved.

The requested fields have to match the CoreSchema specification. If no field is requested, following fields are provided by default:

  • uri
  • score
groupString-Provides a grouped suggestion result. The group parameter has to specify a field name which is single-valued and has group support enabled.

Response

The response provides terms and product suggestions. The provided frequency is currently always -1.

{
   "terms":    [
      {
         "suggestion": "suggestion 1",
         "frequency": "-1"
      },
      {
         "suggestion": "suggestion 2",
         "frequency": "-1"
      },
      ...
   ],
   "documents":    [
      {
         "productNumber": "productID_1925",
         "title": "product 1"
      },
            {
         "productNumber": "productID_1983",
         "title": "product 2"
      },
      ...
   ]
}


PHP API Client

The PHP API client provides full support for the search suggestions. You can use it either in an autosuggest context or in any other scenario that seems to be useful.

<?php
include_once("ContentOnTarget-PHP-API-Client.php");
$config = com\repalogic\ContentOnTarget\Client\Configuration::getConfig("https://api.shopontarget.com/", "userName", "userApiHash", "coreName", "coreApiHash");
$suggestApi = com\repalogic\ContentOnTarget\Client\SuggestApi($config);
 
//get term suggestions for 'sear'
$suggestResults = $suggestApi->suggest("sear",true,false);
 
//get product suggestions for 'sear'
$suggestResults = $suggestApi->suggest("sear",false,true);
 
//get term and product suggestions for 'sear' at once
$suggestResults = $suggestApi->suggest("sear",true,true);
?>