管理已儲存的查詢

已儲存的查詢 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()