我在启用了文件流的 varchar(max) 类型的列上创建了全文索引。文件流包含 JPG、TIF、PDF 和 XML 等数据(尽管我相信这与问题几乎无关)。
我创建了两个查询,允许我搜索索引。
全文搜索#1--
select
parentObj.ObjectID as 'GroupingID',
parentObj.Name as 'Grouping',
childObj.ObjectID as 'FileObjID',
childObj.Name as 'FileName',
fs.FileStreamID
from dbo.dat_FileStream fs
inner join dbo.dat_Object childObj
on fs.ObjectID = childObj.ObjectID
inner join dbo.dat_Collection c
on fs.ObjectID = c.ObjectID
inner join dbo.dat_Object parentObj
on c.ParentID = parentObj.ObjectID
where contains(FileStreamData, @srchTerm)
and parentObj.ObjectTypeID = 1
ORDER BY 'Grouping'
全文搜索#2--
select
KEY_TBL.RANK,
parentObj.ObjectID as 'GroupingID',
parentObj.Name as 'Grouping',
childObj.ObjectID as 'FileObjID',
childObj.Name as 'FileName',
fs.FileStreamID
from dbo.dat_FileStream fs
inner join containstable(dbo.dat_FileStream, FileStreamData, @srchTerm, 1000) as KEY_TBL
on fs.FileStreamID = KEY_TBL.[KEY]
inner join dbo.dat_Object childObj
on fs.ObjectID = childObj.ObjectID
inner join dbo.dat_Collection c
on fs.ObjectID = c.ObjectID
inner join dbo.dat_Object parentObj
on c.ParentID = parentObj.ObjectID
where parentObj.ObjectTypeID = 1
ORDER BY 'Grouping'
两个全文搜索之间的唯一显着区别是查询 #1 使用包含,而查询 #2 使用包含表。
我的问题是这两个查询并不总是产生相同的结果。例如,如果我搜索“独立承包商”这个短语,查询 #1 会产生一个包含 10 个不同文档(PDF 和 XML)的结果集,而查询 #2 只会产生 6 个结果集。这似乎是规则:查询#1 总是比查询#2 产生更多的结果,并且查询#2 总是产生与查询#1 完全相同的匹配。
查询 #1 - 搜索“独立承包商”产生:
4262 AAA-00-12 4561 AAA-00-12.pdf 4235
4316 AAA-00-15 4753 AAA-00-15.pdf 4427
4316 AAA-00-15 4754 AAA-00-15.xml 4428
3873 AAA-00-19 4784 AAA-00-19.pdf 4458
3903 AAA-00-22 6795 AAA-00-22.pdf 6459
3953 AAA-00-24 6899 AAA-00-24.pdf 6563
3953 AAA-00-24 6900 AAA-00-24.xml 6564
4842 AAA-00-9 4905 AAA-00-9.pdf 4577
4842 AAA-00-9 4906 AAA-00-9.xml 4578
4057 AAA-0001 4260 AAA-0001.pdf 3936
查询 #2 - 搜索“独立承包商”产生:
19 4262 AAA-00-12 4561 AAA-00-12.pdf 4235
126 4316 AAA-00-15 4754 AAA-00-15.xml 4428
126 4316 AAA-00-15 4753 AAA-00-15.pdf 4427
116 3873 AAA-00-19 4784 AAA-00-19.pdf 4458
125 3903 AAA-00-22 6795 AAA-00-22.pdf 6459
57 3953 AAA-00-24 6900 AAA-00-24.xml 6564
57 3953 AAA-00-24 6899 AAA-00-24.pdf 6563