SQL Server 全文搜索 - 对某些列进行加权
如果我有以下全文搜索查询:
SELECT *
FROM dbo.Product
INNER JOIN CONTAINSTABLE(Product, (Name, Description, ProductType), 'model') ct
ON ct.[Key] = Product.ProductID
是否可以对正在搜索的列进行权重?
例如,我更关心“名称”列中出现的“模型”一词,而不是“ 描述或产品类型列。
当然,如果该单词出现在所有 3 列中,那么我预计它的排名会比仅出现在名称列中时更高。如果行仅出现在名称中而不是仅出现在描述/产品类型中,是否有任何方法可以使其排名更高?
If I have the following full text search query:
SELECT *
FROM dbo.Product
INNER JOIN CONTAINSTABLE(Product, (Name, Description, ProductType), 'model') ct
ON ct.[Key] = Product.ProductID
Is it possible to weigh the columns that are being searched?
For example, I care more about the word model appearing in the Name column than I do the
Description or ProductType columns.
Of course if the word is in all 3 columns then I would expect it to rank higher than if it was just in the name column. Is there any way to have a row rank higher if it just appears in Name vs just in Description/ProductType?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以执行类似以下查询的操作。这里,
WeightedRank
是通过乘以各个匹配的排名来计算的。注意:不幸的是,我没有安装 Northwind,所以我无法测试它,所以更像伪代码一样查看它,如果它不起作用,请告诉我。You can do something like the following query. Here,
WeightedRank
is computed by multiplying the rank of the individual matches. NOTE: unfortunately I don't have Northwind installed so I couldn't test this, so look at it more like pseudocode and let me know if it doesn't work.清单 3-25。 SQL Server 2008 中的 Pro 全文搜索 的示例列排名乘数搜索
Listing 3-25. Sample Column Rank-Multiplier Search of Pro Full-Text Search in SQL Server 2008
与亨利的解决方案类似,但经过简化、测试并使用问题提供的详细信息。
注意:我对联合和左连接样式进行了性能测试,发现下面的联合样式与我的数据集 YMMV 所需的逻辑读取要少得多。
Similar to Henry's solution but simplified, tested and using the details the question provided.
NB: I ran performance tests on both the union and left join styles and found the below to require far less logical reads on the union style below with my datasets YMMV.