یک تجربهی مهم: نگارش 11 آن را با SQL Server X64 تست کردم کار نکرد. اما نگارش 9 کار میکند.
مستندات کامل
پس از نصب ابتدایی آن، مراحل ذیل را برای فعال سازی آن باید طی کرد:
1) تنظیم مسیر پوشه bin نصب فیلتر (مهم!)
Start > Control Panel > System > Advanced Environment Variables -> System Variables -> find PATH
C:\Program Files\Adobe\Adobe PDF iFilter 9 for 64-bit platforms\bin\
سپس کل سیستم را ری استارت کنید.
2) ثبت آن در وهلهی جاری SQL Server
برای این منظور ابتدا دستورات ذیل را جرا کنید:
exec sys.sp_fulltext_service 'load_os_resources', 1; EXEC sp_fulltext_service 'verify_signature', 0 EXEC sp_fulltext_service 'update_languages'; -- update language list EXEC sp_fulltext_service 'restart_all_fdhosts'; -- restart daemon reconfigure with override
سپس در management studio یکبار بر روی وهلهی جاری کلیک راست کرده و گزینهی Restart را انتخاب کنید (مهم).
3) پس از ریاستارت SQL Server، اطمینان حاصل کنید که این فیلتر جدید نصب شدهاست:
exec sys.sp_help_fulltext_system_components 'filter';
و یا کوئری ذیل نیز برای این منظور مفید است:
SELECT document_type, path from sys.fulltext_document_types where document_type = '.pdf'
4) در ادامه برای استفاده از آن آزمایش ذیل را ترتیب خواهیم داد.
ایجاد یک جدول جدید که فایلهای باینری PDF را در خود ذخیره میکند:
CREATE TABLE PdfDocuments ( id INT IDENTITY(1,1) NOT NULL, doctype NCHAR(4) NOT NULL, doccontent VARBINARY(MAX) NOT NULL, CONSTRAINT PK_PdfDocuments PRIMARY KEY CLUSTERED(id) );
سپس چند رکورد را در آن ثبت میکنیم. برای نمونه دو مقالهی خروجی PDF سایت جاری را در این جدول ثبت خواهیم کرد:
INSERT INTO PdfDocuments(doctype, doccontent) SELECT N'PDF', bulkcolumn FROM OPENROWSET (BULK 'C:\Users\Vahid\Downloads\1732-DotNetTips.pdf', SINGLE_BLOB) AS doc; INSERT INTO PdfDocuments(doctype, doccontent) SELECT N'PDF', bulkcolumn FROM OPENROWSET (BULK 'C:\Users\Vahid\Downloads\1733-DotNetTips.pdf', SINGLE_BLOB) AS doc;
http://msdn.microsoft.com/en-us/library/ms692560%28v=vs.85%29.aspx
-- Search property list CREATE SEARCH PROPERTY LIST PdfSearchPropertyList; GO ALTER SEARCH PROPERTY LIST PdfSearchPropertyList ADD 'Author' WITH (PROPERTY_SET_GUID = 'F29F85E0-4FF9-1068-AB91-08002B27B3D9', PROPERTY_INT_ID = 4, PROPERTY_DESCRIPTION = 'Author - author of a given item.'); GO
در اینجا اگر علاقمند بودید، stop list معرفی شده در قسمتهای قبل را نیز میتوان افزود.
CREATE FULLTEXT STOPLIST SQLStopList; GO -- Add a stopwords ALTER FULLTEXT STOPLIST SQLStopList ADD N'به' LANGUAGE 'English'; ALTER FULLTEXT STOPLIST SQLStopList ADD N'با' LANGUAGE 'English'; --.....
سپس یک کاتالوگ FTS و ایندکس Full-Text ایی را بر روی این جدول ایجاد میکنیم:
-- Full-text catalog CREATE FULLTEXT CATALOG PdfDocumentsFtCatalog; GO -- Full-text index CREATE FULLTEXT INDEX ON PdfDocuments ( [doccontent] TYPE COLUMN [doctype] Language 1033 STATISTICAL_SEMANTICS ) KEY INDEX PK_PdfDocuments ON PdfDocumentsFtCatalog WITH STOPLIST = SQLStopList, SEARCH PROPERTY LIST = PdfSearchPropertyList, CHANGE_TRACKING AUTO; GO
آیا کار میکند ؟ چیزی ایندکس شدهاست؟
SELECT I.document_id, I.display_term, I.occurrence_count FROM sys.dm_fts_index_keywords_by_document(DB_ID(DB_NAME()), OBJECT_ID(N'dbo.PdfDocuments')) AS I INNER JOIN dbo.PdfDocuments D ON D.id = I.document_id;
انجام دو کوئری بر روی آن. یکی برای یافتن متنی ساده و دیگری برای یافتن خواص
SELECT * FROM PdfDocuments WHERE CONTAINS(doccontent, N'است') SELECT I.document_id, I.display_term, I.property_id FROM sys.dm_fts_index_keywords_by_property(DB_ID(DB_NAME()), OBJECT_ID(N'dbo.PdfDocuments')) AS I INNER JOIN dbo.PdfDocuments D ON D.id = I.document_id;