SQL Server 2005全文索引(full text search)

數據庫提供全文索引已經很普及了,之前使用了PostgreSQL和MySQL的,今天嘗試了SQL Server 2005。

首先新建一個數據庫,在新建一個表格,選擇Properties->Files,啓用索引,

image

要建立索引,需要有有一個unique的列,我選擇建立一個自動遞增的整數列。在數據庫的storage->Full Text Catalogs建立一個新的“full text search catalog”。選擇你要建立索引的列,郵件點擊新建“Fulltext Index…”。然後選擇表格右鍵點擊新建“Full-text Index”。

  • 多個單詞(短語)
  • 同一個詞根(英語適用)
  • 不同單詞設置權重
    SELECT ProductName
    FROM Products
    WHERE CONTAINS(ProductName, 'ISABOUT (stout weight (.8),
       ale weight (.4), lager weight (.2) )' )
  • 單詞之間設定距離
    SELECT ProductName
    FROM Products
    WHERE CONTAINS(ProductName, '"laugh*" NEAR lager')

參考:

  1. 【1】http://www.developer.com/db/article.php/3446891/Understanding-SQL-Server-Full-Text-Indexing.htm
  2. 【2】http://aspalliance.com/1512_Understanding_Full_Text_Search_in_SQL_Server_2005.1
  3. 【3】http://www.kodyaz.com/articles/SQL-Server-Full-Text-Search-Indexing.aspx
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章