使用全文搜索查找精确匹配

发布于 2024-12-12 18:33:33 字数 601 浏览 0 评论 0原文

使用 Sql Server 2008,如何使用全文搜索来实际找到精确的字符串匹配。我对此感到非常困难,而且我在网上找不到令人满意的解决方案。

例如,如果我正在搜索字符串“Bojan Skrchevski”,我希望第一个结果正是如此。

到目前为止,我已经尝试格式化字符串,如:“Bojan* NEAR Skrchevski*”并调用 CONTAINSTABLE 来获取结果,但该字符串的格式设置为返回更多结果,如 Bojana 和 Bojananana 等。我也尝试按排名排序,但仍然没有成功。

此外,在我的字符串中,我有一个数字序列,例如:“3 1 7”,但使用当前格式,它还会返回“7 1 3”等。

示例:

DECLARE @var varchar(4000);
SET @var = '"Oxford*" NEAR 24 NEAR 7 NEAR 5 NEAR "London*"'
SELECT [Key] FROM CONTAINSTABLE(dbo.[MyTable], [MyField], @var);

我希望能够获得确切的顺序。不会得到“Oxford 7 24 5 London”的结果。

如何格式化字符串才能正确完成此操作?

Using the Sql Server 2008 how can you actually find an exact string match using full-text search. I'm having a real hard time with this and I just couldn't find a satisfactory solution anywhere online.

For example, if I'm searching for the string "Bojan Skrchevski" I want the first result to be exactly that.

So far I've tried formatting the string like: "Bojan* NEAR Skrchevski*" and call CONTAINSTABLE to get results, but this string is formatted to return more results as Bojana and Bojananana etc. I also tried to ORDER BY RANK, but still no success.

Furthermore, in my string I have a number sequence like: "3 1 7", but with the current formatting it also returns "7 1 3" etc.

Example:

DECLARE @var varchar(4000);
SET @var = '"Oxford*" NEAR 24 NEAR 7 NEAR 5 NEAR "London*"'
SELECT [Key] FROM CONTAINSTABLE(dbo.[MyTable], [MyField], @var);

I want to be able to get the exact ordering. Not to get "Oxford 7 24 5 London" as a result.

How do I format the string to accomplish this correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迟到的我 2024-12-19 18:33:33

有 2 个选项

1)
这将获得名称中包含 Mountain 的所有项目

SELECT Name, ListPrice
FROM Production.Product
WHERE ListPrice = 80.99
   AND CONTAINS(Name, 'Mountain');
GO

2)
这将获得文档中包含这 3 个字符串的所有项目,无论顺序如何

SELECT Title
FROM Production.Document
WHERE FREETEXT (Document, 'vital safety components' );

这取决于您真正想要的,但我无法完全理解。

如果我没有抓住重点,请发布一个示例以及结果应该是什么。

·克尔

克里斯托夫

There's 2 options

1)
This will get all items which have Mountain in their name

SELECT Name, ListPrice
FROM Production.Product
WHERE ListPrice = 80.99
   AND CONTAINS(Name, 'Mountain');
GO

2)
This will get all items which have these 3 strings in Document no matter what order

SELECT Title
FROM Production.Document
WHERE FREETEXT (Document, 'vital safety components' );

It depends on what you really want but I couldn't understand completely.

If I'm missing the point please post a sample and what the result should be.

kr,

Kristof

七度光 2024-12-19 18:33:33

也许一种方法是通过全文搜索选择多个结果,然后从这些结果中SELECT特定的结果。但也许可以有更好的解决方案。

我尝试了这个方法并且确实有效。它的工作速度也比仅SELECT值要快得多。

Perhaps one approach could be to select several results with the full-text search and then SELECT the specific one from those results. But maybe there could be a better solution to this.

I tried this approach and it actually worked. It also works a lot faster then to just SELECT the value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文