使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
统计查询结果
您可以使用 matters.count
方法来统计 Gmail 或 Google 群组查询中的邮件数量,然后再创建导出内容。有了这些信息,您就可以优化查询过滤条件,以返回更多或更少的搜索结果。
如需使用保险柜资源,相应账号必须拥有所需的保险柜权限,并且能够访问相应事宜。如需访问诉讼或调查,相应账号必须已创建该诉讼或调查、已与该账号共享该诉讼或调查,或者该账号拥有查看所有诉讼或调查的权限。
以下示例展示了如何统计查询返回的结果,这些结果是满足以下条件的消息:
- 归账号
email1
和 email2
所有的消息。
- 排除邮件草稿。
- 发送给
ceo@solarmora.com
的消息。
Java
public Long count(Vault client, String matterId) {
AccountInfo emailsToSearch = new AccountInfo().setEmails(ImmutableList.of("email1", "email2"));
MailOptions mailQueryOptions = new MailOptions().setExcludeDrafts(true);
String queryTerms = "to:ceo@solarmora.com";
Query query =
new Query()
.setCorpus("MAIL")
.setDataScope("ALL_DATA")
.setSearchMethod("ACCOUNT")
.setAccountInfo(emailsToSearch)
.setTerms(queryTerms);
CountArtifactsRequest request = new CountArtifactsRequest().setQuery(query);
Operation operation = client.matters().count(matterId, request).execute();
while(!operation.getDone()) {
sleep(2000);
operation = service.operations().get(operation.getName()).execute();
}
if(operation.getResponse() != null) {
return Long.parseLong(operation.getResponse.get("total_count").toString());
}
return -1;
}
Python
def count(service, matter_id):
emails_to_search = ['email1', 'email2']
mail_query_options = {'excludeDrafts': True}
query_terms = 'to:ceo@solarmora.com'
mail_query = {
'corpus': 'MAIL',
'dataScope': 'ALL_DATA',
'searchMethod': 'ACCOUNT',
'accountInfo': {
'emails': emails_to_search
},
'terms': query_terms,
'mailOptions': mail_query_options,
}
request = {
'query': mail_query
}
operation = service.matters().count(matterId=matter_id, body=request).execute()
while not operation.getDone():
time.sleep(2)
operation = service.operations().get(name=operation.getName()).execute()
if operation.getResponse() is None:
return -1
return operation.getResponse()["total_count"]
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["Count query results\n-------------------\n\nYou can use the `matters.count` method to count the messages from a Gmail or Groups query before you create an export. With this information, you can refine your query filters to return more or less results.\n\nTo work with Vault resources, the account must have the [required Vault\nprivileges](https://support.google.com/vault/answer/2799699) and access to the\nmatter. To access a matter, the account must have created the matter, have the\nmatter shared with them, or have the **View All Matters** privilege.\n\nThe following example shows how to count the results returned by a query for messages that meet the following criteria:\n\n- messages owned by accounts `email1` and `email2`.\n- excludes draft messages.\n- messages sent to `ceo@solarmora.com`.\n\n### Java\n\n```java\npublic Long count(Vault client, String matterId) {\n AccountInfo emailsToSearch = new AccountInfo().setEmails(ImmutableList.of(\"email1\", \"email2\"));\n MailOptions mailQueryOptions = new MailOptions().setExcludeDrafts(true);\n String queryTerms = \"to:ceo@solarmora.com\";\n Query query =\n new Query()\n .setCorpus(\"MAIL\")\n .setDataScope(\"ALL_DATA\")\n .setSearchMethod(\"ACCOUNT\")\n .setAccountInfo(emailsToSearch)\n .setTerms(queryTerms);\n CountArtifactsRequest request = new CountArtifactsRequest().setQuery(query);\n Operation operation = client.matters().count(matterId, request).execute();\n\n while(!operation.getDone()) {\n sleep(2000);\n operation = service.operations().get(operation.getName()).execute();\n }\n if(operation.getResponse() != null) {\n return Long.parseLong(operation.getResponse.get(\"total_count\").toString());\n }\n return -1;\n}\n \n```\n\n### Python\n\n```python\ndef count(service, matter_id):\n emails_to_search = ['email1', 'email2']\n mail_query_options = {'excludeDrafts': True}\n query_terms = 'to:ceo@solarmora.com'\n mail_query = {\n 'corpus': 'MAIL',\n 'dataScope': 'ALL_DATA',\n 'searchMethod': 'ACCOUNT',\n 'accountInfo': {\n 'emails': emails_to_search\n },\n 'terms': query_terms,\n 'mailOptions': mail_query_options,\n }\n request = {\n 'query': mail_query\n }\n operation = service.matters().count(matterId=matter_id, body=request).execute()\n\n while not operation.getDone():\n time.sleep(2)\n operation = service.operations().get(name=operation.getName()).execute()\n\n if operation.getResponse() is None:\n return -1\n\n return operation.getResponse()[\"total_count\"]\n \n```"]]