SearchExplainerController.java 1.86 KB
package com.yoho.search.restapi.tools;

import com.yoho.search.base.utils.HttpServletRequestUtils;
import com.yoho.search.service.scene.others.explain.SearchExplainerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
public class SearchExplainerController {

    private static final Logger logger = LoggerFactory.getLogger(SearchExplainerController.class);

    @Autowired
    private SearchExplainerService searchExplainerService;

    //显示SKN分词结果
    @RequestMapping(value = "/tools/show")
    public Map<String, Object> show(HttpServletRequest request) {
        Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
        try {
            return searchExplainerService.show(paramMap);
        } catch (Throwable t) {
            logger.error(t.getMessage(), t);
            return errorResult(t.getMessage());
        }
    }

    //显示SKN和商品的匹配结果
    @RequestMapping(value = "/tools/multiFieldAnalyzeList")
    public Map<String, Object> multiFieldAnalyzeList(HttpServletRequest request) {
        Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
        try {
            return searchExplainerService.multiFieldAnalyzeList(paramMap);
        } catch (Throwable t) {
            logger.error(t.getMessage(), t);
            return errorResult(t.getMessage());
        }
    }

    private Map<String, Object> errorResult(String message) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", "500");
        map.put("message", message);
        return map;
    }

}