本文介绍了创建自定义的NEST过滤令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何配置指数使用NEST这样JSON:
How can I configure Index using NEST with such JSON:
"settings":{
"analysis":{
"filter":{
"name_ngrams":{
"side":"front",
"max_gram":50,
"min_gram":2,
"type":"edgeNGram"
}
},
"analyzer":{
"partial_name":{
"filter":[
"standard",
"lowercase",
"asciifolding",
"name_ngrams"
],
"type":"custom",
"tokenizer":"standard"
}
}
}
我可以使用 CustomAnalyzer
类创建我的自定义分析,但我发现could'n如何创建自定义过滤器和分析器我内注册。
I could create my custom analyzer using CustomAnalyzer
class, but I could'n find how to create custom filter and register it within my analyzer.
在此先感谢!
推荐答案
一些搜索我已经后找到了解决方法:
After some searching I've found a solution:
var partialName = new CustomAnalyzer
{
Filter = new List<string> {"lowercase", "name_ngrams", "standard", "asciifolding"},
Tokenizer = "standard"
};
var fullName = new CustomAnalyzer
{
Filter = new List<string> {"standard", "lowercase", "asciifolding"},
Tokenizer = "standard"
};
client.CreateIndex("indexname", c => c
.Analysis(descriptor => descriptor
.TokenFilters(bases => bases.Add("name_ngrams", new EdgeNGramTokenFilter
{
MaxGram = 20,
MinGram = 2,
Side = "front"
}))
.Analyzers(bases => bases
.Add("partial_name", partialName)
.Add("full_name", fullName))
)
.AddMapping<Company>(m => m
.Properties(o => o
.String(i => i
.Name(x => x.Name)
.IndexAnalyzer("partial_name")
.SearchAnalyzer("full_name")
))));
这篇关于创建自定义的NEST过滤令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!