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

Bạn có thể sử dụng phương thức matters.count để đếm thư từ một truy vấn trong 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 cụm từ tìm kiếm để 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 nội dung. Để truy cập vào một vấn đề, tài khoản phải đã tạo vấn đề, chia sẻ vấn đề với họ hoặc có đặc quyền Xem tất cả các vấn đề.

Ví dụ sau đây cho thấy cách tính kết quả mà truy vấn trả về cho thư đá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.
  • đã gửi tin nhắn tới 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"]