SQL Server,ISABOUT,加权术语

时间:2012-12-04 10:03:24

标签: sql sql-server full-text-search containstable isabout

我试图弄清楚加密术语在SQL SERVER中的ISABOUT查询中的确切工作方式。

这是我目前所处的位置:

每个查询都返回以下行:

QUERY 1(重量1): 初始排名

SELECT * FROM CONTAINSTABLE(documentParts, title, 'ISABOUT ("e" weight (1) ) ') ORDER BY RANK DESC, [KEY]

KEY     RANK
306342  249
272619  156
221557  114

QUERY 2(重量0.8): 排名增加,保留初始订单

SELECT * FROM CONTAINSTABLE(documentParts, title, 'ISABOUT ("e" weight (0.8) ) ') ORDER BY RANK DESC, [KEY]

 KEY     RANK
 306342  321
 272619  201
 221557  146

QUERY 3(权重0.2): 排名增加,保留初始订单

SELECT * FROM CONTAINSTABLE(documentParts, title, 'ISABOUT ("e" weight (0.2) ) ') ORDER BY RANK DESC, [KEY]

 KEY    RANK
 306342 998
 272619 877
 221557 692

QUERY 4(权重0.17): 排名下降,最佳匹配现在为最后,这些字词的反向行为从0.17开始

SELECT * FROM CONTAINSTABLE(documentParts, title, 'ISABOUT ("e" weight (0.17) ) ') ORDER BY RANK DESC, [KEY]

 KEY      RANK
 272619   960
 221557   958
 306342   802

QUERY 5(权重0.16): 排名增加,最佳匹配现在是第二

SELECT * FROM CONTAINSTABLE(documentParts, title, 'ISABOUT ("e" weight (0.17) ) ') ORDER BY RANK DESC, [KEY]

 KEY      RANK
 272619   978
 306342   935
 221557   841

QUERY 6(重量0.01): 排名降低,最佳匹配再次出现

SELECT * FROM CONTAINSTABLE(documentParts, title, 'ISABOUT ("e" weight (0.01) ) ') ORDER BY RANK DESC, [KEY]

 KEY    RANK
 221557 105
 272619 77
 306342 50

体重1的最佳匹配排名为249,而体重下降至0.2,最佳匹配排名上升至998。 从0.2到0.17排名降低,从0.16结果反转(重现此行为的权重值取决于术语,可能取决于搜索的列...

似乎有一个重量意味着相反的点,就像“不包括这个术语”。   你对这种行为有什么解释吗?   为什么在体重下降时排名上升?   为什么排名在某个点之后会下降,直到结果被反转,您如何预测这一点呢?

当用户搜索创建以下查询的内容时,我使用自定义“断字符”:

CONTAINSTABLE(documentParts, title, 
      'ISABOUT (
          "wordA wordB wordC" weight (0.8), 
          "wordA*" NEAR "wordB*" NEAR "wordC*" weight (0.6), 
          "wordA*" weight (0.1), 
          "wordB*" weight (0.1), 
          "wordC*" weight (0.1), 
       ) ')

我希望0.1字的排名很高吗? 以下查询是否与上述相同,我是否期望0.1排名有一些奇怪的行为?

CONTAINSTABLE(documentParts, title, '
      ISABOUT ( "wordA wordB wordC" weight (0.8) ), 
      OR ISABOUT ( "wordA*" NEAR "wordB*" NEAR "wordC*" weight (0.6) ), 
      OR ISABOUT ( "wordA*" weight (0.1) ), 
      OR ISABOUT ( "wordB*" weight (0.1) ), 
      OR ISABOUT ( "wordC*" weight (0.1) ), 
      ')

2 个答案:

答案 0 :(得分:4)

根据我的经验,我得到了最好的结果,其中权重加起来为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) 
           ) ')

答案 1 :(得分:3)

由于时钟正在滴答作响,我最终得到了类似的东西,取得了相当不错的结果......:

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

我会将它传递给测试团队并将其称为一天......