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
原文地址:https://www.cnblogs.com/ainima/p/6331321.html