跳到主要内容

Stop

stop 过滤器删除分词文本中的指定停用词,帮助消除常见且意义不大的词。您可以使用 stop_words 参数配置停用词列表。

配置

stop 过滤器是 Zilliz Cloud 中的自定义过滤器,通过在过滤器配置中设置 "type": "stop" 来指定。

analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "stop", # Specifies the filter type as stop
"stop_words": ["of", "to", "_english_"], # Defines custom stop words and includes the English stop word list
}],
}

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

参数

描述

stop_words

要从分词中移除的单词列表。默认情况下,使用预定义的 english 列表,其中包含常见的英语停用词。有关 english 的详细信息,请查看这里

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

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

使用示例

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

Analyzer 配置

analyzer_params = {
"tokenizer": "standard",
"filter":[{
"type": "stop", # Specifies the filter type as stop
"stop_words": ["of", "to", "_english_"], # Defines custom stop words and includes the English stop word list
}],
}

使用 run_analyzer 验证效果

from pymilvus import (
MilvusClient,
)

client = MilvusClient(uri="YOUR_CLUSTER_ENDPOINT")

# Sample text to analyze
sample_text = "The stop filter allows control over common stop words for text processing."

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

预期结果

['The', 'stop', 'filter', 'allows', 'control', 'over', 'common', 'stop', 'words', 'text', 'processing']