法语分析器
可以使用以下命令将内置的 french
分析器应用于文本字段
PUT /french-index
{
"mappings": {
"properties": {
"content": {
"type": "text",
"analyzer": "french"
}
}
}
}
词干排除
您可以使用以下命令将 stem_exclusion
与此语言分析器一起使用
PUT index_with_stem_exclusion_french_analyzer
{
"settings": {
"analysis": {
"analyzer": {
"stem_exclusion_french_analyzer": {
"type": "french",
"stem_exclusion": ["autorité", "acceptation"]
}
}
}
}
}
法语分析器内部结构
french
分析器由以下组件构建而成
-
分词器:
standard
-
词元过滤器
- 省略 (法语)
- 小写
- 停用词 (法语)
- 关键词
- 词干提取器 (法语)
自定义法语分析器
您可以使用以下命令创建自定义法语分析器
PUT /french-index
{
"settings": {
"analysis": {
"filter": {
"french_stop": {
"type": "stop",
"stopwords": "_french_"
},
"french_elision": {
"type": "elision",
"articles_case": true,
"articles": [
"l", "m", "t", "qu", "n", "s",
"j", "d", "c", "jusqu", "quoiqu",
"lorsqu", "puisqu"
]
},
"french_stemmer": {
"type": "stemmer",
"language": "light_french"
},
"french_keywords": {
"type": "keyword_marker",
"keywords": []
}
},
"analyzer": {
"french_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"french_elision",
"lowercase",
"french_stop",
"french_keywords",
"french_stemmer"
]
}
}
}
},
"mappings": {
"properties": {
"content": {
"type": "text",
"analyzer": "french_analyzer"
}
}
}
}
生成的词元
使用以下请求检查使用该分析器生成的词元
POST /french-index/_analyze
{
"field": "content",
"text": "Les étudiants étudient à Paris et dans les universités françaises. Leurs numéros sont 123456."
}
响应包含生成的词元
{
"tokens": [
{"token": "etudiant","start_offset": 4,"end_offset": 13,"type": "<ALPHANUM>","position": 1},
{"token": "etudient","start_offset": 14,"end_offset": 22,"type": "<ALPHANUM>","position": 2},
{"token": "pari","start_offset": 25,"end_offset": 30,"type": "<ALPHANUM>","position": 4},
{"token": "universit","start_offset": 43,"end_offset": 54,"type": "<ALPHANUM>","position": 8},
{"token": "francais","start_offset": 55,"end_offset": 65,"type": "<ALPHANUM>","position": 9},
{"token": "numero","start_offset": 73,"end_offset": 80,"type": "<ALPHANUM>","position": 11},
{"token": "123456","start_offset": 86,"end_offset": 92,"type": "<NUM>","position": 13}
]
}