全文搜索问题

时间:2010-01-29 07:40:04

标签: sql full-text-search

我有2张桌子nsk_UserInfo和照片。 我使用全文搜索查询来显示结果

SELECT nsk_UserInfo.User_ID
       , nsk_UserInfo.Name
       , nsk_UserInfo.Contact_Person
       , nsk_UserInfo.Address, Photos.Photo1 as 'Photo'
FROM nsk_UserInfo INNER JOIN Photos ON nsk_UserInfo.User_ID = Photos.User_ID 
WHERE FREETEXT ((nsk_UserInfo.*), 'My search term')

此查询显示结果但不优先记录(行)。 我可以做什么? 是查询正确还是有任何变化?

1 个答案:

答案 0 :(得分:1)

要获得排名,您需要使用FREETEXTTABLE()。像这样:

SELECT nsk_UserInfo.User_ID,
       nsk_UserInfo.Name,
       nsk_UserInfo.Contact_Person,
       nsk_UserInfo.Address,
       Photos.Photo1 as Photo,
       KeyTable.RANK
FROM nsk_UserInfo
  INNER JOIN Photos
    ON nsk_UserInfo.User_ID = Photos.User_ID
  INNER JOIN FREETEXTTABLE((nsk_UserInfo.*), 'My search term') AS KeyTable
     ON nsk_UserInfo.User_ID = KeyTable.[KEY]
ORDER BY KeyTable.RANK DESC;

http://msdn.microsoft.com/en-us/library/ms142583.aspx查看更多信息。