名前空間: microsoft.graph
重要
Microsoft Graph の /beta バージョンの API は変更される可能性があります。 実稼働アプリケーションでこれらの API を使用することは、サポートされていません。 v1.0 で API を使用できるかどうかを確認するには、Version セレクターを使用します。
クエリと一致するアイテムを対象にアイテムの階層を検索します。
フォルダー階層内、ドライブ全体、現在のユーザーと共有されるファイル内で検索できます。
アクセス許可
この API の最小特権としてマークされているアクセス許可またはアクセス許可を選択します。
アプリで必要な場合にのみ、より高い特権のアクセス許可またはアクセス許可を使用します。 委任されたアクセス許可とアプリケーションのアクセス許可の詳細については、「アクセス許可の種類」を参照してください。 これらのアクセス許可の詳細については、「アクセス許可のリファレンス」を参照してください。
| アクセス許可の種類 |
最小特権アクセス許可 |
より高い特権のアクセス許可 |
| 委任 (職場または学校のアカウント) |
Files.Read |
Files.Read.All、Files.ReadWrite、Files.ReadWrite.All、Sites.Read.All、Sites.ReadWrite.All |
| 委任 (個人用 Microsoft アカウント) |
Files.Read |
Files.Read.All、Files.ReadWrite、Files.ReadWrite.All |
| アプリケーション |
Files.Read.All |
Files.ReadWrite.All、Sites.Read.All、Sites.ReadWrite.All |
注: このメソッドは Sites.Selected アプリケーションのアクセス許可をサポートしていません。
HTTP 要求
GET /drives/{drive-id}/root/search(q='{search-text}')
GET /groups/{group-id}/drive/root/search(q='{search-text}')
GET /me/drive/root/search(q='{search-text}')
GET /sites/{site-id}/drive/root/search(q='{search-text}')
GET /users/{user-id | userPrincipalName}/drive/root/search(q='{search-text}')
オプションのクエリ パラメーター
このメソッドは、 $expand、 $select、 $skipToken、 $top、 $orderbyOData クエリ パラメーター をサポートして、応答をカスタマイズします。
関数パラメーター
| パラメーター |
型 |
説明 |
| q |
string |
アイテムの検索に使用するクエリ テキスト。 値は、ファイル名、メタデータ、およびファイルのコンテンツを含む複数のフィールドに渡って照合できます。 |
例
要求
次の例では、サインインしているユーザーのドライブ アイテム内の複数のフィールドで、「Contoso Project」の一致を検索します。
GET /me/drive/root/search(q='Contoso Project')
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].SearchWithQ("{q}").GetAsSearchWithQGetResponseAsync();
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
//other-imports
)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
q := "{q}"
search, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").SearchWithQ(&q).GetAsSearchWithQGetResponse(context.Background(), nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
var result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").searchWithQ("{q}").get();
const options = {
authProvider,
};
const client = Client.init(options);
let search = await client.api('/me/drive/root/search(q='Contoso Project')')
.version('beta')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->searchWithQ('{q}', )->get()->wait();
Import-Module Microsoft.Graph.Beta.Files
Search-MgBetaDriveItem -DriveId $driveId -DriveItemId $driveItemId
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').search_with_q("{q}").get()
応答
このメソッドは、検索条件に一致する DriveItems のコレクション含んでいるオブジェクトを返します。
アイテムが見つからない場合は、空のコレクションが返されます。
一致する値が多すぎる場合、応答はページングされ、 @odata.nextLink プロパティには結果の次のページへの URL が含まれます。
クエリ パラメーターを使用すると、ページ内のアイテム数を指定できます。
HTTP/1.1 200 OK
Content-type: application/json
{
"value": [
{
"id": "0123456789abc!123",
"name": "Contoso Project",
"folder": {},
"searchResult": { "onClickTelemetryUrl": "https://bing.com/0123456789abc!123" }
},
{
"id": "0123456789abc!456",
"name": "Contoso Project 2016",
"folder": {},
"searchResult": { "onClickTelemetryUrl": "https://bing.com/0123456789abc!456" }
}
],
"@odata.nextLink": "https://graph.microsoft.com/v1.0/me/drive/root/search(query='contoso project')&skipToken=1asdlnjnkj1nalkm!asd"
}
ユーザーがアクセスできるアイテムの検索
ドライブ内のアイテムの検索に加えて、アプリでは現在のユーザーと共有されるアイテムを含めるように、検索範囲を広げることができます。
検索範囲を広げるには、Drive リソースの search メソッドを使用します。
例
GET /me/drive/search(q='Contoso Project')
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].SearchWithQ("{q}").GetAsSearchWithQGetResponseAsync();
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
//other-imports
)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
q := "{q}"
search, err := graphClient.Drives().ByDriveId("drive-id").SearchWithQ(&q).GetAsSearchWithQGetResponse(context.Background(), nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
var result = graphClient.drives().byDriveId("{drive-id}").searchWithQ("{q}").get();
const options = {
authProvider,
};
const client = Client.init(options);
let search = await client.api('/me/drive/search(q='Contoso Project')')
.version('beta')
.get();
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$result = $graphServiceClient->drives()->byDriveId('drive-id')->searchWithQ('{q}', )->get()->wait();
Import-Module Microsoft.Graph.Beta.Files
Search-MgBetaDrive -DriveId $driveId
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
result = await graph_client.drives.by_drive_id('drive-id').search_with_q("{q}").get()
応答
ドライブ リソースからの検索時の応答には、ドライブの外部のアイテム (現在のユーザーと共有されているアイテム) が含まれていることがあります。
こうしたアイテムには、それらが対象のドライブの外部に保存されていることを示す、remoteItem ファセットが含まれます。
HTTP/1.1 200 OK
Content-type: application/json
{
"value": [
{
"id": "0123456789abc!123",
"name": "Contoso Project",
"folder": {},
"searchResult": { "onClickTelemetryUrl": "https://bing.com/0123456789abc!123" },
"remoteItem": { "id": "!23141901", "driveId": "s!1020101jlkjl12lx" }
},
{
"id": "0123456789abc!456",
"name": "Contoso Project 2016",
"folder": {},
"searchResult": { "onClickTelemetryUrl": "https://bing.com/0123456789abc!456" }
}
],
"@odata.nextLink": "https://graph.microsoft.com/v1.0/me/drive/root/search(query='contoso project')&skipToken=1asdlnjnkj1nalkm!asd"
}
エラー応答
エラーがどのように返されるかの詳細については、「エラー応答」を参照してください。