在标准的Azure搜索分析器中添加停用词?

时间:2018-10-23 19:42:53

标签: azure-search

我在Azure搜索索引中使用了en.microsoft分析器。在大多数情况下,它运行良好,但是我需要添加一些特定于域的停用词。有什么方法可以向现有的分析仪添加停用词?还是要实现一个自定义分析器,该分析器从标准分析器继承其行为,并且仅覆盖停用词,而将其他所有内容保持不变?

1 个答案:

答案 0 :(得分:2)

虽然您不能继承现有的分析器,但是可以创建一对custom analyzers(一个用于索引,另一个用于搜索),其功能与en.microsoft等效,但是带有您自己的停用词清单。在REST API的索引定义有效负载中的外观如下:

{
  ...
  "analyzers": [
    {
      "@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
      "name": "my_search_analyzer",
      "tokenizer": "my_english_search_tokenizer",
      "tokenFilters": [ "my_asciifolding_search", "lowercase", "my_stopword_filter" ]
    },
    {
      "@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
      "name": "my_index_analyzer",
      "tokenizer": "my_english_index_tokenizer",
      "tokenFilters": [ "my_asciifolding_index", "lowercase", "my_stopword_filter" ]
    }
  ],
  "tokenizers": [
    {
      "name": "my_english_search_tokenizer",
      "@odata.type": "#Microsoft.Azure.Search.MicrosoftLanguageStemmingTokenizer",
      "isSearchTokenizer": true,
      "language": "english"
    },
    {
      "name": "my_english_index_tokenizer",
      "@odata.type": "#Microsoft.Azure.Search.MicrosoftLanguageStemmingTokenizer",
      "isSearchTokenizer": false,
      "language": "english"
    }
  ],
  "tokenFilters": [
    {
      "name": "my_asciifolding_search",
      "@odata.type": "#Microsoft.Azure.Search.AsciiFoldingTokenFilter",
      "preserveOriginal": false
    },
    {
      "name": "my_asciifolding_index",
      "@odata.type": "#Microsoft.Azure.Search.AsciiFoldingTokenFilter",
      "preserveOriginal": true
    },
    {
      "name": "my_stopword_filter",
      "@odata.type": "#Microsoft.Azure.Search.StopwordsTokenFilter",
      "stopwords": [ "put", "your", "custom", "stopwords", "here" ]
    }
  ]
}