跳到主要内容

Stemmer

stemmer 过滤器将单词简化为其基本或根形式(称为词干提取),使得匹配不同变化形式中具有相似意义的单词变得更加容易。stemmer 过滤器支持多种语言,允许在各种语言环境中有效地进行搜索和索引。

配置

stemmer 过滤器是 Zilliz Cloud 中的自定义过滤器,通过在过滤器配置中设置 "type": "stemmer" 并将 language 参数设置为您需要的值的方式来指定。

analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "stemmer", # Specifies the filter type as stemmer
"language": "english", # Sets the language for stemming to English
}],
}

stemmer 过滤器接受以下可选参数。

参数

描述

language

指定词干提取过程的语言。支持的语言包括:"arabic", "danish", "dutch", "english", "finnish", "french", "german", "greek", "hungarian", "italian", "norwegian", "portuguese", "romanian", "russian", "spanish", "swedish", "tamil", "turkish"

stemmer 过滤器作用于分词器生成的词项,因此必须与分词器结合使用。有关 Zilliz Cloud 中可用的分词器列表,请参阅分词器参考

定义 analyzer_params 后,您可以在定义 Collection Schema 时将其应用于 VARCHAR 字段。这使得 Zilliz Cloud 能够使用指定的分析器处理该字段中的文本,以实现高效的分词和过滤。更多信息,请参阅使用示例

示例输出

在完成 Analyzer 配置后,您可以使用 run_analyzer 方法来验证分词效果是否符合预期。

Analyzer 配置

analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "stemmer", # Specifies the filter type as stemmer
"language": "english", # Sets the language for stemming to English
}],
}

使用 run_analyzer 验证效果

from pymilvus import (
MilvusClient,
)

client = MilvusClient(uri="YOUR_CLUSTER_ENDPOINT")

# Sample text to analyze
sample_text = "running runs looked ran runner"

# Run the standard analyzer with the defined configuration
result = client.run_analyzer(sample_text, analyzer_params)
print("Standard analyzer output:", result)

预期结果

['run', 'run', 'look', 'ran', 'runner']