توضّح هذه الصفحة كيفية البحث عن الملفات التي تم تطبيق تصنيف أو قيمة حقل معيّنة عليها.
أنواع حقول التصنيفات
تكون حقول التصنيفات في 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 (مع 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' |
الملفات التي يكون فيها 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
مثال
يوضّح نموذج الرمز التالي كيفية استخدام 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
من التصنيف المطلوب إرجاعه.