问题
When defining a custom analyzer for Azure Search there is an option of defining a token filter from this list. I am trying to support search of both prefix and infix. For example: if a field contains the name: 123 456, I want the searchable terms to contain:
1
12
123
23
3
4
45
456
56
6
When using the EdgeNGramTokenFilterV2 which seems to do the trick, there is an option of defining a "side" property, but only "front" and "back" are supported, not both. the "front" (default) value generates this list:
1
12
123
4
45
456
and back generates:
123
23
3
456
56
6
I tried using two token two EdgeNGramTokenFilterV2s, but this creates terms from combining the two filters such as: "2" or "5":
1
12
123
23
3
4
45
456
56
6
2 // Unwanted
5 // Unwanted
I also tried using a "reverse" token, but this reverses everything and the results are still wrong.
I am using only one search field ("Name") and would prefer it to stay like this. (Thought of the option of using a different field named "name_reverse" with a different analyzer, but this is very inefficient and will cause a lot of headache when connecting the search engine to the data source.
For easier reference, this is the current index creation request:
{
"name": "testindexboth",
"fields": [
{"name": "id", "type": "Edm.String", "key": true },
{"name": "Name", "type": "Edm.String", "searchable": true, "analyzer": "myAnalyzer"}
],
"myAnalyzer": [
{
"name": "myAnalyzer",
"@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
"tokenizer": "standard_v2",
"tokenFilters":["front_filter", "back_filter"]
}],
"tokenFilters":[
{
"name":"front_filter",
"@odata.type":"#Microsoft.Azure.Search.EdgeNGramTokenFilterV2",
"maxGram":15,
"side": "front"
},
{
"name":"back_filter",
"@odata.type":"#Microsoft.Azure.Search.EdgeNGramTokenFilterV2",
"maxGram":15,
"side": "back"
}
]
}
Is there an option of combining both, without getting them scramble up the results?
回答1:
Add two fields to your index, with two different custom analyzers: one for prefix, one for suffix. When querying, query against both fields.
来源:https://stackoverflow.com/questions/46756336/create-an-edgengram-analyzer-supporting-both-sides-in-azure-search