使用 Microsoft 搜索 API xrank 搜索结果

可以在 Microsoft Graph 中使用 Microsoft 搜索 API XRANK 表达式,根据匹配表达式中的特定字词匹配项提升项的动态排名,而无需更改与查询匹配的项目。 XRANK 表达式包含一个必须匹配的组件、匹配表达式,以及一个或多个只对动态排名做出贡献的组件,即排名表达式。 必须为有效的 XRANK 表达式指定至少 1 个参数(不包括 n)。 xrank 运算符仅在 SharePoint 中托管的文件上受支持。

XRANK 运算符的使用语法如下:

<match expression> XRANK(cb=100, rb=0.4, pb=0.4, avgb=0.4, stdb=0.4, nb=0.4, n=200) <rank expression>

有关 XRANK 运算符的动态排名计算的详细信息,请参阅 动态排名运算符

示例

以下示例显示了一个请求,该请求搜索 SharePoint 中托管的文件并使用 XRANK 运算符 提升指定的搜索结果。

不带 XRANK 的请求

POST https://graph.microsoft.com/v1.0/search/query
Content-Type: application/json

{
    "requests": [
        {
            "entityTypes": [
                "listItem"
            ],
            "query": {
                "queryString": "cat OR dog"
            },
            "from": 0,
            "size": 1
        }
    ]
}

响应

HTTP/1.1 200 OK
Content-type: application/json
{
    "value": [
        {
            "searchTerms": [
                "cat",
                "dog"
            ],
            "hitsContainers": [
                {
                    "hits": [
                        {
                            "hitId": "32faa5c0-0bd5-4918-a19c-7b3c415a0fb4",
                            "rank": 1,
                            "summary": "this program has changed any times over the years, but one of the most common is “<c0>dog</c0> food <ddd/> However, only a few of those will get focused attention through the “<c0>dog</c0> food” process <ddd/> ",
                            "resource": {
                                "@odata.type": "#microsoft.graph.listItem",
                                "createdDateTime": "2021-04-22T19:22:23Z",
                                "lastModifiedDateTime": "2021-12-03T19:00:27Z",
                                "webUrl": "https://microsoft.sharepoint.com/teams/Employee_Experience/SitePages/Dog-Foodxxxxx.aspx"
                            }
                        }
                    ],
                    "total": 616865,
                    "moreResultsAvailable": true
                }
            ]
        }
    ],
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}

使用 XRANK 请求

POST https://graph.microsoft.com/v1.0/search/query
Content-Type: application/json

{
    "requests": [
        {
            "entityTypes": [
                "listItem"
            ],
            "query": {
                "queryString": "(cat OR dog) XRANK(cb=100) note"
            },
            "from": 0,
            "size": 1
        }
    ]
}

响应

HTTP/1.1 200 OK
Content-type: application/json

{
    "value": [
        {
            "searchTerms": [
                "cat",
                "dog",
                "note"
            ],
            "hitsContainers": [
                {
                    "hits": [
                        {
                            "hitId": "cb32ce8e-7f82-4b1d-b1fb-52e6af95fbed",
                            "rank": 1,
                            "summary": "Microsoft is committed to providing a <ddd/> Other than meeting rooms marked as <c0>dog</c0>-free, meeting organizers can decide on a case-specific basis whether to disallow <c0>dogs</c0> in their meetings <ddd/> ",
                            "resource": {
                                "@odata.type": "#microsoft.graph.listItem",
                                "createdDateTime": "2020-09-21T04:46:40Z",
                                "lastModifiedDateTime": "2022-09-18T09:15:18Z",
                                "webUrl": "https://microsofteur.sharepoint.com/teams/insider/EN/SitePages/Dog-Policy.aspx"
                            }
                        }
                    ],
                    "total": 616865,
                    "moreResultsAvailable": true
                }
            ]
        }
    ],
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}

已知限制

以下资源不支持 XRANK 表达式: messagechatMessageeventpersonexternalItem

后续步骤