我的 Sql Server 存储过程中的搜索查询出现问题

发布于 2024-07-23 07:34:35 字数 280 浏览 5 评论 0原文

我有以下存储过程:-

SELECT Id, Name
FROM FooBars
WHERE CONTAINS(Name, 'FORMSOF(Tesaurus, @query)')

当查询中有一个单词时工作正常:例如。 富* 但当我想要寻找多个单词时,它就会失败。 例如。 foo* bar* (这意味着任何包含以 foo 开头和以 bar 开头的单词的行)。

我的 @query 参数需要采用什么格式才能启用同义词库的全文搜索的多个单词?

I have the following stored proc :-

SELECT Id, Name
FROM FooBars
WHERE CONTAINS(Name, 'FORMSOF(Tesaurus, @query)')

Works fine when there is one word i the query: eg. foo*
But it fails when I want to have more than one word which i'm trying to look for.
eg. foo* bar* (this means any rows that have words that start with foo and start with bar).

What format does my @query argument need to look like, to enable multiple words for a Full Text Search with a Thesaurus?

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

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

发布评论

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

评论(1

明天过后 2024-07-30 07:34:35

据我所知,如果您想搜索两个或多个表达式,则需要将它们与 AND、OR 或 NEAR 连接起来,如下所示(直接来自在线图书):

USE AdventureWorks;
GO

SELECT Name
FROM Production.Product
WHERE CONTAINS(Name, '"chain*" OR "full*"');
GO

SELECT Description
FROM Production.ProductDescription
WHERE CONTAINS(Description, 'bike NEAR performance');
GO

SELECT Description
FROM Production.ProductDescription
WHERE ProductDescriptionID <> 5 AND
CONTAINS(Description, ' Aluminum AND spindle');

If and how that will work with your FORMSOF (...) 我不清楚表达方式 - 但我相信你可以很快尝试一下,不是吗?

SELECT Id, Name
FROM FooBars
WHERE CONTAINS(Name, 'FORMSOF(THESAURUS, "foo*")'
    OR 'FORMSOF(THESAURUS, "bar*")')

还要确保在 FORMSOF () 表达式中正确拼写“thesaurus”! :-)

马克

As far as I know, if you want to search for two or more expressions, you need to concatenate those with either AND, OR or NEAR, something like this (straight from Books Online):

USE AdventureWorks;
GO

SELECT Name
FROM Production.Product
WHERE CONTAINS(Name, '"chain*" OR "full*"');
GO

SELECT Description
FROM Production.ProductDescription
WHERE CONTAINS(Description, 'bike NEAR performance');
GO

SELECT Description
FROM Production.ProductDescription
WHERE ProductDescriptionID <> 5 AND
CONTAINS(Description, ' Aluminum AND spindle');

If and how that would work together with your FORMSOF(...) expression is unclear to me - but I'm sure you could quickly try that, no?

SELECT Id, Name
FROM FooBars
WHERE CONTAINS(Name, 'FORMSOF(THESAURUS, "foo*")'
    OR 'FORMSOF(THESAURUS, "bar*")')

Also make sure to spell "thesaurus" correctly in your FORMSOF () expression! :-)

Marc

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