This is sixth part of the series of Integrated Full Text Search in Microsoft SQL Server 2008. If you want to study the topic in depth, Please read my past five articles in this series. Below are the links of the same.
Note: I am using the same table & data which I have created in my past articles. So if you are directly landed to this article, kindly get the create table script from second article listed above.
Since we had already looked at FREETEXTTABLE, CONTAINSTABLE is not something new. It is also work at TVF but it has bit more functionality than FREETEXTTABLE. You have to provide table name, column(s) name and search condition. CONTAINSTABLE can accept all search condition which is valid in CONTAINS predicate.
CONTAINSTABLE also return KEY and RANK column like FREETEXTTABLE which you can join with your original table. You can refer FREETEXTTABLE’s
article for more details.
Let us see some examples for CONTAINSTABLE in Microsoft SQL Server 2008.
–this T-SQL will return only key value and rank
–this is sample search of CONTAINSTABLE
–with FORMSOF clause which we used in CONTAINS also in previous article
Select t2.* FROM CONTAINSTABLE
) as t1 join FTSTest t2 on t1.[key]=t2.Id
–there is one more useful clause, ISABOUT, which you can use with CONTAINS and CONTAINSTABLE
–You can give weight of the search word between 0.0 to 1.0
–search word with greater weight comes up with higher rank so that you can sort it easily.
N’ISABOUT(volatile WEIGHT(0.1), General WEIGHT(1.0))’
INNER JOIN FTSTest pm
ON ct.[KEY] = pm.ID
ORDER BY ct.[RANK] DESC;