测试es的分词效果

1、service

    public Object getAnalyzeResponse(String text) {
        try {

            AnalyzeRequest analyzeRequest = AnalyzeRequest.withGlobalAnalyzer("ik_max_word", text);

            AnalyzeResponse response = restHighLevelClient.indices().analyze(analyzeRequest, RequestOptions.DEFAULT);
            List tokens = response.getTokens();
            System.out.println(JSON.toJSONString(tokens));


            return tokens;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

2、controller

    @ApiOperation(value = "查询分词效果")
    @GetMapping(value = "getAnalyzeResponse")
    public ResultMsg getAnalyzeResponse(
            @RequestParam String text
    ) {
        return ResultMsg.builder(this.product2Service.getAnalyzeResponse(text));
    }

3、实际分词效果

{
  "msg": "成功",
  "data": [
    {
      "term": "牛肉面",
      "startOffset": 0,
      "endOffset": 3,
      "position": 0,
      "positionLength": 1,
      "type": "CN_WORD",
      "attributes": {}
    },
    {
      "term": "牛肉",
      "startOffset": 0,
      "endOffset": 2,
      "position": 1,
      "positionLength": 1,
      "type": "CN_WORD",
      "attributes": {}
    },
    {
      "term": "面",
      "startOffset": 2,
      "endOffset": 3,
      "position": 2,
      "positionLength": 1,
      "type": "CN_CHAR",
      "attributes": {}
    }
  ],
  "success": true,
  "code": 200
}

测试es的分词效果_第1张图片

 

你可能感兴趣的:(elasticsearch,c#,大数据)