البحث عن ملفات ذات تصنيف أو قيمة حقل معيّنة

وتوضّح هذه الصفحة طريقة البحث عن الملفات التي تم تطبيق تصنيف أو قيمة حقل معيّنة عليها.

أنواع حقول التصنيف

تتم كتابة حقول تصنيفات Google Drive بشكل كبير مع مراعاة استخدام كل نوع لدلالات البحث والفهرسة المختلفة. يوضح الجدول التالي أنواع البيانات المتاحة.

Type خيارات نوع التصنيف عوامل تشغيل البحث المتوافقة
النص 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, =, !=
قائمة الاختيارات 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'
الملفات التي يكون فيها execute_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

مثال

يوضّح نموذج الرموز التالي كيفية استخدام labelId واحد أو أكثر لإدراج جميع الملفات ذات تصنيف أو قيمة حقل محدّدَين من مورد ملفات Drive. ويتم أيضًا استخدام طريقة files.list. يجب أن يكون نص الطلب فارغًا.

إذا أردت تضمين labelInfo في الردّ، عليك أيضًا تحديد ما يلي:

  • includeLabels كقائمة من المعرّفات مفصولة بفواصل.

  • labelInfo في المعلمة fields للدلالة على أنك تريد عرض labelInfo ضمن includeLabels.

في حال نجاح هذا الإجراء، سيحتوي نص الاستجابة على قائمة الملفات.

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 الثانية المطلوب عرضها في التصنيف.