Microsoft Search API を使用してスペル修正を要求する

Microsoft Graph の Microsoft Search API を使用して、スペル修正を要求して、ユーザー クエリの入力ミスと一致したコンテンツ内の正しい単語の不一致を処理できます。 スペル修正を要求するには、searchRequestqueryAlterationOptions プロパティで次のプロパティを指定します。

  • enableSuggestion を使用して、ユーザー クエリのスペル候補を有効または無効にします。 を渡 true して、ユーザー クエリで入力ミスのスペル修正候補情報を取得できます。

  • enableModification を使用して、ユーザー クエリのスペル変更を有効または無効にします。 入力ミスのある元のクエリの結果がない場合に、修正されたクエリの検索結果を取得し、対応する修正情報を取得するために渡trueすことができます。

両方とも有効になっている場合、スペル修正の優先順位はスペル候補よりも高くなります。

スペル チェックの変更が有効になっているときにスペル チェック候補が無効になっている場合でも、入力ミスのある元のクエリのスペル チェック候補が結果に含まれる場合があります。 これは設計上、スペルの変更が有効になっている場合、この機能によってスペル候補が既定で提供されるためです。

複数のエンティティの検索でスペル修正を有効にするには、すべてのユーザー クエリ文字列を同じにする必要があります。

例 1: スペル候補を要求する

次の例では、文字列accounttを含む listItem リソースをクエリし、クエリのスペル候補を要求します。

応答には、スペル候補の 変更Response オブジェクトが含まれています。

要求

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

{
    "requests": [
        {
            "entityTypes": [
                "listItem"
            ],
            "query": {
                "queryString": "accountt"
            },
            "from": 0,
            "size": 25,
            "queryAlterationOptions": {
                "enableSuggestion": true,
                "enableModification": false
            }
        }
    ]
}

応答

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

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.searchResponse)",
    "value": [
        {
            "searchTerms": [
                "accountt"
            ],
            "hitsContainers": [
                {
                    "total": 0,
                    "moreResultsAvailable": false
                }
            ],
            "queryAlterationResponse": {
                "@odata.type": "#microsoft.substrateSearch.alterationResponse",
                "originalQueryString": "accountt",
                "queryAlteration": {
                    "@odata.type": "#microsoft.substrateSearch.searchAlteration",
                    "alteredQueryString": "account",
                    "alteredHighlightedQueryString": "account",
                    "alteredQueryTokens": [
                        {
                            "offset": 0,
                            "length": 8,
                            "suggestion": "account"
                        }
                    ]
                },
                "queryAlterationType": "Suggestion"
            }
        }
    ]
}

例 2: スペルの変更を要求する

次の例では、文字列accounttを含む listItem リソースをクエリし、クエリのスペル変更を要求します。

この例では、入力ミス accounttを持つ元のクエリの結果はありません。 応答には、修正された文字列 account と変更に関連する結果が含まれています。スペルの変更に関する オブジェクトが返 されます。

要求

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

{
    "requests": [
        {
            "entityTypes": [
                "listItem"
            ],
            "query": {
                "queryString": "accountt"
            },
            "from": 0,
            "size": 25,
            "queryAlterationOptions": {
                "enableSuggestion": true,
                "enableModification": true
            }
        }
    ]
}

応答

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

{
    "@odata.context": "https://graph.microsoft.com/beta/$metadata#Collection(microsoft.graph.searchResponse)",
    "value": [
        {
            "searchTerms": [
                "account"
            ],
            "hitsContainers": [
                {
                    "total": 1,
                    "moreResultsAvailable": false,
                    "hits": [
                        {
                            "hitId": "FlULeN/ui/1GjLx1rUfio5UAAEl",
                            "rank": 1,
                            "summary": "",
                            "resource": {
                                "@odata.type": "#microsoft.graph.listItem",
                                "createdDateTime": "2019-06-10T06:37:43Z",
                                "lastModifiedDateTime": "2019-06-10T06:37:43Z",
                                "name": "web_part_test_long Notebook",
                                "webUrl": "https://contoso.sharepoint.com/sites/contoso-team/Lists/Issue tracker list/DispForm.aspx?ID=1",
                                "sharepointIds": {
                                    "listId": "33498de0-d695-4d23-ac26-e1bf95a3206e",
                                    "listItemId": "13"
                                },
                                "createdBy": {
                                    "user": {
                                        "displayName": "System Account"
                                    }
                                },
                                "lastModifiedBy": {
                                    "user": {
                                        "displayName": "System Account"
                                    }
                                },
                                "parentReference": {
                                    "sharepointIds": {
                                        "listId": "da61a2b0-4120-4a3f-812b-0fc0d79bf16b"
                                    },
                                    "siteId": "m365x231305.sharepoint.com,5724d91f-650c-4810-83cc-61a8818917d6,c3ba25dc-2c9f-48cb-83be-74cdf68ea5a0"
                                }
                            }
                        }
                    ]
                }
            ],
            "queryAlterationResponse": {
                "@odata.type": "#microsoft.substrateSearch.alterationResponse",
                "originalQueryString": "accountt",
                "queryAlteration": {
                    "@odata.type": "#microsoft.substrateSearch.searchAlteration",
                    "alteredQueryString": "account",
                    "alteredHighlightedQueryString": "account",
                    "alteredQueryTokens": [
                        {
                            "offset": 0,
                            "length": 8,
                            "suggestion": "account"
                        }
                    ]
                },
                "queryAlterationType": "Modification"
            }
        }
    ]
}

既知の制限

スペル修正は、 メッセージイベントサイトドライブdriveItemlistlistItemexternalItem の各リソースでのみサポートされます。

次の手順