代码之家  ›  专栏  ›  技术社区  ›  user246392

如何在Azure搜索索引中获取字符匹配而不是子字符串

  •  0
  • user246392  · 技术社区  · 7 年前

    我为我的 DocumentDB FirstName , LastName ,和 Username 用户名

    0 回复  |  直到 7 年前
        1
  •  2
  •   Liam Cavanagh - MSFT    7 年前

    根据您的上述评论添加另一个答案。所以基本上在最好的情况下,你要做的是前缀,后缀和通配符搜索。因此,如果用户名是user246392,您可以通过键入“use”、“392”甚至“er246”找到它。前缀很简单,因为你可以搜索use*并找到它。

    RegEx with Azure Search ,这可以让您完成请求的全部通配符部分(即搜索“392”)。

    如果你想做后缀搜索,你可以做一个非常有效的技巧,你可以创建一个新的字段,它将是一个自定义的分析器,将按相反的顺序索引单词。下面是一个索引模式的示例,该模式允许这样做(在后缀名字段上)

    {   
    "name":"people",
    "fields": [
        { "name":"id", "type":"Edm.String", "key":true, "searchable":false },
        {"name": "suffixName", "type": "Edm.String", "searchable":true, "indexAnalyzer":"suffixIndexingAnalyzer", "searchAnalyzer":"reverseText"}
    ],
    "analyzers": [
        {
            "@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
            "name": "suffixIndexingAnalyzer",  
            "tokenizer": "keyword_v2",
            "tokenFilters": [
                "asciifolding",
                "lowercase",
                "reverse",
                "my_edgeNGramForSuffix"
            ],
            "charFilters": []
        },
        {
            "@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
            "name": "reverseText",  
            "tokenizer": "classic",
            "tokenFilters": [
                "lowercase",
                "reverse"
            ],
            "charFilters": []
        }
    
    ],
    "tokenFilters":[  
        {
            "@odata.type": "#Microsoft.Azure.Search.EdgeNGramTokenFilterV2",
            "name": "my_edgeNGramForSuffix",
            "minGram": 2,
            "maxGram": 25,
            "side": "front"
        }
    ]
    

    }

        2
  •  0
  •   Liam Cavanagh - MSFT    7 年前

    custom analyzer 启用了RegEx seared可能有助于此字段?请注意,ReGEX不像典型的索引那样有性能,因为我们需要扫描整个内容,而不是去倒置索引来查找令牌匹配。

    推荐文章