कोई खास लेबल या फ़ील्ड वैल्यू वाली फ़ाइलें खोजें

इस पेज पर, किसी खास लेबल या फ़ील्ड वैल्यू वाली फ़ाइलों को खोजने का तरीका बताया गया है.

लेबल फ़ील्ड के टाइप

Google Drive के लेबल फ़ील्ड में टाइप किए जाते हैं, जिनमें अलग-अलग तरह के इंडेक्स और सर्च सिमैंटिक काम करते हैं. नीचे दी गई टेबल में उपलब्ध डेटा टाइप दिखाए गए हैं.

Type लेबल प्रकार विकल्प इस्तेमाल किए जा सकने वाले खोज ऑपरेटर
टेक्स्ट TextOptions is null, is not null, =, contains, starts with
लंबा लेख LongTextOptions is null, is not null, contains
Integer IntegerOptions is null, is not null, =, !=, <, >, <=, >=
तारीख DateOptions is null, is not null, =, !=, <, >, <=, >=
चुनें SelectionOptions is null, is not null, =, !=
उपयोगकर्ता UserOptions is null, is not null, =, !=
चयन सूची SelectOptions (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'
ऐसी फ़ाइलें जहां टिप्पणी की शुरुआत "हैलो" से होती है labels/contract.comment STARTS WITH 'hello'
ऐसी फ़ाइलें जिनमें स्थिति लागू की गई है labels/contract.status = 'executed'
ऐसी फ़ाइलें जिनमें स्थिति लागू नहीं होती labels/contract.status != 'executed'
ऐसी फ़ाइलें जिनमें एक्ज़ीक्यूट करने की तारीख किसी खास तारीख से पहले की है 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 का इस्तेमाल आईडी की कॉमा-सेपरेटेड लिस्ट के तौर पर करें.

  • fields पैरामीटर में labelInfo डालें, ताकि यह पता चल सके कि आपको labelInfo को includeLabels के अंदर दिखाना है.

कामयाब होने पर, response बॉडी में फ़ाइलों की सूची शामिल की जाती है.

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.