管理已保存的查询

借助已保存查询 API,您可以通过编程方式管理保险柜中已保存的查询。您可以运行已保存的查询来检索相同结果或更多更新的结果,具体取决于查询的条件。例如,如果您的查询包含结束日期,检索到的结果与首次运行查询时得到的结果相同。如果查询不包含结束日期,您将得到原始结果以及任何符合搜索条件的新数据。

您可以在脚本中使用此 API:

  • 在诉讼或调查中创建已保存的查询
  • 删除诉讼或调查中已保存的查询
  • 从诉讼或调查中检索已保存的查询
  • 检索诉讼或调查中所有已保存的查询

要使用保险柜资源,账号必须拥有所需的保险柜 权限以及对 至关重要。要访问某个诉讼或调查,该账号必须是该诉讼或调查的创建者,且拥有该诉讼或调查的 或拥有查看所有诉讼或调查的权限。

创建已保存的搜索查询

以下示例展示了如何为邮件和云端硬盘中的文件创建已保存的查询:

邮件

Java

public SavedQuery createMailAllDataAccountSavedQuery(String matterId) throws Exception {
    AccountInfo emailsToSearch =
        new AccountInfo().setEmails((ImmutableList.of("email1", "email2")));
    MailOptions mailOptions = new MailOptions().setExcludeDrafts(true);
    String queryTerms = "to:ceo@solarmora.com";
    Query mailQuery =
        new Query()
            .setCorpus("MAIL")
            .setDataScope("ALL_DATA")
            .setSearchMethod("ACCOUNT")
            .setAccountInfo(emailsToSearch)
            .setTerms(queryTerms)
            .setMailOptions(mailOptions);
    SavedQuery savedQuery =
        new SavedQuery()
            .setDisplayName("NEW SAVED QUERY NAME")
            .setQuery(mailQuery);
    return client.matters().savedQueries().create(matterId, savedQuery).execute();
} 

Python

def create_mail_all_data_account_saved_query(self, 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,
    }
    saved_query = {
        'displayName': 'NEW SAVED QUERY NAME',
        'query': mail_query,
    }
    return self.service.matters().savedQueries().create(
        matterId=matter_id, body=saved_query).execute()

云端硬盘

Java

public SavedQuery createDriveAllDataOUSavedQuery(String matterId) throws Exception {
    OrgUnitInfo ouToSearch = new OrgUnitInfo().setOrgUnitId("ou id retrieved from admin sdk");
    DriveOptions driveQueryOptions = new DriveOptions().setIncludeTeamDrives(true);
    Query driveQuery =
        new Query()
            .setCorpus("DRIVE")
            .setDataScope("ALL_DATA")
            .setSearchMethod("ORG_UNIT")
            .setOrgUnitInfo(ouToSearch)
            .setDriveOptions(driveQueryOptions);
    SavedQuery savedQuery =
        new SavedQuery()
            .setDisplayName("NEW SAVED QUERY NAME")
            .setQuery(driveQuery);
    return client.matters().savedQueries().create(matterId, savedQuery).execute();
  }
} 

Python

def create_drive_all_data_ou_saved_query(self, matter_id):
    ou_to_search = 'ou id retrieved from admin sdk'
    drive_query_options = {'includeTeamDrives': True}
    drive_query = {
        'corpus': 'DRIVE',
        'dataScope': 'ALL_DATA',
        'searchMethod': 'ORG_UNIT',
        'orgUnitInfo': {
            'org_unit_id': ou_to_search,
        },
        'driveOptions': drive_query_options
    }
    saved_query = {
        'displayName': 'NEW SAVED QUERY NAME',
        'query': drive_query,
    }
    return self.service.matters().savedQueries().create(
        matterId=matter_id, body=saved_query).execute()

删除已保存的搜索查询

以下示例展示了如何删除已保存的查询。

Java

public Empty deleteSavedQuery(String matterId, String savedQueryId) throws Exception {
    return client.matters().savedQueries().delete(matterId, savedQueryId).execute();
} 

Python

def delete_saved_query(self, matter_id, saved_query_id):
    empty_response = self.service.matters().savedQueries().delete(
        matterId=matter_id, savedQueryId=saved_query_id).execute()
    return empty_response

获取已保存的搜索查询

以下示例展示了如何按 ID 检索已保存的查询。

Java

public SavedQuery getSavedQuery(String matterId, String savedQueryId) throws Exception {
    return client.matters().savedQueries().get(matterId, savedQueryId).execute();
} 

Python

def get_saved_query(self, matter_id, saved_query_id):
    saved_query = self.service.matters().savedQueries().get(
        matterId=matter_id, savedQueryId=saved_query_id).execute()
    return saved_query

列出诉讼或调查中已保存的查询

以下示例展示了如何列出诉讼或调查的已保存查询。

Java

public void listSavedQueries(String matterId) throws Exception {
    ListSavedQueriesResponse firstPageResponse =
        client.matters().savedQueries().list(matterId).setPageSize(10).execute();
    String nextPageToken = firstPageResponse.getNextPageToken();
    if (nextPageToken != null) {
      client
          .matters()
          .savedQueries()
          .list(matterId)
          .setPageSize(10)
          .setPageToken(nextPageToken)
          .execute();
    }
} 

Python

def list_saved_queries(self, matter_id):
    first_page_response = self.service.matters().savedQueries().list(
        matterId=matter_id, pageSize=10).execute()
    if 'nextPageToken' in first_page_response:
      self.service.matters().savedQueries().list(
          pageSize=10,
          pageToken=first_page_response['nextPageToken']).execute()