我在 SQL Server 数据库上使用全文搜索来返回多个表的结果。最简单的情况是搜索人名字段和描述字段。我用来执行此操作的代码如下所示:
select t.ProjectID as ProjectID, sum(t.rnk) as weightRank
from
(
select KEY_TBL.RANK * 1.0 as rnk, FT_TBL.ProjectID as ProjectID
FROM Projects as FT_TBL
INNER JOIN FREETEXTTABLE(Projects, Description, @SearchText) AS KEY_TBL
ON FT_TBL.ProjectID=KEY_TBL.[KEY]
union all
select KEY_TBL.RANK * 50 as rnk, FT_TBL.ProjectID as ProjectID
FROM Projects as FT_TBL
... <-- complex unimportant join
INNER JOIN People as p on pp.PersonID = p.PersonID
INNER JOIN FREETEXTTABLE(People, (FirstName, LastName), @SearchText) AS KEY_TBL
ON p.PersonID=KEY_TBL.[KEY]
)
group by ProjectID
正如上面(希望)清楚的那样,我试图在项目描述字段中对一个人的名字匹配而不是匹配。如果我搜索“john”之类的内容,那么所有以 john 为名的项目都会得到很大的权重(如预期的那样)。我遇到的问题是搜索有人提供了像“约翰史密斯”这样的全名。在这种情况下,名称的匹配度要弱得多,因为(我认为)每个firstname
/lastname
列中只有一半的搜索词匹配。在许多情况下,这意味着与输入的姓名完全匹配的人不一定会在搜索结果顶部附近返回。
我已经能够通过分别搜索每个firstname
/lastname
字段并将它们的分数加在一起来纠正这个问题,因此我的新查询如下所示:
select t.ProjectID as ProjectID, sum(t.rnk) as weightRank
from
(
select KEY_TBL.RANK * 1.0 as rnk, FT_TBL.ProjectID as ProjectID
FROM Projects as FT_TBL
INNER JOIN FREETEXTTABLE(Projects, Description, @SearchText) AS KEY_TBL
ON FT_TBL.ProjectID=KEY_TBL.[KEY]
union all
select KEY_TBL.RANK * 50 as rnk, FT_TBL.ProjectID as ProjectID
FROM Projects as FT_TBL
... <-- complex unimportant join
INNER JOIN People as p on pp.PersonID = p.PersonID
INNER JOIN FREETEXTTABLE(People, (FirstName), @SearchText) AS KEY_TBL
ON p.PersonID=KEY_TBL.[KEY]
union all
select KEY_TBL.RANK * 50 as rnk, FT_TBL.ProjectID as ProjectID
FROM Projects as FT_TBL
... <-- complex unimportant join
INNER JOIN People as p on pp.PersonID = p.PersonID
INNER JOIN FREETEXTTABLE(People, (LastName), @SearchText) AS KEY_TBL
ON p.PersonID=KEY_TBL.[KEY]
)
group by ProjectID
我的问题:
这是我应该采用的方法,还是有某种方法可以让全文搜索对列列表进行操作,就好像它是一团文本一样:即将firstname
和lastname
列视为单个name
列,从而获得更高的分数匹配包括人名和姓氏的字符串?