I am using ContainsTable
in my T-SQL statement to get most relevant content as per some given keywords
in below query.
Select @Values = '"Keyword 1","Keyword 2,"Keyword 3"',
Select @FirstLevelValues = 'Isabout ('+@Values+' Weight(0.7))'
Select @SecondLevelValues = 'Isabout ('+@Values+' Weight(0.3))'
;with cte as (
(Select [Key], [Rank] from ContainsTable(PostsTable, Title, @FirstLevelValues))
union
(Select [Key], [Rank] from ContainsTable(PostsTable, Description, @SecondLevelValues))
)
Select Top 100 P.* from PostsTable P
Left Join cte on cte.[Key] = P.ID where
P.PostDate between DATEADD(DAY, -5, GETUTCDATE()) and GETUTCDATE()
Order by cte.[Rank] DESC, PostDate DESC
Now my problem is that I have [Rank]
column, which rates a Post from PostsTable
on the basis of most relevant (most keyword matches has higher ranking). But, this should work in conjunction with PostDate
column. Means the most relevant and the most recent Post should be rated higher than only the most relevant post. I do understand the concept of Order by, where one resultset is ordered basis one column first followed by the second column and so on. But in my case, I want that the PostDate
should also be considered a criteria, probably with a Weight
as in IsAbout
clause, so it can also decide the ranking of the post.