SQL Server, ISABOUT, weighted terms

╄→гoц情女王★ 提交于 2019-12-05 03:40:37

In my experience I have had the best results where the weights add up to 1.

CONTAINSTABLE(documentParts, content, 
          'ISABOUT (
              "wordA wordB wordC" weight (0.5), 
              "wordA*" NEAR "wordB*" NEAR "wordC*" weight (0.2), 
              "wordA*" weight (0.1), 
              "wordB*" weight (0.1), 
              "wordC*" weight (0.1) 
           ) ')

Since the clock is ticking I end up with something like this which fetches quite good results...:

SELECT [KEY], SUM([RANK]) AS [RANK] FROM (
    SELECT [KEY], ([RANK]*1)/(SUM([RANK]) OVER( PARTITION BY 1)/ CAST(COUNT([RANK]) OVER( PARTITION BY 1) AS FLOAT)) AS [RANK] 
        FROM CONTAINSTABLE(documentParts, content, 
              'ISABOUT (
                  "wordA wordB wordC" weight (0.8), 
                  "wordA*" NEAR "wordB*" NEAR "wordC*" weight (0.6), 
                  "wordA*" weight (0.4), 
                  "wordB*" weight (0.4), 
                  "wordC*" weight (0.4) 
               ) ') c
        WHERE c.RANK>0
        UNION ALL      
        SELECT [KEY], ([RANK]*2)/(SUM([RANK]) OVER( PARTITION BY 1)/ CAST(COUNT([RANK]) OVER( PARTITION BY 1) AS FLOAT)) AS [RANK] 
        FROM CONTAINSTABLE(documents, title, 
              'ISABOUT (
                  "wordA wordB wordC" weight (0.8), 
                  "wordA*" NEAR "wordB*" NEAR "wordC*" weight (0.6), 
                  "wordA*" weight (0.4), 
                  "wordB*" weight (0.4), 
                  "wordC*" weight (0.4) 
               ) ') c
         WHERE c.RANK>0
    ) t 
    GROUP BY [KEY]
ORDER BY [RANK] DESC

I will pass it to the test team and call it a day...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!