使用自动和手动刷新功能刷新网页

如果您的数据存储区使用基本网站搜索,那么您商店的索引的新鲜度与 Google 搜索中的新鲜度相同。

如果您的数据存储区中启用了高级网站索引编制,系统会以以下方式刷新数据存储区中的网页:

  • 自动刷新
  • 手动刷新
  • 基于站点地图的刷新

本页介绍了自动刷新和手动刷新。如需了解和实现基于站点地图的刷新,请参阅根据站点地图编制索引和刷新。

准备工作

如果您在网站中使用 robots.txt 文件,请更新该文件。如需了解详情,请参阅如何准备网站的 robots.txt 文件。

自动刷新

Agent Search 会按如下方式自动刷新:

  • 创建数据存储区后,系统会为其中包含的网页生成初始索引。
  • 在初始索引编制完成后,它会尽最大努力对任何新发现的网页进行索引编制,并重新抓取现有网页。
  • 如果数据存储的查询率为 50 次查询/30 天,则会定期刷新该数据存储。

手动刷新

如果您想刷新已启用高级网站索引编制的数据存储区中的特定网页,可以调用 recrawlUris 方法。您可以使用 uris 字段指定要抓取的每个网页。recrawlUris 方法是一种长时间运行的操作,它会一直运行,直到系统抓取您指定的网页或在 24 小时后超时(以先到者为准)。如果 recrawlUris 方法超时,您可以再次调用该方法,并指定仍需抓取的网页。您可以轮询 operations.get 方法,以监控重新抓取操作的状态。

重新抓取的限制

您可以抓取网页的频率以及一次可以抓取的网页数量存在限制:

  • 每天的通话次数。每个项目每天允许调用 recrawlUris 方法的次数上限为 20 次。
  • 每次通话的网页数。您可以通过调用 recrawlUris 方法指定的 uris 值数量上限为 10,000。

重新抓取数据存储区中的网页

您可以手动抓取已开启高级网站索引编制的数据存储区中的特定网页。

REST

如需使用命令行抓取数据存储区中的特定网页,请按以下步骤操作:

  1. 查找您的数据存储区 ID。如果您已有数据存储区 ID,请跳至下一步。

    1. 在 Google Cloud 控制台中,前往 AI Applications 页面,然后在导航菜单中点击数据存储区。

      前往“数据存储区”页面

    2. 点击您的数据存储区的名称。

    3. 在数据存储区的数据页面上,获取数据存储区 ID。

  2. 调用 recrawlUris 方法,并使用 uris 字段指定要抓取的每个网页。每个 uri 都表示一个网页,即使其中包含星号 (*) 也是如此。系统不支持通配符模式。

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1alpha/projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/siteSearchEngine:recrawlUris" \
    -d '{
      "uris": [URIS]
    }'
    

    替换以下内容:

    • PROJECT_ID:您的 Google Cloud 项目的 ID。
    • DATA_STORE_ID:Agent Search 数据存储区的 ID。
    • URIS:要抓取的网页列表,例如 "https://example.com/page-1", "https://example.com/page-2", "https://example.com/page-3"。

    输出类似于以下内容:

    {
      "name": "projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/operations/recrawl-uris-0123456789012345678",
      "metadata": {
        "@type": "type.googleapis.com/google.cloud.discoveryengine.v1alpha.RecrawlUrisMetadata"
      }
    }
    
  3. 在监控重新抓取操作的状态时,请保存 name 值,以作为 operations.get 操作的输入。

监控重新抓取操作的状态

您用于抓取数据存储区中的网页的 recrawlUris 方法是一种长时间运行的操作,它会一直运行,直到抓取完您指定的网页或在 24 小时后超时(以先到者为准)。您可以通过轮询 operations.get 方法来监控此长时间运行的操作的状态,并指定 recrawlUris 方法返回的 name 值。继续轮询,直到响应表明以下任一情况:(1) 所有网页都已抓取完毕;(2) 在所有网页都抓取完毕之前,操作已超时。如果 recrawlUris 超时,您可以再次调用它,并指定未被抓取的网站。

REST

