SELECT b.FK_Publication_ID, b.PageNumber as PageNumber, b.SearchText as SearchText, a.Title as Title ,
TitleSearch.[Rank] + PubSearch.[Rank] * 10000
AS [Rank]
FROM PublicationSearch
INNER JOIN Publication a ON b.FK_Publication_Id = a.Id
INNER JOIN FREETEXTTABLE(PublicationSearch, SearchText, "searchtext") PubSearch ON b.Id = PubSearch.[Key]
INNER JOIN FREETEXTTABLE(Publication, Title, "searchtext") TitleSearch ON a.Id = TitleSearch.[Key]
WHERE b.FK_ContentType_Id IN (SELECT * FROM UF_CSVToTable(@Options))
UNION
SELECT a.Id, null as PageNumber, null as Searchtext, a.Title as Title, TitleSearch.[Rank] * 100 AS [Rank]
FROM Publication a
INNER JOIN FREETEXTTABLE(Publication,Title, "searchtext") TitleSearch ON a.Id = TitleSearch.[Key]
UNION
SELECT b.FK_Publication_ID, b.PageNumber as PageNumber, b.SearchText as SearchText, null as Title,
PubSearch.[Rank]
AS [Rank]
FROM PublicationSearch b
INNER JOIN FREETEXTTABLE(PublicationSearch, SearchText, "searchtext") PubSearch ON b.Id = PubSearch.[Key]
ORDER BY [Rank] DESC
以上是使用UNION
下面是你建议的
选择 b.FK_Publication_ID,b.PageNumber 作为 PageNumber,b.SearchText 作为 SearchText,a.Title 作为 Title 作为 ContentType,
TitleSearch.[Rank] * 100 (Ranking, dont know how to do it here)
AS [Rank]
FROM PublicationSearch b
INNER JOIN Publication a ON b.FK_Publication_Id = a.Id
JOIN FREETEXTTABLE(PublicationSearch, SearchText, "searchtext")PubSearch ON b.Id = PubSearch.[Key]
FULL JOIN FREETEXTTABLE(Publication, Title, "searchtext")TitleSearch ON a.Id = TitleSearch.[Key]
order by [RANK] desc
继承人,确切的脚本。使用完全联接,我从 BOTH 表和仅从 PublicationSearch 表中获取记录,但不仅从 Publication 表中获取记录
此外,在两个表中找到的记录应该排名更高,然后是仅来自 Publication 表的记录,然后是来自 PublicationSerach 表的记录
谢谢..