如何在全文搜索(Sql Server)中设置订单优先级
我有一个简单的tbl_posts表,有三列(id、name、content) 我为名称和内容列创建了全文索引。 当我像这样询问它时:如何在全文搜索(Sql Server)中设置订单优先级,sql,sql-server-2005,full-text-search,ranking,Sql,Sql Server 2005,Full Text Search,Ranking,我有一个简单的tbl_posts表,有三列(id、name、content) 我为名称和内容列创建了全文索引。 当我像这样询问它时: SELECT * FROM dbo.tbl_posts WHERE FREETEXT ( *, 'search word' ) 我希望结果的顺序将首先按列名称中的排名排序,然后按我的内容 CREATE FUNCTION PostFreeTextSearch ( @SearchTerms nvarchar(100) )
SELECT *
FROM dbo.tbl_posts
WHERE FREETEXT ( *, 'search word' )
我希望结果的顺序将首先按列名称中的排名排序,然后按我的内容
CREATE FUNCTION PostFreeTextSearch
(
@SearchTerms nvarchar(100)
)
RETURNS TABLE
AS
RETURN
(
SELECT
CASE WHEN fttName.[Key] IS NULL THEN fttContent.[Key] ELSE fttName.[Key] END as id,
fttName.[RANK] as NameScore,
fttContent.[RANK] as ContentScore
FROM
FREETEXTTABLE(tbl_Posts, (Name), @SearchTerms) fttName
FULL OUTER JOIN
FREETEXTTABLE(tbl_Posts, (Content), @SearchTerms) fttContent ON fttName.[Key] = fttContent.[Key]
WHERE fttName.RANK > 0 OR fttContent.RANK > 0
)
GO
SELECT * FROM PostFreeTextSearch('sql server')