我在一个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使用containsstable。
我的问题是两个查询并不总是产生相同的结果。例如,如果我搜索短语“独立承包商”,查询#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
答案 0 :(得分:3)
top_n_by_rank
指定只按最低排名匹配,按降序排列, 被退回。仅适用于 指定整数值n。 如果 top_n_by_rank与其他人合并 参数,查询可以返回 行数少于行数 实际上匹配所有的 谓词。强>
尝试使用w / o top运行,看看它是否与CONTAINS
匹配。