use of com.salesmanager.shop.store.model.search.AutoCompleteRequest in project shopizer by shopizer-ecommerce.
the class SearchController method autocomplete.
/**
* Retrieves a list of keywords for a given series of character typed by the end user
* This is used for auto complete on search input field
* @param json
* @param store
* @param language
* @param model
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = "/services/public/search/{store}/{language}/autocomplete.json", produces = "application/json;charset=UTF-8")
@ResponseBody
public String autocomplete(@RequestParam("q") String query, @PathVariable String store, @PathVariable final String language, Model model, HttpServletRequest request, HttpServletResponse response) {
MerchantStore merchantStore = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
if (merchantStore != null) {
if (!merchantStore.getCode().equals(store)) {
// reset for the current request
merchantStore = null;
}
}
try {
if (merchantStore == null) {
merchantStore = merchantStoreService.getByCode(store);
}
if (merchantStore == null) {
LOGGER.error("Merchant store is null for code " + store);
// TODO localized message
response.sendError(503, "Merchant store is null for code " + store);
return null;
}
AutoCompleteRequest req = new AutoCompleteRequest(store, language);
/**
* formatted toJSONString because of te specific field names required in the UI *
*/
SearchKeywords keywords = searchService.searchForKeywords(req.getCollectionName(), query, AUTOCOMPLETE_ENTRIES_COUNT);
return keywords.toJSONString();
} catch (Exception e) {
LOGGER.error("Exception while autocomplete " + e);
}
return null;
}
use of com.salesmanager.shop.store.model.search.AutoCompleteRequest in project shopizer by shopizer-ecommerce.
the class SearchFacadeImpl method autocompleteRequest.
@Override
public ValueList autocompleteRequest(String word, MerchantStore store, Language language) {
AutoCompleteRequest req = new AutoCompleteRequest(store.getCode(), language.getCode());
// String formattedQuery = String.format(coreConfiguration.getProperty("AUTOCOMPLETE_QUERY"), query);
/**
* formatted toJSONString because of te specific field names required in
* the UI
*/
SearchKeywords keywords = getSearchKeywords(req, word);
ValueList returnList = new ValueList();
returnList.setValues(keywords.getKeywords());
return returnList;
}
Aggregations