【发布时间】:2014-05-23 12:55:55
【问题描述】:
我使用的是 MS SQL Server 2012,我有两个表:
1) Keyword_table 包含关键字列表,例如:
keyword, nvarchar(50)
-------------------
web
book
AI
work
...
2) art_table 包含 ID 和文章列表,例如:
artID, int art, nvarchar(MAX)
---------------------------------------
1 The Web is a system of ...
2 AI is the intelligence exhibited by machines or software ...
3 The Web includes Web 1.0, Web 2.0 and Web 3.0
4 The work done by ...
....
我想搜索keyword_table中的每个关键字,得到包含该关键字的文章的数量,例如根据上面的数据,结果应该是这样的:
keyword No of articles
----------------------------------
web 2
book 0
AI 1
work 1
art_table 有几百万条记录,并且在 art 列上有全文索引,我知道我可以使用contains 来搜索一个简单的术语(单个单词/短语),如下所示:
select *
from art_table
where contains (art, 'web')
并统计包含web的文章数量:
select count(*)
from art_table
where contains (art, 'web')
但是如何搜索关键字表中的所有关键字?
提前致谢!
【问题讨论】:
-
@AdamCaviness 我正在使用 SQL Server 的全文搜索,但我想问如何使用“包含谓词”从另一个表中搜索关键字?
-
感谢您的澄清。
标签: sql sql-server full-text-search contains