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

You can search for words or phrases and specify a weighting value. Weight, a number between 0.0 and 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 value available, and a weight value of 1.0 is the highest available value. For example, this query searches for all customer addresses, using weight values, in which any text beginning with the string des is near either Rue or Bouchers. Microsoft® SQL Server™ gives a higher ranking value to those rows with more of the words specified. Therefore, SQL Server gives a higher ranking value to a row with des Rue Bouchers than to a row with des Rue.

USE Northwind

GO

SELECT CompanyName, ContactName, Address  

FROM Customers

WHERE CONTAINS(Address, 'ISABOUT ("des*",   

                                  Rue WEIGHT(0.5),

                                  Bouchers WEIGHT(0.9)

                                 )

                        '

              )

GO

  

A weighted term can be used in conjunction with any of the other four types of terms.

Applying weights in a query is more useful if the resulting rank values for the rows can be used to order the result set rows and determine if the rank values can be returned in the select list. This is not possible with the CONTAINS predicate, but it is possible with the CONTAINSTABLE rowset-valued function. Although the usefulness of a rank value is most obvious with weighted terms, because of the less precise nature of full-text queries, it can be useful for any term.

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.