이 페이지에서는 특정 라벨 또는 필드 값이 있는 파일을 검색하는 방법을 설명합니다.
라벨 필드 유형
Google Drive 라벨 필드는 타입 지정 및 검색 시맨틱스를 지원하는 각 유형으로 철저하게 입력됩니다. 다음 표에는 사용 가능한 데이터 유형이 나와 있습니다.
유형 | 라벨 유형 옵션 | 지원되는 검색 연산자 |
---|---|---|
텍스트 | 텍스트 옵션 | is null, is not null, =, contains, starts with |
긴 텍스트 | LongTextOptions | is null, is not null, contains |
정수 | 정수 옵션 | is null, is not null, =, !=, <, >, <=, >= |
날짜 | 날짜 옵션 | is null, is not null, =, !=, <, >, <=, >= |
선택 | SelectionOptions | is null, is not null, =, != |
사용자 | 사용자 옵션 | is null, is not null, =, != |
선택 목록 | SelectionOptions (max_ entries > 1) | is null, is not null, in, not in |
사용자 목록 | UserOptions (max_ entries > 1) | is null, is not null, in, not in |
검색 예
1. 라벨 또는 필드의 존재를 기반으로 검색하기
특정 라벨이 적용되거나 적용되지 않은 항목을 검색할 수 있습니다.
'labels/contract' in labels
not 'labels/contract' in labels
특정 필드가 설정되어 있거나 설정되지 않은 항목도 검색할 수 있습니다.
labels/contract.comment IS NOT NULL
labels/contract.comment IS NULL
2. 단일 값 필드를 기반으로 검색
예상 필드 값과 일치하는 검색어를 작성할 수 있습니다. 다음 표에는 유효한 필드 쿼리가 나와 있습니다.
쿼리하려는 항목 | 쿼리 문자열 |
---|---|
댓글이 '안녕하세요'로 설정된 항목 | labels/contract.comment = 'hello' |
댓글이 'hello'로 시작하는 파일 | labels/contract.comment STARTS WITH 'hello' |
상태가 실행되는 파일 | labels/contract.status = 'executed' |
상태가 실행되지 않는 파일 | labels/contract.status != 'executed' |
run_date가 특정 날짜 이전인 파일 | labels/contract.execution_date < '2020-06-22' |
value_usd (정수)가 특정 값보다 작은 파일 | labels/contract.value_usd < 2000 |
client_contact가 특정 이메일 주소로 설정된 파일 | labels/contract.client_contact = 'alex@altostrat.com' |
3. 다중 값 필드가 있는 필드를 기준으로 검색합니다 (예: ListOptions.max_Entries > 1).
여러 값을 지원하는 필드는 IN 연산자를 사용해서만 쿼리할 수 있습니다.
'EMAIL_ADDRESS' IN labels/project.project_leads
NOT 'EMAIL_ADDRESS' IN labels/project.project_leads
예
이 예에서는 특정 라벨 또는 필드 값이 있는 모든 파일을 Google Drive 파일 리소스에서 나열하는 방법을 설명합니다.
응답에 labelInfo
를 포함하려면 다음과 같이 지정해야 합니다.
쉼표로 구분된
labelId
목록인includeLabels
fields
매개변수의labelInfo
를 사용하여 파일 응답에서labelInfo
를 반환하도록 지정합니다.
이 예에서는 하나 이상의 labelId
를 사용하여 요청된 라벨 정보와 일치하는 파일을 쿼리하고 반환합니다. files.list
메서드도 사용합니다.
자바
List<File> fileList = driveService.files().list().setIncludeLabels("LABEL_1_ID,LABEL_2_ID").setFields("items(labelInfo, id)").setQ("'labels/LABEL_1_ID' in labels and 'labels/LABEL_2_ID' in labels").execute().getItems();
Python
file_list = drive_service.files().list(includeLabels="LABEL_1_ID,LABEL_2_ID", q="'labels/LABEL_1_ID' in labels and 'labels/LABEL_2_ID' in labels", fields="items(labelInfo, id)");
Node.js
/**
* Search for Drive files with specific labels
* @return{obj} file list with labelInfo
**/
async function getFileWithSpecificLabels() {
// Get credentials and build service
// TODO (developer) - Use appropriate auth mechanism for your app
const {GoogleAuth} = require('google-auth-library');
const {google} = require('googleapis');
const auth = new GoogleAuth({scopes: 'https://www.googleapis.com/auth/drive'});
const service = google.drive({version: 'v3', auth});
try {
const fileList = await service.files.list({
includeLabels: 'LABEL_1_ID,LABEL_2_ID',
q: '\'labels/LABEL_1_ID\' in labels and \'labels/LABEL_2_ID\' in labels',
fields:'files(labelInfo, id)',
});
return file;
} catch (err) {
// TODO (developer) - Handle error
throw err;
}
}