如何在全文查询中确定哪个词是命中的?

70gysomp  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(205)

在一个非常简单的选择中,如下所示:

select * from Table1 where contains(*, 'word1 OR word2 OR wordN OR ...')

有没有办法知道在全文索引中找到了哪个词?
我知道怎样做一个报告,说明一个词在一定的时间间隔内出现了多少次。

Something like: 
Word     Total
Word1     189
Word2     120
Word3      13

我做了以下操作,但是查询速度非常慢:

select p.id, COUNT(ArtId) AS Total from Table n
INNER JOIN @lPs p ON  CHARINDEX( p.sWord, sText) > 0 
where Contains(n.sText, '"word1 " OR " word2 " OR " word3 "') AND dColumn Between 'date1' AND 'date2'
GROUP BY p.id

where @lPs is a table variable with 2 columns: id int, sWord nvarchar

任何建议都将不胜感激

wfveoks0

wfveoks01#

尝试使用子查询:

select p.id, p.sWord, COUNT(ArtId) AS Total
from (select n.*
      from Table n
      where Contains(n.sText, '"word1 " OR " word2 " OR " word3 "') and
            dColumn Between 'date1' AND 'date2'
     ) n join
     @lPs p
     on s.Text like CONCAT('%' CHARINDEX( p.sWord, n.sText) > 0 
group by p.id, p.sWord;

SQLServer可能会对带有子查询的全文索引更友好。

相关问题