简体   繁体   English

SQL Server 2005 Express中的全文本索引比较

[英]Full-Text Index Comparisons in SQL Server 2005 Express

How does one compare the text field of one record to all the other records in SQL server to return, for example, the top 5 most related records? 如何将一个记录的文本字段与SQL Server中的所有其他记录进行比较以返回例如最相关的前5个记录?

An example of the functionality I'm after are the various Related Posts plugins for Wordpress that produce a list of links to posts related to the post currently being viewed. 我要使用的功能的一个示例是Wordpress的各种Related Posts插件,这些插件会生成指向与当前正在查看的帖子相关的帖子的链接列表。

Cheers, Iain 干杯,伊恩

Thanks for these responses. 感谢您的答复。 I'm familiar with the referenced functions, but I'm not sure they do what I need. 我熟悉引用的函数,但是不确定它们是否可以满足我的需求。 For example: 例如:

SELECT P.id, 'Product' AS Type, FT.rank, C.url + '/' + P.url AS url, longTitle, shortTitle, P.description
FROM Products P
     INNER JOIN CONTAINSTABLE (Products, (longTitle, shortTitle), '"my text content"') AS FT ON P.id = FT.[key]
     LEFT JOIN Product_Categories PC ON P.id = PC.productID
     LEFT Join Categories C ON C.id = PC.categoryID
WHERE [primary] = 1
ORDER BY rank DESC

returns only rows with the exact phrase "my text content" - I need rows with only "text" to be returned, but at a lower rank. 仅返回带有确切短语“我的文本内容”的行-我需要返回仅包含“文本”的行,但排位较低。 If I change the query as follows: 如果我将查询更改如下:

SELECT P.id, 'Product' AS Type, FT.rank, C.url + '/' + P.url AS url, longTitle, shortTitle, P.description
FROM Products P
     INNER JOIN CONTAINSTABLE (Products, (longTitle, shortTitle), '"my" or "text" or "content"') AS FT ON P.id = FT.[key]
     LEFT JOIN Product_Categories PC ON P.id = PC.productID
     LEFT Join Categories C ON C.id = PC.categoryID
WHERE [primary] = 1
ORDER BY rank DESC

I get more rows, but rows with all three words don't appear to rank clearly higher than rows with 1 of the words. 我得到的行更多,但是包含所有三个单词的行的排名似乎显然没有高于包含其中一个单词的行的排名。

Any further thoughts? 还有其他想法吗?

You need to use CONTAINSTABLE , this returns a RANK column you can use to sort by. 您需要使用CONTAINSTABLE,这将返回一个RANK列,您可以使用该列进行排序。

SELECT TOP 5 [Key] FROM CONTAINSTABLE ([YourFullText],'SomethingToSearch')
ORDER BY [RANK] DESC

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM