跳到主要内容
版本:v2.6.x

词干

stemmer 过滤器可将单词还原为其基本形式或词根形式(称为词干化),从而更容易匹配不同词性中含义相似的单词。stemmer 过滤器支持多种语言,可在各种语言环境中进行有效搜索和索引。

配置

stemmer 过滤器是 Milvus 的自定义过滤器。要使用它,请在过滤器配置中指定"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 过滤器对标记符生成的术语进行操作,因此必须与标记符结合使用。

定义analyzer_params 后,可以在定义 Collection Schema 时将它们应用到VARCHAR 字段。这样,Milvus 就可以使用指定的分析器对该字段中的文本进行处理,从而实现高效的标记化和过滤。有关详情,请参阅示例使用

示例

在将分析器配置应用到 Collection 模式之前,请使用run_analyzer 方法验证其行为。

分析器配置

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

验证使用run_analyzerCompatible with Milvus 2.5.11+

from pymilvus import (
MilvusClient,
)

client = MilvusClient(uri="http://localhost:19530")

# 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)
# restful
not support yet

预期输出

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