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

前端 未结 8 2158
傲寒
傲寒 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:24

    They probably relate based on tags that are added to the questions...

    0 讨论(0)
  • 2020-12-30 16:27

    I'm pretty sure it would be most efficient to implement the feature based on the tags associated with each post.

    0 讨论(0)
  • 2020-12-30 16:30

    It's probably done using a full text search which matches like words/phrases. I've used it in MySQL and SQL Server with decent success with out of the box functionality.

    You can find more on MySQL full text searches at:

    http://dev.mysql.com/doc/refman/5.1/en/fulltext-search.html

    Or just google Full Text search and you will find a lot of information.

    0 讨论(0)
  • 2020-12-30 16:30

    It looks keyword based on the title you enter, queried against titles and content of other questions. Probably easier (and more appropriate) to do in Lucene (or similar) then in a relational database.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-12-30 16:38

    I'd say it's probably a full text search on the question title and the question content and answers as well using the individual words (not the whole title) you enter. Then, using the ranking features of full-text, the top 10 or so questions that rank the highest are displayed.

    As tydok pointed out, it looks like they are using full-text searching (I couldn't imagine any other way).

    Here's the MSDN reference on Full-Text Searching, nailing the specific query used probably isn't going to happen.

    0 讨论(0)
提交回复
热议问题