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

एक्सपोर्ट बनाने से पहले, 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"]