views:

105

answers:

1

I want to use SQL Server 2005 Express to find the top five tuples related to a paragraph of text. I know I can use Full Text Indexing and CONTAINSTABLE to find rows that contain an exact phrase, but how do I get it to return the closest matches to the words in a paragraph, not the exact paragraph itself.

So far the only way I can think of is to split the CONTAINSTABLE query, inserting ' or ' for every space character, generating a query along the lines of the following, but am concerned about performance (and stop words).

SELECT id, FT.rank, description
FROM SearchTable
    INNER JOIN CONTAINSTABLE (SearchTable, *, 
            '"This" OR "is" OR "my" OR "paragraph"') AS FT 
            ON SearchTable.id = FT.[key]
ORDER BY Rank DESC

I expect there's a standard solution to this problem - does anyone know what it is?

+2  A: 

Have you tried the FREETEXT and FREETEXTTABLE which should do what you are trying to do?

http://msdn.microsoft.com/en-us/library/cc879300.aspx

Jonathan Kehayias
Yes, this is exactly what you want. FREETEXT/FREETEXTTABLE automatically splits the search text into words, and the ranking is based on how well it matches - exact phrase ranks highest, then all words, etc.
GalacticCowboy
Ahhh - so this is the difference between FREETEXTTABLE and CONTAINSTABLE! Head-Slap moment :0) Many thanks.