统计查询结果
您可以在创建导出内容之前,使用 matters.count
方法统计 Gmail 或群组查询中的邮件数量。有了这些信息,您就可以优化查询过滤条件,以返回更多或更少的结果。
若要使用保险柜资源,该账号必须具有必要的保险柜权限,并且对相应事宜拥有访问权限。若要访问某项诉讼或调查,相应账号必须是该诉讼或调查的创建者、该诉讼或调查的共享对象,或者拥有查看所有诉讼或调查权限。
以下示例展示了如何针对符合以下条件的消息查询返回的结果进行计数:
- 账号
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"]