Method: query.suggest
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
HTTP 要求
POST https://cloudsearch.googleapis.com/v1/query/suggest
這個網址使用 gRPC 轉碼語法。
要求主體
要求主體的資料會採用以下結構:
欄位 |
requestOptions |
object (RequestOptions )
請求選項,例如搜尋應用程式和使用者時區。
|
query |
string
系統會顯示部分查詢的自動完成建議。舉例來說,如果查詢是「sea」,伺服器可能會傳回「season」、「search」、「seagull」等。
|
dataSourceRestrictions[] |
object (DataSourceRestriction )
用於提供建議的來源。如未指定,系統會從目前的搜尋應用程式取得資料來源。 注意:系統僅支援下列來源的建議字詞:
- 第三方資料來源
- PredefinedSource.PERSON
- PredefinedSource.GOOGLE_DRIVE
|
回應主體
建議 API 的回應。
如果成功,回應主體會含有以下結構的資料:
欄位 |
suggestResults[] |
object (SuggestResult )
建議清單。
|
授權範圍
需要下列其中一種 OAuth 範圍:
https://www.googleapis.com/auth/cloud_search.query
https://www.googleapis.com/auth/cloud_search
詳情請參閱授權指南。
SuggestResult
JSON 表示法 |
{
"suggestedQuery": string,
"source": {
object (Source )
},
// Union field suggestion can be only one of the following:
"querySuggestion": {
object (QuerySuggestion )
},
"peopleSuggestion": {
object (PeopleSuggestion )
}
// End of list of possible types for union field suggestion .
} |
欄位 |
suggestedQuery |
string
使用者點選建議內容時,系統會用於搜尋的建議查詢
|
source |
object (Source )
建議的來源。
|
聯集欄位 suggestion 。包含建議查詢的其他中繼資料。並指出建議查詢的類型。舉例來說,如果有 PeopleSuggestion,表示 suggested_query 是人物建議。suggestion 只能是下列其中一項: |
querySuggestion |
object (QuerySuggestion )
如果建議查詢是字詞/詞組完成,就會顯示這個欄位。
|
peopleSuggestion |
object (PeopleSuggestion )
當建議內容是某位聯絡人時,就會顯示這個圖示。這類資訊包含使用者的更多資訊,例如電子郵件 ID、姓名等。
|
QuerySuggestion
這個類型沒有任何欄位。
這個欄位目前不包含任何內容,僅用於指出建議結果是字詞完成。
PeopleSuggestion
JSON 表示法 |
{
"person": {
object (Person )
}
} |
欄位 |
person |
object (Person )
建議的使用者。可能不會填入人員物件中的所有欄位。
|
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[],[],null,["# Method: query.suggest\n\n- [HTTP request](#body.HTTP_TEMPLATE)\n- [Request body](#body.request_body)\n - [JSON representation](#body.request_body.SCHEMA_REPRESENTATION)\n- [Response body](#body.response_body)\n - [JSON representation](#body.SuggestResponse.SCHEMA_REPRESENTATION)\n- [Authorization scopes](#body.aspect)\n- [SuggestResult](#SuggestResult)\n - [JSON representation](#SuggestResult.SCHEMA_REPRESENTATION)\n- [QuerySuggestion](#QuerySuggestion)\n- [PeopleSuggestion](#PeopleSuggestion)\n - [JSON representation](#PeopleSuggestion.SCHEMA_REPRESENTATION)\n- [Try it!](#try-it)\n\nProvides suggestions for autocompleting the query.\n\n**Note:** This API requires a standard end user account to execute. A service account can't perform query API requests directly; to use a service account to perform queries, set up [Google Workspace domain-wide delegation of authority](https://developers.google.com/workspace/cloud-search/docs/guides/delegation/).\n\n### HTTP request\n\n`POST https://cloudsearch.googleapis.com/v1/query/suggest`\n\nThe URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.\n\n### Request body\n\nThe request body contains data with the following structure:\n\n| JSON representation |\n|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"requestOptions\": { object (/workspace/cloud-search/docs/reference/rest/v1/RequestOptions) }, \"query\": string, \"dataSourceRestrictions\": [ { object (/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#DataSourceRestriction) } ] } ``` |\n\n| Fields ||\n|----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `requestOptions` | `object (`[RequestOptions](/workspace/cloud-search/docs/reference/rest/v1/RequestOptions)`)` Request options, such as the search application and user timezone. |\n| `query` | `string` Partial query for which autocomplete suggestions will be shown. For example, if the query is \"sea\", then the server might return \"season\", \"search\", \"seagull\" and so on. |\n| `dataSourceRestrictions[]` | `object (`[DataSourceRestriction](/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#DataSourceRestriction)`)` The sources to use for suggestions. If not specified, the data sources are taken from the current search application. NOTE: Suggestions are only supported for the following sources: - Third-party data sources - PredefinedSource.PERSON - PredefinedSource.GOOGLE_DRIVE |\n\n### Response body\n\nResponse of the suggest API.\n\nIf successful, the response body contains data with the following structure:\n\n| JSON representation |\n|---------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"suggestResults\": [ { object (/workspace/cloud-search/docs/reference/rest/v1/query/suggest#SuggestResult) } ] } ``` |\n\n| Fields ||\n|--------------------|-------------------------------------------------------------------------------------------------------------------------------|\n| `suggestResults[]` | `object (`[SuggestResult](/workspace/cloud-search/docs/reference/rest/v1/query/suggest#SuggestResult)`)` List of suggestions. |\n\n### Authorization scopes\n\nRequires one of the following OAuth scopes:\n\n- `https://www.googleapis.com/auth/cloud_search.query`\n- `https://www.googleapis.com/auth/cloud_search`\n\nFor more information, see the [Authorization guide](/workspace/guides/configure-oauth-consent).\n\nSuggestResult\n-------------\n\nOne suggestion result.\n\n| JSON representation |\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"suggestedQuery\": string, \"source\": { object (/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#Source) }, // Union field `suggestion` can be only one of the following: \"querySuggestion\": { object (/workspace/cloud-search/docs/reference/rest/v1/query/suggest#QuerySuggestion) }, \"peopleSuggestion\": { object (/workspace/cloud-search/docs/reference/rest/v1/query/suggest#PeopleSuggestion) } // End of list of possible types for union field `suggestion`. } ``` |\n\n| Fields ||\n|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `suggestedQuery` | `string` The suggested query that will be used for search, when the user clicks on the suggestion |\n| `source` | `object (`[Source](/workspace/cloud-search/docs/reference/rest/v1/settings.searchapplications#Source)`)` The source of the suggestion. |\n| Union field `suggestion`. Contains additional metadata about the suggested query. It also indicates the type of the suggested query. For e.g. if PeopleSuggestion is present, it indicates that suggested_query is a person suggestion. `suggestion` can be only one of the following: ||\n| `querySuggestion` | `object (`[QuerySuggestion](/workspace/cloud-search/docs/reference/rest/v1/query/suggest#QuerySuggestion)`)` This field will be present if the suggested query is a word/phrase completion. |\n| `peopleSuggestion` | `object (`[PeopleSuggestion](/workspace/cloud-search/docs/reference/rest/v1/query/suggest#PeopleSuggestion)`)` This is present when the suggestion indicates a person. It contains more information about the person - like their email id, name etc. |\n\nQuerySuggestion\n---------------\n\nThis type has no fields.\nThis field does not contain anything as of now and is just used as an indicator that the suggest result was a phrase completion.\n\nPeopleSuggestion\n----------------\n\nThis field contains information about the person being suggested.\n\n| JSON representation |\n|------------------------------------------------------------------------------------------|\n| ``` { \"person\": { object (/workspace/cloud-search/docs/reference/rest/v1/Person) } } ``` |\n\n| Fields ||\n|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `person` | `object (`[Person](/workspace/cloud-search/docs/reference/rest/v1/Person)`)` Suggested person. All fields of the person object might not be populated. |"]]