Sunday, May 18, 2008    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Jan 2007 >>
S M T W T F S
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Search

Categories
 • Adobe (61) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (6) [RSS]
 • AIR (96) [RSS]
 • Appearances (105) [RSS]
 • Books (66) [RSS]
 • CFEclipse (14) [RSS]
 • ColdFusion (1081) [RSS]
 • Flash (91) [RSS]
 • Flex (319) [RSS]
 • Jobs (81) [RSS]
 • JRun (12) [RSS]
 • Labs (27) [RSS]
 • LiveCycle (12) [RSS]
 • MAX (141) [RSS]
 • Regular Expressions (12) [RSS]
 • SQL (36) [RSS]
 • Stuff (492) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (131) [RSS]
 • Wireless (96) [RSS]

Other BLOGs
 • Ray Camden
 • Tim Buntel
 • Sean Corfield
 • John Dowdell
 • Steven Erat
 • Brandon Purcell
 • Charlie Arehart
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Entry / Main
January 5, 2007

Ranking SQL Server 2005 Full-Text Search Results

When performing full-text searches you usually want not just results, but a ranking indicating how close a match is to what you are looking for. In SQL Server 2005, ranks are accessed via ranking functions - FULLTEXT searches are ranked using function FULLTEXTTABLE() and CONTAINS searches are ranked using function CONTAINSTABLE(). Both of these functions are used the same way, and both accept search patterns, the same search patterns supported by the FULLTEXT and CONTAINS predicates themselves.

Here is an example:

SELECT f.rank, note_id, note_text
FROM productnotes,
FREETEXTTABLE(productnotes, note_text, 'rabbit food') f
WHERE productnotes.note_id=f.[key]
ORDER BY rank DESC;

This example performs a FREETEXT type search. Instead of filtering using the WHERE clause, the FREETEXTTABLE() function is used and given a search pattern instructing the full-text engine to match any rows that contain words meaning rabbit and food. FREETEXTTABLE() returns a table which is given an alias of "f" (so as to be able to refer to it in column selection and the join), this table contains a column named "key" which will contain the primary key value of the table that was indexed (productnotes in this example), and "rank" which is the rank value assigned. And finally, results here are sorted by rank descending, as the higher the rank the greater the match.

It is also possible to assign weight values to search patterns and words. The rankings assigned in the example used here assumed that all words were equally important and relevant. If this is not the case, and some words are more important than others, then the ISABOUT() function can be used to assign relative weights, and the full-text search engine will then use these values when determining rankings.

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments
Ben,

Love the post; I have the full text search up and running. I used your SQL but the rank on each of the results = '0'.

Any Ideas?

RF
# Posted By RichF | 2/7/07 2:54 PM
working fine over here, maybe you have the wrong columns in your ft catalog
# Posted By Patrick | 3/27/07 8:37 AM
You are getting rank 0 because it uses a previously built FT catalog. If you rebuild the catalog you should get values for the RANK.

Either you can rebuild the FTC using the following query or right clicking the FTC from SQL Server Management Studio

ALTER FULLTEXT CATALOG catalog_name
REBUILD
# Posted By Gayeshan | 5/18/07 6:51 AM
hello.

is there a rational explanation for which after some select statements, the rank returned by the full-text search engine is 0, knowing that just after the repopulation the rank is displayed correctly?

in other words, time and usage messes up the ranking....

thanks!
# Posted By mike | 7/31/07 11:35 PM
Hello

I am doing FREETEXT search in my Database.

I have indexed my table (Article_ArticleContent) and included some of the columns.

However, executing the query do not returns any records:

SELECT
cArticleTitle, cShortDescription
FROM
Article_ArticleContent
WHERE CONTAINS
(cArticleTitle,' "a*" ');

Although executing the following query, it returns me the correct number of records:

select cArticleTitle, cShortDescription
from dbo.Article_ArticleContent
where cArticleTitle LIKE 'a%'

Can you please let me know if I am missing something in Indexing or in the SELECT query.

Ankit
# Posted By Ankit | 12/11/07 8:25 AM

  © Copyright 1997-2008 Ben Forta, All Rights Reserved