首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么更改maxResults会导致Google / Gmail中的结果总数发生变化?

为什么更改maxResults会导致Google / Gmail中的结果总数发生变化?
EN

Stack Overflow用户
提问于 2022-01-09 13:16:20
回答 1查看 111关注 0票数 0

为什么更改maxResults参数会导致resultSizeEstimate在调用gmail.users.messages.list()时发生剧烈变化

Google文档将resultSizeEstimate列表为:估计结果总数。

..。这意味着这个最终的结果集不应该仅仅通过改变每页返回的项目数而改变。

maxResults: 1 示例A: .

代码语言:javascript
复制
{
  "config": {
    "url": "https://www.googleapis.com/gmail/v1/users/me/messages?q=before%3A2021%2F1%2F9&maxResults=1",
    "method": "GET",
    "headers": {
      "Accept-Encoding": "gzip",
      "User-Agent": "google-api-nodejs-client/0.7.2 (gzip)",
      "Authorization": "Bearer [snip]",
      "Accept": "application/json"
    },
    "params": {
      "q": "before:2021/1/9",
      "maxResults": 1
    },
    "responseType": "json"
  },
  "data": {
    "messages": [ ... ],
    "nextPageToken": "14911817971227869758",
    "resultSizeEstimate": 8
  },
  "headers": {
    "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
    "cache-control": "private",
    "connection": "close",
    "content-encoding": "gzip",
    "content-type": "application/json; charset=UTF-8",
    "date": "Sun, 09 Jan 2022 12:59:48 GMT",
    "server": "ESF",
    "transfer-encoding": "chunked",
    "vary": "Origin, X-Origin, Referer",
    "x-content-type-options": "nosniff",
    "x-frame-options": "SAMEORIGIN",
    "x-xss-protection": "0"
  },
  "status": 200,
  "statusText": "OK"
}

maxResults: 2 示例B: .

代码语言:javascript
复制
{
  "config": {
    "url": "https://www.googleapis.com/gmail/v1/users/me/messages?q=before%3A2021%2F1%2F9&maxResults=2",
    "method": "GET",
    "headers": {
      "Accept-Encoding": "gzip",
      "User-Agent": "google-api-nodejs-client/0.7.2 (gzip)",
      "Authorization": "Bearer [snip]",
      "Accept": "application/json"
    },
    "params": {
      "q": "before:2021/1/9",
      "maxResults": 2
    },
    "responseType": "json"
  },
  "data": {
    "messages": [ ... ],
    "nextPageToken": "16903415066875011466",
    "resultSizeEstimate": 12
  },
  "headers": {
    "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
    "cache-control": "private",
    "connection": "close",
    "content-encoding": "gzip",
    "content-type": "application/json; charset=UTF-8",
    "date": "Sun, 09 Jan 2022 13:10:48 GMT",
    "server": "ESF",
    "transfer-encoding": "chunked",
    "vary": "Origin, X-Origin, Referer",
    "x-content-type-options": "nosniff",
    "x-frame-options": "SAMEORIGIN",
    "x-xss-protection": "0"
  },
  "status": 200,
  "statusText": "OK"
}

maxResults: (not set)示例C: .

代码语言:javascript
复制
{
  "config": {
    "url": "https://www.googleapis.com/gmail/v1/users/me/messages?q=before%3A2021%2F1%2F9",
    "method": "GET",
    "headers": {
      "Accept-Encoding": "gzip",
      "User-Agent": "google-api-nodejs-client/0.7.2 (gzip)",
      "Authorization": "Bearer [snip]",
      "Accept": "application/json"
    },
    "params": {
      "q": "before:2021/1/9"
    },
    "responseType": "json"
  },
  "data": {
    "messages": [ ... ],
    "nextPageToken": "16942818266524948378",
    "resultSizeEstimate": 412
  },
  "headers": {
    "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
    "cache-control": "private",
    "connection": "close",
    "content-encoding": "gzip",
    "content-type": "application/json; charset=UTF-8",
    "date": "Sun, 09 Jan 2022 13:09:05 GMT",
    "server": "ESF",
    "transfer-encoding": "chunked",
    "vary": "Origin, X-Origin, Referer",
    "x-content-type-options": "nosniff",
    "x-frame-options": "SAMEORIGIN",
    "x-xss-protection": "0"
  },
  "status": 200,
  "statusText": "OK"
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-10 08:59:48

此前曾在“问题跟踪器”中报道过这一点,谷歌认为这是有意的行为,因为人们预计resultSizeEstimate并不准确;这是一个“估计”:

resultSizeEstimate显示不同值的原因在于它的估计。正如在resultSizeEstimate中提到的,文档只是估计结果的总数,而不是结果的确切数量。

参考资料:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70641645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档