What is the SQL used to do a search similar to “Related Questions” on Stackoverflow

前端 未结 8 2184
傲寒
傲寒 2020-12-30 16:08

I am trying to implement a feature similar to the "Related Questions" on Stackoverflow.

How do I go about writing the SQL statement that will search the Tit

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-30 16:37

    After enabling Full Text search on my SQL 2005 server, I am using the following stored procedure to search for text.

    ALTER PROCEDURE [dbo].[GetSimilarIssues] 
    (
     @InputSearch varchar(255)
    )
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    
    DECLARE @SearchText varchar(500);
    
    SELECT @SearchText = '"' + @InputSearch + '*"'
    
    SELECT  PostId, Summary, [Description], 
    Created
    FROM Issue
    
    WHERE FREETEXT (Summary, @SearchText);
    END
    

提交回复
热议问题