我有以下要求:
SELECT Id,SearchKeyWords, PTitle, PDescription, Presentation, Category, ManufacturerId
FROM V_ProductForSearch
WHERE CONTAINS ((SearchKeyWords, PTitle, PDescription, Presentation), @KeyWords)
是否可以在找到术语的列的功能中归因于不同的权重。例如,在这种情况下,两个第一列的权重为0.8,最后一列的权重为0.5。
我知道当我们有几个搜索的术语时可以分配一个权重,但是对于列可以做同样的事情吗?
答案 0 :(得分:1)
微软并没有采用一种方法来实现这一目标,你只能权衡关键词,因为它已经得到了重视。 http://msdn.microsoft.com/en-us/library/ms187787.aspx(阅读G段)
我尝试过另一种方法,我希望可以使用它。
我正在做的是权衡SearchKeyWords = 5,PTitle = 4,PDescription = 3,Presentation = 2.这些值正在总结和排序
SELECT Id,SearchKeyWords, PTitle, PDescription, Presentation, Category, ManufacturerId, SUM(srank) ranked
FROM (
SELECT Id,SearchKeyWords, PTitle, PDescription, Presentation, Category, ManufacturerId, 5 srank
FROM V_ProductForSearch
WHERE CONTAINS ((SearchKeyWords), @KeyWords)
UNION ALL
SELECT Id,SearchKeyWords, PTitle, PDescription, Presentation, Category, ManufacturerId, 4 srank
FROM V_ProductForSearch
WHERE CONTAINS ((PTitle), @KeyWords)
UNION ALL
SELECT Id,SearchKeyWords, PTitle, PDescription, Presentation, Category, ManufacturerId , 3 srank
FROM V_ProductForSearch
WHERE CONTAINS ((PDescription), @KeyWords)
UNION ALL
SELECT Id,SearchKeyWords, PTitle, PDescription, Presentation, Category, ManufacturerId, 2 srank
FROM V_ProductForSearch
WHERE CONTAINS ((Presentation), @KeyWords) ) a
GROUP BY Id,SearchKeyWords, PTitle, PDescription, Presentation, Category, ManufacturerId
ORDER BY SUM(srank)