Search in sources :

Example 1 with SearchKeywords

use of com.salesmanager.core.model.search.SearchKeywords 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 SearchKeywords

use of com.salesmanager.core.model.search.SearchKeywords 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)

Example 3 with SearchKeywords

use of com.salesmanager.core.model.search.SearchKeywords in project shopizer by shopizer-ecommerce.

the class SearchServiceImpl method searchForKeywords.

public SearchKeywords searchForKeywords(String collectionName, String word, int entriesCount) throws ServiceException {
    try {
        SearchResponse response = searchService.searchAutoComplete(collectionName, word, entriesCount);
        SearchKeywords keywords = new SearchKeywords();
        if (response != null && response.getInlineSearchList() != null) {
            keywords.setKeywords(Arrays.asList(response.getInlineSearchList()));
        }
        return keywords;
    } catch (Exception e) {
        LOGGER.error("Error while searching keywords " + word, e);
        throw new ServiceException(e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) SearchKeywords(com.salesmanager.core.model.search.SearchKeywords) ServiceException(com.salesmanager.core.business.exception.ServiceException) SearchResponse(com.shopizer.search.services.SearchResponse)

Aggregations

SearchKeywords (com.salesmanager.core.model.search.SearchKeywords)3 AutoCompleteRequest (com.salesmanager.shop.store.model.search.AutoCompleteRequest)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 ValueList (com.salesmanager.shop.model.entity.ValueList)1 SearchResponse (com.shopizer.search.services.SearchResponse)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1