如需使用命令行监控重新抓取操作的状态,请按以下步骤操作:

  1. 查找您的数据存储区 ID。如果您已有数据存储区 ID,请跳至下一步。

    1. 在 Google Cloud 控制台中,前往 AI Applications 页面,然后在导航菜单中点击数据存储区。

      前往“数据存储区”页面

    2. 点击您的数据存储区的名称。

    3. 在数据存储区的数据页面上,获取数据存储区 ID。

  2. 轮询 operations.get 方法。

    curl -X GET \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -H "X-Goog-User-Project: PROJECT_ID" \
    "https://discoveryengine.googleapis.com/v1alpha/OPERATION_NAME"
    

    替换以下内容:

  3. 评估每个回答。

    • 如果响应表明存在待处理的 URI,并且重新抓取操作尚未完成,则表示您的网页仍在被抓取。继续轮询。

      示例

        {
          "name": "projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/operations/recrawl-uris-0123456789012345678",
          "metadata": {
            "@type": "type.googleapis.com/google.cloud.discoveryengine.v1alpha.RecrawlUrisMetadata",
            "createTime": "2023-09-05T22:07:28.690950Z",
            "updateTime": "2023-09-05T22:22:10.978843Z",
            "validUrisCount": 4000,
            "successCount": 2215,
            "pendingCount": 1785
          },
          "done": false,
          "response": {
            "@type": "type.googleapis.com/google.cloud.discoveryengine.v1alpha.RecrawlUrisResponse",
          }
        }

      响应字段的说明如下:

      • createTime:表示长时间运行的操作的开始时间。
      • updateTime:表示上次更新长时间运行的操作元数据的时间。表示元数据每 5 分钟更新一次,直到操作完成。
      • validUrisCount:表示您在对 recrawlUris 方法的调用中指定了 4,000 个有效的 URI。
      • successCount:表示已成功抓取 2,215 个 URI。
      • pendingCount:表示有 1,785 个 URI 尚未被抓取。
      • done:值为 false 表示重新抓取操作仍在进行中。

    • 如果响应表明没有待处理的 URI(未返回 pendingCount 字段),并且重新抓取操作已完成,则表示您的网页已被抓取。停止轮询 - 您可以退出此程序。

      示例

        {
          "name": "projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/operations/recrawl-uris-0123456789012345678",
          "metadata": {
            "@type": "type.googleapis.com/google.cloud.discoveryengine.v1alpha.RecrawlUrisMetadata",
            "createTime": "2023-09-05T22:07:28.690950Z",
            "updateTime": "2023-09-05T22:37:11.367998Z",
            "validUrisCount": 4000,
            "successCount": 4000
          },
          "done": true,
          "response": {
            "@type": "type.googleapis.com/google.cloud.discoveryengine.v1alpha.RecrawlUrisResponse"
          }
        }

      响应字段的说明如下:

      • createTime:表示长时间运行的操作的开始时间。
      • updateTime:表示上次更新长时间运行的操作元数据的时间。表示元数据每 5 分钟更新一次,直到操作完成。
      • validUrisCount:表示您在对 recrawlUris 方法的调用中指定了 4,000 个有效的 URI。
      • successCount:表示已成功抓取 4,000 个 URI。
      • done:值为 true 表示重新抓取操作已完成。
  4. 如果响应表明存在待处理的 URI,并且重新抓取操作已完成,则表示重新抓取操作在抓取所有网页之前超时(24 小时后)。从重新抓取数据存储区中的网页开始。在对 recrawlUris 方法的新调用中,使用 operations.get 响应中的 failedUris 值作为 uris 字段中的值。

    Example.

    {
      "name": "projects/PROJECT_ID/locations/global/collections/default_collection/dataStores/DATA_STORE_ID/operations/recrawl-uris-8765432109876543210",
      "metadata": {
        "@type": "type.googleapis.com/google.cloud.discoveryengine.v1alpha.RecrawlUrisMetadata",
        "createTime": "2023-09-05T22:07:28.690950Z",
        "updateTime": "2023-09-06T22:09:10.613751Z",
        "validUrisCount": 10000,
        "successCount": 9988,
        "pendingCount": 12
      },
      "done": true,
      "response": {
        "@type": "type.googleapis.com/google.cloud.discoveryengine.v1alpha.RecrawlUrisResponse",
        "failedUris": [
          "https://example.com/page-9989",
          "https://example.com/page-9990",
          "https://example.com/page-9991",
          "https://example.com/page-9992",
          "https://example.com/page-9993",
          "https://example.com/page-9994",
          "https://example.com/page-9995",
          "https://example.com/page-9996",
          "https://example.com/page-9997",
          "https://example.com/page-9998",
          "https://example.com/page-9999",
          "https://example.com/page-10000"
        ],
        "failureSamples": [
          {
            "uri": "https://example.com/page-9989",
            "failureReasons": [
              {
                "corpusType": "DESKTOP",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              },
              {
                "corpusType": "MOBILE",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              }
            ]
          },
          {
            "uri": "https://example.com/page-9990",
            "failureReasons": [
              {
                "corpusType": "DESKTOP",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              },
              {
                "corpusType": "MOBILE",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              }
            ]
          },
          {
            "uri": "https://example.com/page-9991",
            "failureReasons": [
              {
                "corpusType": "DESKTOP",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              },
              {
                "corpusType": "MOBILE",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              }
            ]
          },
          {
            "uri": "https://example.com/page-9992",
            "failureReasons": [
              {
                "corpusType": "DESKTOP",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              },
              {
                "corpusType": "MOBILE",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              }
            ]
          },
          {
            "uri": "https://example.com/page-9993",
            "failureReasons": [
              {
                "corpusType": "DESKTOP",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              },
              {
                "corpusType": "MOBILE",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              }
            ]
          },
          {
            "uri": "https://example.com/page-9994",
            "failureReasons": [
              {
                "corpusType": "DESKTOP",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              },
              {
                "corpusType": "MOBILE",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              }
            ]
          },
          {
            "uri": "https://example.com/page-9995",
            "failureReasons": [
              {
                "corpusType": "DESKTOP",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              },
              {
                "corpusType": "MOBILE",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              }
            ]
          },
          {
            "uri": "https://example.com/page-9996",
            "failureReasons": [
              {
                "corpusType": "DESKTOP",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              },
              {
                "corpusType": "MOBILE",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              }
            ]
          },
          {
            "uri": "https://example.com/page-9997",
            "failureReasons": [
              {
                "corpusType": "DESKTOP",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              },
              {
                "corpusType": "MOBILE",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              }
            ]
          },
          {
            "uri": "https://example.com/page-9998",
            "failureReasons": [
              {
                "corpusType": "DESKTOP",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              },
              {
                "corpusType": "MOBILE",
                "errorMessage": "Page was crawled but was not indexed by UCS within 24 hours."
              }
            ]
          }
        ]
      }
    }

    以下是部分响应字段的说明:

    • createTime. 长时间运行的操作的开始时间。
    • updateTime。长时间运行的操作元数据的上次更新时间。元数据每 5 分钟更新一次,直到操作完成。
    • validUrisCount。表示您在对 recrawlUris 方法的调用中指定了 10,000 个有效的 URI。
    • successCount。表示已成功抓取 9,988 个 URI。
    • pendingCount. 表示有 12 个 URI 尚未被抓取。
    • done。值为 true 表示重新抓取操作已完成。
    • failedUris。在重新抓取操作超时之前未抓取的 URI 列表。
    • failureInfo. 有关未能成功抓取的 URI 的信息。即使有超过 10 个 URI 无法抓取,系统最多也只会返回 10 个 failureInfo 数组值。
    • errorMessage。URI 无法被 corpusType 抓取的原因。如需了解详情,请参阅错误消息。

