Configuring Query xC custom extension
The /configuration endpoint is used to add the customized configuration details in ZooKeeper node. There is a root node in ZooKeeper with the name /configuration, and inside the root node are child nodes where you can add the configuration.
The available nodes are:
- xC cextensions
- wc-component
- Colors, organized by language
- Filters to aid in natural language processing
- Units of measure, and
- Relevancy
To register xC customizations for pre- and post-processing of the actual search request to this child node, pass the configuration node the nodeName="xC" parameter as a request.
For example,
http://data_environment_hostname:30921/search/resources/api/v2/configuration?nodeName=xC&envType=auth
For
the full REST API specification, see the Query REST API. Example
Here is an example structure for an xC
configuration:
{
"preProcess": [
{
"storeId" : "1",
"endpoint": {
"query": "/productview/bySearchTerm/pre",
"xC": "/commerceue/extension/search/productview/preBySearchTerm",
"properties": [
{}
]
}
}
],
"postProcess": [
{
"storeId" : "1",
"endpoint": {
"query": "/productview/bySearchTerm/post",
"xC": "/commerceue/extension/search/productview/postBySearchTerm",
"properties": [
{
"fields": [
"name",
"shortDescription",
"UserData"
]
}
]
}
}
]
}
You can use Java, as in the following
CustomProductViewResource.java
file:
package com.hcl.commerce.search.rest;
/*
* Licensed Materials - Property of HCL Technologies Limited. (C) Copyright HCL Technologies Limited 1996, 2020.
*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/productview")
public class CustomProductViewResource {
/**
* This method is use to add the search criteria.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping(value = "/preBySearchTerm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity preFindProductsBySearchTerm(@RequestBody Map criteria) throws Exception {
ArrayList list = (ArrayList) criteria.get("content");
List filter = new ArrayList();
filter.add("manufacturer.text:\"manufacturerName\"");
Map filterMap = new HashMap();
filterMap.put("_wcf.search.internal.filterquery", filter);
list.add(filterMap);
criteria.put("content", list);
ResponseEntity result = new ResponseEntity(criteria, HttpStatus.OK);
return result;
}
/**
* This method is use to manipulate the data post from server.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@RequestMapping(value = "/postBySearchTerm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity postFindProductsBySearchTerm(@RequestBody Map response) throws Exception {
ArrayList list = (ArrayList) response.get("content");
for (Object obj : list) {
if (obj instanceof Map) {
Map m = (Map) obj;
m.put("name", "Custom :: " + m.get("name"));
}
}
ResponseEntity result = new ResponseEntity(response, HttpStatus.OK);
return result;
}
}