Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Giving precedence/weight to a column using FREETEXTTABLE

I am using SQL Server Full Text Search, with the keyword FREETEXTTABLE to return a table of results based on a few columns, searching for a keyword.

Now I have 2 main columns that I am searching on, Title and Description, I want to give precedence to the Title column as this will most likely have my results but Description might contain results too but I want it to give precedence for a word in Title over Description (but I don't want to use CONTAINSTABLE as this is too specific). Is there a way to give columns weights/precedence using FREETEXTTABLE?

like image 648
David Avatar asked Nov 10 '09 19:11

David


1 Answers

You'll need to use 2 queries with a union, providing a 'weight' of your own, something like this:

select  [key], sum(rnk) as weightRank
from
        (
            select Rank * 2.0 as rnk, [key] from freetexttable(tableName,Title,'free text string')
            union all
            select Rank * 1.0 as rnk, [key] from freetexttable(tableName,Description,'free text string')
        ) as t
group by [key]
like image 150
boydc7 Avatar answered Sep 22 '22 21:09

boydc7