RANK BY Clause

Topic Last Modified: 2006-06-13

The Structured Query Language (SQL) RANK BY clause can be used to sort results based on how frequently and where the queried strings appear in the indexed documents.

RANK BY CLAUSE (Mechanism, Weight)

The parameter CLAUSE is either WEIGHT or COERCION.

The parameter Mechanism is an action, such as WEIGHT or MULTIPLY.

The parameter Weight specifies the significance of the rank by assigning a numerical value between 0 and 1.

Example

This example contains a SQL search string that uses clause weighting to assign certain search terms a fraction of the weight that other search terms have. The example searches all properties on the items for the term "Star" and the term "Planet." If the search engine finds only "Star" in an item, it should rank that item at one-quarter the value of an item containing "Planet."

The rank Field holds the relevant rank of search results.

strSQL = "Select ""urn:schemas:httpmail:subject"", " & """urn:schemas.microsoft.com:fulltextqueryinfo:rank"" 
strSQL = strSQL & "FROM scope('shallow traversal of "http://myserver/public/test/""')" 
strSQL = strSQL & "WHERE " & "CONTAINS(*.'""Star""')" 
strSQL = strSQL & "RANK BY WEIGHT(0.25) OR " & "CONTAINS(*,'""Planet""') RANK BY WEIGHT(1.0)"

See Also

Other Resources

SELECT Statement