管理已儲存的查詢

您可以透過已儲存的查詢 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()