Đếm kết quả truy vấn

Bạn có thể sử dụng phương thức matters.count để đếm số lượng thư từ một cụm từ tìm kiếm trên Gmail hoặc Groups trước khi tạo tệp xuất. Với thông tin này, bạn có thể tinh chỉnh bộ lọc truy vấn để trả về nhiều hoặc ít kết quả hơn.

Để sử dụng các tài nguyên của Vault, tài khoản phải có các đặc quyền bắt buộc đối với Vault và quyền truy cập vào vấn đề. Để truy cập vào một vấn đề, tài khoản phải là tài khoản đã tạo vấn đề đó, được chia sẻ vấn đề đó hoặc có đặc quyền Xem tất cả vấn đề.

Ví dụ sau đây cho thấy cách đếm số kết quả do một truy vấn trả về cho những thông báo đáp ứng các tiêu chí sau:

  • tin nhắn thuộc sở hữu của tài khoản email1email2.
  • không bao gồm thư nháp.
  • tin nhắn gửi đến 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"]