跳到主要内容

ASCII folding

asciifolding 过滤器将基本拉丁Unicode块(前127个ASCII字符)之外的字符转换为其ASCII等效字符。例如,它将字符如 í 转换为 i,使得文本处理更加简单和一致,特别是对于多语言内容。

配置

asciifolding 过滤器内置于 Zilliz Cloud。要使用它,只需在 analyzer_params 的过滤器部分指定其名称。

analyzer_params = {
"tokenizer": "standard",
"filter": ["asciifolding"],
}

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

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

使用示例

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

Analyzer 配置

analyzer_params = {
"tokenizer": "standard",
"filter": ["asciifolding"],
}

使用 run_analyzer 验证效果

from pymilvus import (
MilvusClient,
)

client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)

# Sample text to analyze
sample_text = "Café Möller serves crème brûlée and piñatas."

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

预期结果

['Cafe', 'Moller', 'serves', 'creme', 'brulee', 'and', 'pinatas']