Dela via


Searching for Words or Phrases Using Weighted Values (Weighted Term)

You can use CONTAINS or CONTAINSTABLE to search for words or phrases and specify a weighting value. Weight, measured as a number from 0.0 through 1.0, indicates the degree of importance for each word and phrase within a set of words and phrases. A weight value of 0.0 is the lowest, and a weight value of 1.0 is the highest.

Examples

The following example shows a query that searches for all customer addresses, using weight values, in which any text beginning with the string "Bay" has either "Street" or "View". SQL Server 2008 gives a higher rank to those rows with more of the words specified.

USE AdventureWorks2008R2;
GO
SELECT AddressLine1, KEY_TBL.RANK 
FROM Person.Address AS Address INNER JOIN
CONTAINSTABLE(Person.Address, AddressLine1, 'ISABOUT ("Bay*", 
         Street WEIGHT(0.9), 
         View WEIGHT(0.1)
         ) ' ) AS KEY_TBL
ON Address.AddressID = KEY_TBL.[KEY]
ORDER BY KEY_TBL.RANK;
GO

A weighted term can be used in conjunction with any of the other four types of terms, namely simple term, prefix term, generation term, and proximity term.