用什么SQL进行类似“相关问题"的搜索?在 Stackoverflow 上 [英] What is the SQL used to do a search similar to "Related Questions" on Stackoverflow
问题描述
我正在尝试实现类似于相关问题"的功能在 Stackoverflow 上.
I am trying to implement a feature similar to the "Related Questions" on Stackoverflow.
如何编写将在我的数据库的标题和摘要字段中搜索类似问题的 SQL 语句?
How do I go about writing the SQL statement that will search the Title and Summary field of my database for similar questions?
如果我的问题是:用于执行类似于相关问题"的搜索的 SQL 是什么?在 Stackoverflow 上".
If my questions is: "What is the SQL used to do a search similar to "Related Questions" on Stackoverflow".
我能想到的步骤是;
- 去掉引号
- 将句子拆分为一组单词并对每个单词运行 SQL 搜索.
如果我这样做,我猜我不会得到任何有意义的结果.我不确定服务器上是否启用了全文搜索,所以我没有使用它.使用全文搜索会有优势吗?
If I do it this way, I am guessing that I wouldn't get any meaningful results. I am not sure if Full Text Search is enabled on the server, so I am not using that. Will there be an advantage of using Full Text Search?
我发现了一个类似的问题,但没有答案:similar question
I found a similar question but there was no answer: similar question
使用 SQL 2005
Using SQL 2005
推荐答案
在我的 SQL 2005 服务器上启用全文搜索后,我使用以下存储过程来搜索文本.
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
这篇关于用什么SQL进行类似“相关问题"的搜索?在 Stackoverflow 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!