kubal5003
kubal5003

Reputation: 7254

FREETEXT search - ordering results according to how close they match

I'm trying to implement a Full Text Search. I'm using FREETEXT and I get the correct results. The problem is the ordering of results. If try to search for "car park" the results that match both those words should be at the beginning and then those matching only one of them. How can I accomplish this?

Thank

Upvotes: 4

Views: 2373

Answers (1)

Aaron
Aaron

Reputation: 383

Use FREETEXTTABLE instead of FREETEXT.

FREETEXTTABLE will return a table of keys with Rank information. You can sort on this Rank information to find the items that are the closest matches.

Microsoft FREETEXTTABLE documentation

The following example shows how this works:

SELECT
    t.TableID
    , t.TextData
    , ft.Rank
FROM
    Table t
    INNER JOIN FREETEXTTABLE ( Table , * , 'car park' ) ft ON ( t.TableID = ft.[Key] )
ORDER BY
    ft.Rank DESC

Upvotes: 9

Related Questions