इस पेज पर, किसी खास लेबल या फ़ील्ड वैल्यू वाले फ़ाइलें खोजने का तरीका बताया गया है.
लेबल फ़ील्ड के टाइप
Google Drive के लेबल फ़ील्ड, अलग-अलग टाइप के होते हैं. हर टाइप के लिए, इंडेक्सिंग और खोज के अलग-अलग सिमैंटिक इस्तेमाल किए जाते हैं. यहां दी गई टेबल में, उपलब्ध डेटा टाइप दिखाए गए हैं.
| टाइप | लेबल टाइप के विकल्प | सर्च के लिए इस्तेमाल किए जा सकने वाले ऑपरेटर |
|---|---|---|
| टेक्स्ट | TextOptions | is null, is not null, =, contains, starts with |
| पूर्णांक | IntegerOptions | is null, is not null, =, !=, <, >, <=, >= |
| तारीख | DateOptions | is null, is not null, =, !=, <, >, <=, >= |
| चुनें | SelectionOptions | is null, is not null, =, != |
| उपयोगकर्ता | UserOptions | is null, is not null, =, != |
| चुनी गई वैल्यू की सूची | SelectionOptions (with max_entries > 1) | is null, is not null, in, not in |
| उपयोगकर्ता सूची | UserOptions (with max_entries > 1) | is null, is not null, in, not in |
सर्च क्वेरी के उदाहरण
1. किसी लेबल या फ़ील्ड के मौजूद होने या न होने के आधार पर खोज करना
उन आइटम को खोजा जा सकता है जिन पर कोई खास लेबल लागू किया गया हो या न किया गया हो:
'labels/contract' in labelsnot 'labels/contract' in labels
उन आइटम को भी खोजा जा सकता है जिनमें कोई खास फ़ील्ड सेट किया गया हो या न किया गया हो:
labels/contract.comment IS NOT NULLlabels/contract.comment IS NULL
2. सिंगल-वैल्यू वाले फ़ील्ड के आधार पर खोज करना
सर्च क्वेरी लिखकर, फ़ील्ड की अनुमानित वैल्यू से मैच किया जा सकता है. यहां दी गई टेबल में, फ़ील्ड की मान्य क्वेरी दिखाई गई हैं:
| आप किस बारे में क्वेरी करना चाहते हैं | क्वेरी स्ट्रिंग |
|---|---|
| वे आइटम जिनमें टिप्पणी "hello" पर सेट है | labels/contract.comment = 'hello' |
| वे फ़ाइलें जिनमें टिप्पणी "hello" से शुरू होती है | labels/contract.comment STARTS WITH 'hello' |
| वे फ़ाइलें जिनका स्टेटस 'पूरा हुआ' है | labels/contract.status = 'executed' |
| वे फ़ाइलें जिनका स्टेटस 'पूरा नहीं हुआ' है | labels/contract.status != 'executed' |
| वे फ़ाइलें जिनकी execution_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_leadsNOT 'EMAIL_ADDRESS' IN labels/project.project_leads
उदाहरण
यहां दिए गए कोड के सैंपल में, Drive के फ़ाइल
संसाधन से किसी खास लेबल या फ़ील्ड वैल्यू वाली सभी
फ़ाइलों की सूची बनाने के लिए, एक या एक से ज़्यादा labelId का इस्तेमाल करने का तरीका दिखाया गया है. इसमें,
files.list तरीके का भी इस्तेमाल किया गया है. अनुरोध का मुख्य हिस्सा खाली होना चाहिए.
अगर आपको जवाब में labelInfo शामिल करना है, तो आपको यह भी बताना होगा:
includeLabelsकॉमा से अलग की गई आईडी की सूची के तौर पर.fieldsपैरामीटर मेंlabelInfo, ताकि यह पता चले कि आपकोincludeLabelsमेंlabelInfoचाहिए.
अनुरोध पूरा होने पर, जवाब के मुख्य हिस्से में फ़ाइलों की सूची दिखती है.
Java
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)").execute();
Node.js
/**
* Search for Drive files with specific labels
* @return{obj} file list with labelInfo
**/
async function searchForFileWithLabels() {
// 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;
}
इनकी जगह ये डालें:
- LABEL_1_ID: लौटाए जाने वाले लेबल का पहला
labelId. - LABEL_2_ID: लौटाए जाने वाले लेबल का दूसरा
labelId.