我有一个简单的tbl_posts表,其中包含三列(id、name、content)
我为名称和内容列创建了全文索引。当我像这样查询它时:
SELECT *
FROM dbo.tbl_posts
WHERE FREETEXT ( *, 'search word' )
我希望结果的顺序将首先按列名中的排名,然后是我的内容
我有一个简单的tbl_posts表,其中包含三列(id、name、content)
我为名称和内容列创建了全文索引。当我像这样查询它时:
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')