PDA

View Full Version : Search & Ful-Text Indexing



FirstLine
یک شنبه 04 بهمن 1383, 09:32 صبح
با سلام
یه بانک و جدول با در SQLدارم که فیلد Law_Title از نوع NText(500) است.
من میخوام جستجوی زیر را بر اساس Ful-Text دواقع در SQL را بهینه کنم اما بلد نیستم ، لطفا راهنمایی فرمایید.

SELECT * FROM DB_Law WHERE Law_Title Like '%قانون%'
من از این SELECT در StoredProcedure استفاده میکنم و اگر گزینه Like را حذف کنم نتیجه جستجو در مدت 1 ثانیه اجرا و نمایش داده میشود ولی وقتی Like میگذارم حدودا 40 ثانیه زمان میبرد.(کل بانک شامل 50000 رکورد و حجم 500 مگابایت است)
با تشکر

AminSobati
یک شنبه 04 بهمن 1383, 12:28 عصر
دوست عزیزم،
زمانیکه مطمئن هستین Full Text Search رو بصورت صحیح راه اندازی کردین، باید از CONTAINS یا FREETEXT استفاده کنین. مثالهای زیادی در BOL وجود داره که این چند نمونه از کل اونهاست:


Examples
A. Use CONTAINS with <simple_term>
This example finds all products with a price of $15.00 that contain the word "bottles."

USE Northwind
GO
SELECT ProductName
FROM Products
WHERE UnitPrice = 15.00
AND CONTAINS(QuantityPerUnit, 'bottles')
GO

B. Use CONTAINS and phrase in <simple_term>
This example returns all products that contain either the phrase "sasquatch ale" or "steeleye stout."

USE Northwind
GO
SELECT ProductName
FROM Products
WHERE CONTAINS(ProductName, ' "sasquatch ale" OR "steeleye stout" ')
GO

C. Use CONTAINS with <prefix_term>
This example returns all product names with at least one word starting with the prefix choc in the ProductName column.

USE Northwind
GO
SELECT ProductName
FROM Products
WHERE CONTAINS(ProductName, ' "choc*" ')
GO

D. Use CONTAINS and OR with <prefix_term>
This example returns all category descriptions containing the strings "sea" or "bread."

USE Northwind
SELECT CategoryName
FROM Categories
WHERE CONTAINS(Description, '"sea*" OR "bread*"')
GO


موفق باشید