gpt4 book ai didi

tsql - contains 和 containstable 之间有显着区别吗?

转载 作者:行者123 更新时间:2023-12-02 18:26:54 26 4
gpt4 key购买 nike

我在启用了文件流的 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 使用 contains,而查询 #2 使用 containstable。

我的问题是两个查询并不总是产生相同的结果。例如,如果我搜索短语“独立承包商”,查询 #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

最佳答案

CONTAINSTABLE :

top_n_by_rank

Specifies that only the nhighest ranked matches, in descending order, are returned. Applies only when an integer value, n, is specified. If top_n_by_rank is combined with other parameters, the query could return fewer rows than the number of rows that actually match all the predicates.

尝试在没有顶部的情况下运行,看看它是否匹配CONTAINS

关于tsql - contains 和 containstable 之间有显着区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4208075/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com