Search code examples
azure-cognitive-search

How to query url in azure search


I store document with following fileds in azure search, and all of then are searchable filed.

According to offical document search document , I try to query by url with content's keyword is hotel but fail.

POST /indexes/hotels/docs/search?api-version=2017-11-11  
{  
  "search": "url:example.com AND hotel",  
  "searchMode": "all"  
}   

Update:

I have try to use standard tokenizer, and the domain name blog.xuite.net success parser as token.

 "tokens": [
    {
        "token": "https",
        "startOffset": 0,
        "endOffset": 5,
        "position": 0
    },
    {
        "token": "blog.xuite.net",
        "startOffset": 8,
        "endOffset": 22,
        "position": 1
    },
    {
        "token": "yundestiny",
        "startOffset": 23,
        "endOffset": 33,
        "position": 2
    },
    {
        "token": "20050916",
        "startOffset": 34,
        "endOffset": 42,
        "position": 3
    },
 ]

Why can I search by url:blog.xuite.net ?


Solution

  • Finally, I figure out to use CustomAnalyzer by tokenizer = standard_v2 and tokenFilters = LimitTokenFilter. Following is my index setting.

     "analyzers": [
        {
            "@odata.type": "#Microsoft.Azure.Search.CustomAnalyzer",
            "name": "domain_analyzer",
            "tokenizer": "standard_v2",
            "tokenFilters": [
                "my_limit"
            ],
            "charFilters": []
        }
    ],
    "tokenizers": [],
    "tokenFilters": [
        {
            "@odata.type": "#Microsoft.Azure.Search.LimitTokenFilter",
            "name": "my_limit",
            "maxTokenCount": 2,
            "consumeAllTokens": false
        }
    ],
    

    By use this CustomAnalyzer, the url field for example

    https://example.com/test.html 
    

    will be index as example.com only.

    So I can search by search=url:(example.com) AND {keyword}