I'm using SQL Server 2008 FTS and I'd like to be able to integrate weighted rankings into my search results. However, I'd like to weight the columns that a search term is found in differently. For example, if I have a Title column and a Description colu开发者_StackOverflow中文版mn, I want matches fond in Title to rank higher than matches in Description.
Is this possible in SQL Server 2008? As far as can I see, I can only add weights to specific terms, not column locations.
You can use the FREETEXTTABLE function on each column independently and then assign your weights to the Rank column that is returned. I believe I read somewhere though that the Rank column isn't necessarily valid for comparisons across searches, though, so you may need to experiment to ensure that you get accurate results.
SELECT title, filename, sum(relevance)
FROM (
SELECT title, filename, 10 AS relevance FROM page WHERE title like ‘%about%’
UNION
SELECT title, filename, 7 AS relevance FROM page WHERE filename like ‘%about%’
UNION
SELECT title, filename, 5 AS relevance FROM page WHERE keywords like ‘%about%’
UNION
SELECT title, filename, 2 AS relevance FROM page WHERE description like ‘%about%’
) results
GROUP BY title, filename
ORDER BY relevance desc;
精彩评论