及时刷新

Google 建议您对新网页和更新后的网页执行手动刷新,以确保您拥有最新的索引。

错误消息

当您监控重新抓取操作的状态时,如果在您轮询 operations.get 方法时重新抓取操作超时,operations.get 会针对未抓取的网页返回错误消息。下表列出了错误消息、错误是否为暂时性错误(可自行解决的临时错误),以及在重试 recrawlUris 方法之前可以采取的操作。您可以立即重试所有暂时性错误。在实施补救措施后,可以重试所有非暂时性错误。

错误消息 是否为暂时性错误? 在重试重新抓取之前采取的操作
网页已被抓取,但未在 24 小时内被 Agent Search 编入索引 是 调用 recrawlUris 方法时,请使用 operations.get 响应中的 failedUris 值作为 uris 字段中的值。
网站的 robots.txt 阻止了抓取 否 在网站的 robots.txt 文件中取消屏蔽相应 URI,确保允许 Google-CloudVertexBot 用户代理抓取网站,然后重试重新抓取。如需了解详情,请参阅准备数据以便提取中的网站数据。如果您无法访问 robots.txt 文件,请与网域所有者联系。
网页无法访问 否 检查您在调用 recrawlUris 方法时指定的 URI。请确保您提供的是字面 URI,而不是 URI 模式。
抓取超时 是 调用 recrawlUris 方法时,请使用 operations.get 响应中的 failedUris 值作为 uris 字段中的值。
网页被 Google 抓取工具拒绝 是 调用 recrawlUris 方法时,请使用 operations.get 响应中的 failedUris 值作为 uris 字段中的值。
Google 抓取工具无法跟踪相应网址 否 如果存在多次重定向,请使用最后一次重定向中的 URI 并重试
找不到网页 (404) 否 检查您在调用 recrawlUris 方法时指定的 URI。请确保您提供的是字面 URI,而不是 URI 模式。

任何返回“4xx”错误代码的网页都会从索引中移除。

网页需要身份验证 否 高级网站索引编制功能不支持抓取需要进行身份验证的网页。

已删除网页的处理方式

删除网页后,Google 建议您手动刷新已删除的网址。

在自动或手动刷新期间,如果抓取工具抓取您的网站数据存储区时,某个网页返回 4xx 客户端错误代码或 5xx 服务器错误代码,则该无响应的网页会从索引中移除。

如果数据存储区设置为站点地图模式为精确,那么从站点地图中移除网址会从索引中删除该网址。

如果数据存储区设置为 Sitemap Mode 为 Discovery,那么从站点地图中移除网址不会从索引中删除该网址。在抓取相应网站且网页返回 4xx 或 5xx 代码之前,系统不会从索引中删除相应网址。