इस पेज पर, किसी खास लेबल या फ़ील्ड वैल्यू वाली फ़ाइलों को खोजने का तरीका बताया गया है.
लेबल फ़ील्ड के टाइप
Google Drive के लेबल फ़ील्ड, अलग-अलग टाइप के होते हैं. हर टाइप, इंडेक्सिंग और खोज के अलग-अलग सिमैंटिक के साथ काम करता है. यहां दी गई टेबल में, उपलब्ध डेटा टाइप दिखाए गए हैं.
| टाइप | लेबल के टाइप के विकल्प | सर्च ऑपरेटर इस्तेमाल किए जा सकते हैं |
|---|---|---|
| टेक्स्ट | TextOptions | is null, is not null, =, contains, starts with |
| लंबा टेक्स्ट | LongTextOptions | is null, is not null, contains |
| पूर्णांक | 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. सिंगल वैल्यू वाले फ़ील्ड के आधार पर खोज करना
आपको फ़ील्ड की अनुमानित वैल्यू से मैच करने के लिए, खोज क्वेरी लिखने का विकल्प मिलता है. यहां दी गई टेबल में, फ़ील्ड के लिए मान्य क्वेरी दिखाई गई हैं:
| आपको किस बारे में क्वेरी करनी है | क्वेरी स्ट्रिंग |
|---|---|
| ऐसे आइटम जिन पर टिप्पणी "नमस्ते" के तौर पर सेट की गई है | 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.