Giving precedence/weight to a column using FREETEX

2020-02-09 10:41发布

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?

1条回答
别忘想泡老子
2楼-- · 2020-02-09 11:17

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]
查看更多
登录 后发表回答