在ms sql 2012服务器中,我有几列的全文搜索索引
我使用FREETEXTTABLE或CONTAINSTABLE进行查询,如果搜索文本出现在多个列而不是其他列上,我的反应会有所不同。
有没有办法区分或接收结果显示的列名?
感谢。
答案 0 :(得分:1)
我假设您使用*
选项调用FREETEXTTABLE / CONTAINSTABLE来搜索所有列。相反,尝试进行多次调用,每列一次。您可以在1个查询中执行此操作,也可以根据具体情况单独查询。
例如(1查询方法):
SELECT
Case
When (MatchesColumn1or2.[KEY] is not null) Then 'Matches Column 1 or 2'
When (MatchesColumn3.[KEY] is not null) Then 'Matches Column 3'
End
FROM
FREETEXTTABLE(MyTable, (Column1, Column2), 'cat AND dog') as MatchesColumn1or2
full outer join
FREETEXTTABLE(MyTable, Column3, 'cat AND dog') as MatchesColumn3
on (MatchesColumn1or2.[KEY] = MatchesColumn3.[KEY])
以下是一个示例,如果您想保留原始排名值,但要注意增加的性能影响:
SELECT
MatchAllColumns.[RANK],
Case
When (MatchesColumn1or2.[KEY] is not null) Then 'Matches Column 1 or 2'
When (MatchesColumn3.[KEY] is not null) Then 'Matches Column 3'
End
FROM
FREETEXTTABLE(MyTable, *, 'cat AND dog') as MatchAllColumns
left join
FREETEXTTABLE(MyTable, (Column1, Column2), 'cat AND dog') as MatchesColumn1or2
on (MatchAllColumns.[KEY] = MatchesColumn1or2.[KEY])
left join
FREETEXTTABLE(MyTable, Column3, 'cat AND dog') as MatchesColumn3
on (MatchAllColumns.[KEY] = MatchesColumn3.[KEY])