只有ContainsTable
收益相關的評估。你沒有提到需要返回的內容,所以我只是簡單地返回表值的名稱以及給定表的主鍵(你可以用實際的主鍵列名替換「PrimaryKey」,例如PostId或PostCommentsId) ,價值和等級。
Select Z.TableName, Z.PK, Z.Value, Z.Rank
From (
Select 'Posts' As TableName, Posts.PrimaryKey As PK, Posts.Description As Value, CT.Rank
From Posts
Join ContainsTable(Posts, Description, 'Anyword') As CT
On CT.Key = Posts.PrimaryKey
Union All
Select 'PostComments', PostComments.PrimaryKey, PostComments.Comments, CT.Rank
From PostComments
Join ContainsTable(PostComments, Comments, 'Anyword') As CT
On CT.Key = PostComments.PrimaryKey
) As Z
Order By Z.Rank Desc
編輯鑑於更多的信息,這是很清晰的。首先,看起來搜索排名與結果沒有關係。因此,所有必要的是在搜索Post信息和搜索PostComments之間使用OR:
Select ...
From Posts
Where Contains(Posts.Description, Posts.Title, 'searchterm')
Or Exists (
Select 1
From PostComments
Where PostComments.PostId = Posts.Id
And Contains(PostComments.Comments, 'searchterm')
)
@Thomas,感謝您的幫助!也許我不夠清楚,但搜索必須返回POSTS。結果將通過相關性顯示在POSTS順序列表中。 – StackOverflower 2010-04-20 15:21:48
@Timmy O'工具 - 那麼PostComments如何適合等式?帖子和帖子評論如何相關? – Thomas 2010-04-20 15:50:39
@Timmy O'工具 - PostComments中找到的值的排名如何適合問題?如果您能夠展示您期望返回的內容,這將有所幫助。 – Thomas 2010-04-20 15:53:55