Search in sources :

Example 1 with AutoCompleteRequest

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;
}
Also used : AutoCompleteRequest(com.salesmanager.shop.store.model.search.AutoCompleteRequest) SearchKeywords(com.salesmanager.core.model.search.SearchKeywords) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with AutoCompleteRequest

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;
}
Also used : AutoCompleteRequest(com.salesmanager.shop.store.model.search.AutoCompleteRequest) ValueList(com.salesmanager.shop.model.entity.ValueList) SearchKeywords(com.salesmanager.core.model.search.SearchKeywords)

Aggregations

SearchKeywords (com.salesmanager.core.model.search.SearchKeywords)2 AutoCompleteRequest (com.salesmanager.shop.store.model.search.AutoCompleteRequest)2 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 ValueList (com.salesmanager.shop.model.entity.ValueList)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1