在动态 TSQL 中使用 FREETEXTTABLE 的列的优先级/权重

发布于 2024-08-13 11:45:02 字数 1035 浏览 3 评论 0原文

我有动态 sql,可以使用 CONTAINSTABLE 执行分页和全文搜索,效果很好。问题是我想使用 FREETEXTTABLE 但对某些列的排名进行加权

这是我的原始 sql 和我想要整合的排名权重 (出于隐私原因,我已更改名称)

SELECT * FROM 
    (SELECT TOP 10 Things.ID, ROW_NUMBER() 
        OVER(ORDER BY KEY_TBL.RANK DESC ) AS Row FROM [Things]
    INNER JOIN 
        CONTAINSTABLE([Things],(Features,Description,Address),
            'ISABOUT("cow" weight (.9), "cow" weight(.1))') AS KEY_TBL 
    ON [Properties].ID = KEY_TBL.[KEY] 
    WHERE TypeID IN (91, 48, 49, 50, 51, 52, 53) 
        AND
        dbo.FN_CalcDistanceBetweenLocations(51.89249, -8.493376, 
        Latitude, Longitude) <= 2.5 
    ORDER BY KEY_TBL.RANK DESC ) x 
WHERE x.Row BETWEEN 1 AND 10

这是我想要集成的内容

select sum(rnk) as weightRankfrom
From
(select 
    Rank * 2.0 as rnk, 
    [key] 
from freetexttable(Things,Address,'cow')
union all 
select 
    Rank * 1.0 as rnk, 
    [key] 
from freetexttable(Things,(Description,Features),'cow')) as t 
group by [key] 
order by weightRankfrom desc 

I have dynamic sql that perform paging and a full text search using CONTAINSTABLE which works fine. Problem is I would like to use FREETEXTTABLE but weight the rank of some colums over others

Here is my orginal sql and the ranking weight I would like to integrate
(I have changed names for privacy reasons)

SELECT * FROM 
    (SELECT TOP 10 Things.ID, ROW_NUMBER() 
        OVER(ORDER BY KEY_TBL.RANK DESC ) AS Row FROM [Things]
    INNER JOIN 
        CONTAINSTABLE([Things],(Features,Description,Address),
            'ISABOUT("cow" weight (.9), "cow" weight(.1))') AS KEY_TBL 
    ON [Properties].ID = KEY_TBL.[KEY] 
    WHERE TypeID IN (91, 48, 49, 50, 51, 52, 53) 
        AND
        dbo.FN_CalcDistanceBetweenLocations(51.89249, -8.493376, 
        Latitude, Longitude) <= 2.5 
    ORDER BY KEY_TBL.RANK DESC ) x 
WHERE x.Row BETWEEN 1 AND 10

Here is what I would like to integrate

select sum(rnk) as weightRankfrom
From
(select 
    Rank * 2.0 as rnk, 
    [key] 
from freetexttable(Things,Address,'cow')
union all 
select 
    Rank * 1.0 as rnk, 
    [key] 
from freetexttable(Things,(Description,Features),'cow')) as t 
group by [key] 
order by weightRankfrom desc 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听,心雨的声音 2024-08-20 11:45:02

不幸的是,自由文本引擎 (FREETEXTTABLE) 使用的算法无法指定各个输入列的重要性。如果这很重要,您可能需要考虑使用不同的产品来满足您的自由文本需求。

Unfortunately, the algorithm used by the freetext engine (FREETEXTTABLE) has no way to specify the significance of the various input columns. If this is critical, you may need to consider using a different product for your freetext needs.

你的心境我的脸 2024-08-20 11:45:02

您可以创建一个串联的列:

  1. Less_important_field &
  2. 更多重要字段和More_important_field (2x)

这可能看起来非常愚蠢,但这实际上是 BM25F 模拟结构化文档的方法。这种黑客实现的唯一缺点是您实际上无法动态更改权重。它使表有点膨胀,但不一定是索引,索引应该只需要计数。

You can create a column with the concatenation of:

  1. Less_important_field &
  2. More_important_field & More_important_field (2x)

This might look really stupid, but it's actually what BM25F does to simulate structured documents. The only downside of this hack-implementation is that you can't actually dynamically change the weight. It bloats up the table a bit, but not necessarily the index, which should only need counts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文