क्वेरी के नतीजों की गिनती करना

एक्सपोर्ट बनाने से पहले, Gmail या Groups की क्वेरी से मिले मैसेज की संख्या गिनने के लिए, matters.count तरीके का इस्तेमाल किया जा सकता है. इस जानकारी की मदद से, क्वेरी फ़िल्टर को बेहतर बनाया जा सकता है, ताकि ज़्यादा या कम नतीजे मिल सकें.

Vault के संसाधनों का इस्तेमाल करने के लिए, खाते के पास Vault के ज़रूरी अधिकार होने चाहिए. साथ ही, उसके पास मामले का ऐक्सेस भी होना चाहिए. किसी मामले को ऐक्सेस करने के लिए, खाते से मामला बनाया गया हो, मामला उसके साथ शेयर किया गया हो या उसके पास सभी मामले देखें का अधिकार हो.

यहां दिए गए उदाहरण में, उन मैसेज के लिए क्वेरी से मिले नतीजों को गिनने का तरीका बताया गया है जो इन शर्तों को पूरा करते हैं:

  • 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"]