इस पेज पर, किसी खास लेबल या फ़ील्ड वैल्यू वाली फ़ाइलों को खोजने का तरीका बताया गया है.
लेबल फ़ील्ड के टाइप
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 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' |
ऐसी फ़ाइलें जिनमें 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_leads
NOT 'EMAIL_ADDRESS' IN labels/project.project_leads
उदाहरण
यहां दिए गए कोड के सैंपल में, Drive फ़ाइल रिसोर्स से किसी खास लेबल या फ़ील्ड वैल्यू वाली सभी फ़ाइलों की सूची बनाने के लिए, एक या उससे ज़्यादा labelId
इस्तेमाल करने का तरीका दिखाया गया है. यह files.list
तरीके का भी इस्तेमाल करता है. अनुरोध का मुख्य हिस्सा खाली होना चाहिए.
अगर आपको जवाब में labelInfo
शामिल करना है, तो आपको यह भी बताना होगा:
includeLabels
आईडी की कॉमा लगाकर अलग की गई सूची के तौर पर.labelInfo
पैरामीटर मेंfields
का इस्तेमाल करके यह बताया जाता है कि आपको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
है.