Method: query.suggest
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
แสดงคําแนะนําสําหรับการเติมข้อความค้นหาอัตโนมัติ
หมายเหตุ: API นี้ต้องใช้บัญชีผู้ใช้ปลายทางมาตรฐานเพื่อดำเนินการ บัญชีบริการไม่สามารถส่งคําขอไปยัง Query API ได้โดยตรง หากต้องการใช้บัญชีบริการเพื่อทำการค้นหา ให้ตั้งค่าการมอบสิทธิ์ทั้งโดเมนของ Google Workspace
คำขอ HTTP
POST https://cloudsearch.googleapis.com/v1/query/suggest
URL ใช้ไวยากรณ์การแปลง gRPC
เนื้อหาของคำขอ
เนื้อความของคำขอมีข้อมูลซึ่งมีโครงสร้างดังต่อไปนี้
ช่อง |
requestOptions |
object (RequestOptions )
ตัวเลือกคำขอ เช่น แอปพลิเคชันการค้นหาและเขตเวลาของผู้ใช้
|
query |
string
ข้อความค้นหาบางส่วนที่ระบบจะแสดงคําแนะนําที่เติมข้อความอัตโนมัติ เช่น หากข้อความค้นหาคือ "sea" เซิร์ฟเวอร์อาจแสดงผลลัพธ์เป็น "season", "search", "seagull" และอื่นๆ
|
dataSourceRestrictions[] |
object (DataSourceRestriction )
แหล่งที่มาที่จะใช้สำหรับคำแนะนำ หากไม่ได้ระบุ ระบบจะนำแหล่งข้อมูลจากแอปพลิเคชันการค้นหาปัจจุบัน หมายเหตุ: ระบบรองรับคําแนะนําสําหรับแหล่งที่มาต่อไปนี้เท่านั้น
- แหล่งข้อมูลของบุคคลที่สาม
- PredefinedSource.PERSON
- PredefinedSource.GOOGLE_DRIVE
|
เนื้อหาการตอบกลับ
การตอบกลับของ API แนะนำ
หากทำสำเร็จ เนื้อหาการตอบกลับจะมีข้อมูลซึ่งมีโครงสร้างดังต่อไปนี้
การแสดง JSON |
{
"suggestResults": [
{
object (SuggestResult )
}
]
} |
ช่อง |
suggestResults[] |
object (SuggestResult )
รายการคำแนะนำ
|
ขอบเขตการให้สิทธิ์
ต้องใช้ขอบเขต OAuth ต่อไปนี้
https://www.googleapis.com/auth/cloud_search.query
https://www.googleapis.com/auth/cloud_search
ดูข้อมูลเพิ่มเติมได้ที่คู่มือการให้สิทธิ์
SuggestResult
ผลการค้นหาคำแนะนำ 1 รายการ
การแสดง 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 )
ตัวเลือกนี้จะปรากฏเมื่อการแนะนำระบุบุคคล อีเมลดังกล่าวมีข้อมูลเพิ่มเติมเกี่ยวกับบุคคลนั้น เช่น รหัสอีเมล ชื่อ ฯลฯ
|
QuerySuggestion
ประเภทนี้ไม่มีช่อง
ช่องนี้ไม่มีข้อมูลใดๆ ในตอนนี้ และใช้เป็นตัวบ่งชี้ว่าผลการค้นหาที่แนะนำเป็นการเติมข้อความ
PeopleSuggestion
ฟิลด์นี้มีข้อมูลเกี่ยวกับบุคคลที่แนะนำ
การแสดง JSON |
{
"person": {
object (Person )
}
} |
ช่อง |
person |
object (Person )
บุคคลที่แนะนำ ระบบอาจไม่ป้อนข้อมูลในฟิลด์ทั้งหมดของออบเจ็กต์บุคคล
|
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[],[],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. |"]]