管理已保存的查询

借助已保存的查询 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()