云搜索服务 CSS-使用示例:步骤一:配置自定义词库

时间:2023-11-01 16:18:11

步骤一:配置自定义词库

  1. 准备词库文件(UTF-8无BOM格式编码的文本文件),上传到对应OBS路径下。

    主词词库文件中包含词语“智能手机”;停词词库文件中包含词语“是”;同义词词库文件中包含一组同义词“开心”“高兴”

    由于系统默认词库的停用词包含了“是”“的”等常用词,此类停用词可以不用上传。

  2. 在云搜索服务管理控制台,单击左侧导航栏的“集群管理”
  3. “集群管理”页面,单击需要配置自定义词库的集群名称,进入集群基本信息页面。
  4. 在左侧导航栏,选择“自定义词库”,参考配置自定义词库为集群配置1准备好的词库文件。
  5. 待词库配置信息生效后,返回集群列表。单击集群操作列的“Kibana”接入集群。
  6. 在Kibana界面,单击左侧导航栏的“Dev Tools”,进入操作页面。
  7. 执行如下命令,查看自定义词库的不同分词策略的分词效果。
    • 使用ik_smart分词策略对文本内容“智能手机是很好用”进行分词。
      示例代码:
      POST /_analyze{  "analyzer":"ik_smart",  "text":"智能手机是很好用"}

      运行结束后,查看分词效果:

      {  "tokens": [    {      "token": "智能手机",      "start_offset": 0,      "end_offset": 4,      "type": "CN_WORD",      "position": 0    },    {      "token": "很好用",      "start_offset": 5,      "end_offset": 8,      "type": "CN_WORD",      "position": 1    }  ]}
    • 使用ik_max_word分词策略对文本内容“智能手机是很好用”进行分词。

      示例代码:

      POST /_analyze{  "analyzer":"ik_max_word",  "text":"智能手机是很好用"}

      运行结束后,查看分词效果:

      {  "tokens" : [    {      "token" : "智能手机",      "start_offset" : 0,      "end_offset" : 4,      "type" : "CN_WORD",      "position" : 0    },    {      "token" : "智能",      "start_offset" : 0,      "end_offset" : 2,      "type" : "CN_WORD",      "position" : 1    },    {      "token" : "智",      "start_offset" : 0,      "end_offset" : 1,      "type" : "CN_WORD",      "position" : 2    },    {      "token" : "能手",      "start_offset" : 1,      "end_offset" : 3,      "type" : "CN_WORD",      "position" : 3    },    {      "token" : "手机",      "start_offset" : 2,      "end_offset" : 4,      "type" : "CN_WORD",      "position" : 4    },    {      "token" : "机",      "start_offset" : 3,      "end_offset" : 4,      "type" : "CN_WORD",      "position" : 5    },    {      "token" : "很好用",      "start_offset" : 5,      "end_offset" : 8,      "type" : "CN_WORD",      "position" : 6    },    {      "token" : "很好",      "start_offset" : 5,      "end_offset" : 7,      "type" : "CN_WORD",      "position" : 7    },    {      "token" : "好用",      "start_offset" : 6,      "end_offset" : 8,      "type" : "CN_WORD",      "position" : 8    },    {      "token" : "用",      "start_offset" : 7,      "end_offset" : 8,      "type" : "CN_WORD",      "position" : 9    }  ]}
support.huaweicloud.com/usermanual-css/css_01_0036.html