ContentOnTarget provide a JSON over HTTP API to search for documents.

Detail Pages

There are three detail pages available:

Interface

The API is available with this URL path:

/api/2.2/[user]/[core]/[apiHash_Core]/search/

Possible Query Parameters

The API provides following parameter possibilities:

parameterexampledescription
q
/api/2.2/[user]/[core]/[apiHash_Core]/search/?q=search query

Search Parameter according to the Query Syntax

offset
/api/2.2/[user]/[core]/[apiHash_Core]/search/?q=search query&offset=10

specifies the position from which possible search results should be provided

minimal value: 0

length
/api/2.2/[user]/[core]/[apiHash_Core]/search/?q=search query&offset=10&length=20

specified the number of documents which have to be provided at maximum

supported range: 0-100

fields
/api/2.2/[user]/[core]/[apiHash_Core]/search/?q=search query&fields=["uri","testField1","testField2"]

specifies the fields of interest in addition to the score field (which specifies the relevancy of the search result).

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

  • uri
  • score

Additionally to these standard parameters, the system also supports faceting, filtering and sorting

parameterexampledescription
facets
/api/2.2/[user]/[core]/[apiHash_Core]/search/?q=search query&facets=[{"field":"price"}]
Enables facet calculating. More details can be found on Faceted Query.
filter
/api/2.2/[user]/[core]/[apiHash_Core]/search/?q=search query&filter=[{"field":"brand","value":"siemens}]
/api/2.2/[user]/[core]/[apiHash_Core]/search/?q=search query&filter={"type"="OR","fields":[{"field":"brand","value":"siemens}]}
Filters the search results. More details can be found on Filtered Query.
sort
/api/2.2/[user]/[core]/[apiHash_Core]/search/?q=search query&sort={"field":"ASC", "field2":"DESC"}
Sorts the search result. More details can be found on Sorted Query.
group
/api/2.2/[user]/[core]/[apiHash_Core]/search/?q=search query&group=field2
Provides a grouped search result: More details can be found on Grouped Query.

 

Response

On success, the response header is of type 200, the body contains the JSON response with the productNumber and the title.

Example:

{
"queryTime":12,
"searchResults": {
  "totalResults": 50,
  "results": [
	{"productNumber":"123456","title":"Title of the product", "score","1.557"},...
	]
  },
"alternativeSearchResults": {
  "query":"alternative search query",
  "totalResults": 50,
  "results": [
	{"productNumber":"123456","title":"Title of the product", "score","1.557"},...
	]
  },
"searchSuggestions": {
  [{"suggestion":"Titel of the product", "frequency":15},...
  ]
 }
}
parameterdescription
query timethe time needed to execute the search in milliseconds
searchResultssearch results, consisting of a list of data objects
alternativeSearchResults (opt)

in case that the search query was misspelled or there are less than 5 results, an alternative search might be applied. This happens if a similar query can be identified that would return more results. Thus the system provides the possibility to display most relevant search results even in case of misspellings.

searchSuggestions (opt)

Although a query provides a set of related documents, there might be similar, better queries. These alternative search queries are provided as suggestions including the number of documents to provide the user the possibility to improve the search. This could also be used in a "Did you mean" function.

Attention: if alternativeSearchResults is present, the most relevant searchSuggestion is already used.

PHP API Client

The PHP API client provides full support for the fulltext search

<?php
include_once("ContentOnTarget-PHP-API-Client.php");
$config = com\repalogic\ContentOnTarget\Client\Configuration::getConfig("https://api.shopontarget.com/", "userName", "userApiHash", "coreName", "coreApiHash");

$searchApi= new com\repalogic\ContentOnTarget\Client\SearchApi($config);

//specify a root filter (supporting complex boolean filtering)
$rootFilter = new com\repalogic\ContentOnTarget\Client\RootFilterSetting();
 
//specify a first level filter for manufacturers
$firstLevelFilter = new com\repalogic\ContentOnTarget\Client\FirstLevelFilterSetting();
$firstLevelFilter->setTag("manufacturer");
$filterFieldSetting = new com\repalogic\ContentOnTarget\Client\FilterFieldSetting();
$filterFieldSetting->setField("manufacturer");
$filterFieldSetting->setValue("Bosch");
$firstLevelFilter->addField($filterFieldSetting);
$rootFilter->addSubFilter($firstLevelFilter);
 
//specify a facet calculation
$facetSetting = new com\repalogic\ContentOnTarget\Client\FacetSetting();
$facetField = new com\repalogic\ContentOnTarget\Client\FacetFieldSetting();
$facetField->setField("manufacturer");
$facetField->setExcludeTag("manufacturer");
$facetSetting->addFacet($facetField);
$facetField2 = new com\repalogic\ContentOnTarget\Client\FacetFieldSetting();
$facetField2->setField("price");
$facetSetting->addFacet($facetField2);
$searchResults = $searchApi->search("search query",0,20,$rootFilter,$facetSetting);
var_dump($searchResults);
var_dump($searchResults->getFacetResult()->getFacets("manufacturer"));
var_dump($searchResults->getFacetResult()->getFacets("price"));
?>