这是您可以执行的操作:
{
"name":"names","fields":[
{ "name":"id","type":"Edm.String","key":true,"searchable":false },{ "name":"name","analyzer":"my_standard" }
],"analyzers":[
{
"name":"my_standard","@odata.type":"#Microsoft.Azure.Search.CustomAnalyzer","tokenizer":"standard","tokenFilters":[ "lowercase","asciifolding" ]
}
]
}
// Below snippet is for creating definition using c#
new CustomAnalyzer
{
Name = "custom_analyzer",Tokenizer = TokenizerName.Standard,TokenFilters = new[]
{
TokenFilterName.Lowercase,TokenFilterName.AsciiFolding,TokenFilterName.Phonetic
}
}
[IsSearchable,IsFilterable,IsSortable,Analyzer("custom_analyzer")]
public string Property { get; set; }
查看此博客以获取更多参考:
https://azure.microsoft.com/en-in/blog/custom-analyzers-in-azure-search/
这是自定义分析仪的样本测试方法:
[Fact]
public void CanSearchWithCustomAnalyzer()
{
Run(() =>
{
const string CustomAnalyzerName = "my_email_analyzer";
const string CustomCharFilterName = "my_email_filter";
Index index = new Index()
{
Name = SearchTestUtilities.GenerateName(),Fields = new[]
{
new Field("id",DataType.String) { IsKey = true },new Field("message",(AnalyzerName)CustomAnalyzerName) { IsSearchable = true }
},Analyzers = new[]
{
new CustomAnalyzer()
{
Name = CustomAnalyzerName,CharFilters = new[] { (CharFilterName)CustomCharFilterName }
}
},CharFilters = new[] { new PatternReplaceCharFilter(CustomCharFilterName,"@","_") }
};
Data.GetSearchServiceClient().Indexes.Create(index);
SearchIndexClient indexClient = Data.GetSearchIndexClient(index.Name);
var documents = new[]
{
new Document() { { "id","1" },{ "message","My email is someone@somewhere.something." } },new Document() { { "id","2" },"His email is someone@nowhere.nothing." } },};
indexClient.Documents.Index(IndexBatch.Upload(documents));
SearchTestUtilities.WaitForIndexing();
DocumentSearchResult<Document> result = indexClient.Documents.Search("someone@somewhere.something");
Assert.Equal("1",result.Results.Single().Document["id"]);
});
}
随时在您的对话中标记我,希望对您有所帮助。
本文链接:https://www.f2er.com/3115970.html