This page explains how to order the results of a web search query.
Before you begin
Make sure that you do the following:
Create a data store with website data. For more information, see Website URLs.
Create a search app and connect it to the data store. For more information, see Create a search app.
Order your web search results
REST
To use the API to order your web search results for an app with website data,
use the engines.servingConfigs.search
method:
Find your app ID. If you already have your app ID, skip to the next step.
In the Google Cloud console, go to the Agent Builder page.
On the Apps page, find the name of your app and get the app's ID from the ID column.
Make a search query and include the
orderBy
field.curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/engines/APP_ID/servingConfigs/default_search:search" \ -d '{ "servingConfig": "projects/PROJECT_ID/locations/global/collections/default_collection/engines/APP_ID/servingConfigs/default_search", "query": "QUERY", "orderBy": "ORDER_BY" }'
Replace the following:
- PROJECT_ID: The ID of your project.
- APP_ID: The ID of your app.
- QUERY: The query text to search.
- ORDER_BY: The order in which the results are arranged. For
example, specifying
date
returns web pages sorted by Google's estimate for each page's date. These estimates are based on features of the web pages such as the date in the title and URL. The default sort order is descending (pages with the most recent dates are returned first). To get ascending sort order, append:a
to thedate
value—for example,date:a
.