با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
شمارش نتایج پرس و جو
قبل از ایجاد صادرات، میتوانید از روش matters.count
برای شمارش پیامهای یک جستار Gmail یا Groups استفاده کنید. با استفاده از این اطلاعات، می توانید فیلترهای پرس و جو خود را برای بازگشت نتایج کم و بیش اصلاح کنید.
برای کار با منابع Vault، حساب باید دارای امتیازات Vault مورد نیاز و دسترسی به موضوع باشد. برای دسترسی به یک موضوع، حساب باید موضوع را ایجاد کرده باشد، موضوع را با آنها به اشتراک گذاشته باشد، یا دارای امتیاز View All Matters باشد.
مثال زیر نشان می دهد که چگونه می توان نتایج بازگردانده شده توسط یک پرس و جو را برای پیام هایی که دارای معیارهای زیر هستند شمارش کرد:
- پیام های متعلق به حساب های
email1
و email2
. - پیام های پیش نویس را مستثنی می کند.
- پیام های ارسال شده به
ceo@solarmora.com
.
جاوا
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;
}
پایتون
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"]
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["Count query results\n-------------------\n\nYou can use the `matters.count` method to count the messages from a Gmail or Groups query before you create an export. With this information, you can refine your query filters to return more or less results.\n\nTo work with Vault resources, the account must have the [required Vault\nprivileges](https://support.google.com/vault/answer/2799699) and access to the\nmatter. To access a matter, the account must have created the matter, have the\nmatter shared with them, or have the **View All Matters** privilege.\n\nThe following example shows how to count the results returned by a query for messages that meet the following criteria:\n\n- messages owned by accounts `email1` and `email2`.\n- excludes draft messages.\n- messages sent to `ceo@solarmora.com`.\n\n### Java\n\n```java\npublic Long count(Vault client, String matterId) {\n AccountInfo emailsToSearch = new AccountInfo().setEmails(ImmutableList.of(\"email1\", \"email2\"));\n MailOptions mailQueryOptions = new MailOptions().setExcludeDrafts(true);\n String queryTerms = \"to:ceo@solarmora.com\";\n Query query =\n new Query()\n .setCorpus(\"MAIL\")\n .setDataScope(\"ALL_DATA\")\n .setSearchMethod(\"ACCOUNT\")\n .setAccountInfo(emailsToSearch)\n .setTerms(queryTerms);\n CountArtifactsRequest request = new CountArtifactsRequest().setQuery(query);\n Operation operation = client.matters().count(matterId, request).execute();\n\n while(!operation.getDone()) {\n sleep(2000);\n operation = service.operations().get(operation.getName()).execute();\n }\n if(operation.getResponse() != null) {\n return Long.parseLong(operation.getResponse.get(\"total_count\").toString());\n }\n return -1;\n}\n \n```\n\n### Python\n\n```python\ndef count(service, matter_id):\n emails_to_search = ['email1', 'email2']\n mail_query_options = {'excludeDrafts': True}\n query_terms = 'to:ceo@solarmora.com'\n mail_query = {\n 'corpus': 'MAIL',\n 'dataScope': 'ALL_DATA',\n 'searchMethod': 'ACCOUNT',\n 'accountInfo': {\n 'emails': emails_to_search\n },\n 'terms': query_terms,\n 'mailOptions': mail_query_options,\n }\n request = {\n 'query': mail_query\n }\n operation = service.matters().count(matterId=matter_id, body=request).execute()\n\n while not operation.getDone():\n time.sleep(2)\n operation = service.operations().get(name=operation.getName()).execute()\n\n if operation.getResponse() is None:\n return -1\n\n return operation.getResponse()[\"total_count\"]\n \n```"]]