# 停用词
停用词(Stopwords)是在搜索时会被从查询中移除的关键词。
注意: 在索引过程中不会移除停用词。
# 添加停用词
首先让我们创建一个名为 stopword_set1
的停用词集合,并设置 en
语言环境(可选)。
curl "http://localhost:8108/stopwords/stopword_set1" -X PUT \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"stopwords": ["Germany", "France", "Italy", "United States"],
"locale": "en"
}'
成功添加停用词集合后,我们将收到如下响应:
{
"id": "stopword_set1",
"locale": "en",
"stopwords": [
"states","united","france","germany","italy"
]
}
注意短语 United States
被拆分为两个不同的单词添加。这是因为停用词会被分词处理。
# 在搜索时使用停用词
搜索时,我们可以通过 stopwords
参数指定停用词集合,集合中的关键词将从搜索查询中被移除。
curl "http://localhost:8108/multi_search" -X POST \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"searches": [
{
"collection": "books",
"q": "the"
"query_b": "title"
"stopwords": "stopword_set1",
}
]
}'
# 获取所有停用词集合
我们可以通过列表端点获取所有停用词集合。
curl -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
"http://localhost:8108/stopwords"
# 获取特定停用词集合
要获取特定停用词集合的停用词:
curl -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
"http://localhost:8108/stopwords/countries"
# 更新停用词
我们可以用一组新的停用词覆盖现有的停用词集合。例如,要覆盖与 countries
集合关联的停用词,可以执行以下操作:
curl "http://localhost:8108/stopwords/countries" -X PUT \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{"stopwords": ["Germany", "France", "Italy"], "locale": "en"}'