开发者

How do I set order priority in full text search (Sql Server)

I have simple tbl_posts table with three c开发者_如何学编程olumns (id, name, content)

I created fulltext index for name and content columns. When I query it like:

SELECT  *
FROM    dbo.tbl_posts
WHERE   FREETEXT ( *, 'search word' )

I want that the order for results will be ordered first by rank in column name and then my content


    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')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