SQL 包含问题

发布于 2024-11-27 23:00:45 字数 540 浏览 0 评论 0原文

有人可以向我解释一下吗?我有两个查询及其结果如下。


查询

select * from tbl where contains([name], '"*he*" AND "*ca*"')

结果集

赫兹租车

海明威的小酒馆


查询

select * from tbl where contains([name], '"*he*" AND "*ar*"')

结果集

没什么


第一个查询是我所期望的,但是我希望第二个查询返回“Hertz Car Rental”。我是否从根本上误解了“*”在全文搜索中的工作原理?

谢谢!

Can someone explain this to me? I have two queries below with their results.


query:

select * from tbl where contains([name], '"*he*" AND "*ca*"')

result-set:

Hertz Car Rental

Hemingyway's Cantina


query:

select * from tbl where contains([name], '"*he*" AND "*ar*"')

result-set:

nothing


The first query is what I would expect, however I would expect the second query to return "Hertz Car Rental". Am I fundamentally misunderstanding how '*' works in full-text searching?

Thanks!

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

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

发布评论

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

评论(3

西瓜 2024-12-04 23:00:45

我认为 SQL Server 正在将您的字符串解释为 prefix_terms。星号不是普通的旧通配符说明符。全文和包含是面向单词的。对于您想要做的事情,您最好使用普通的旧式 LIKE 而不是 CONTAINS。

http://msdn.microsoft.com/en-us/library/ms187787.aspx

I think SQL Server is interpreting your strings as prefix_terms. The asterisk is not a plain old wildcard specifier. Fulltext and Contains are word oriented. For what you are trying to do, you would be better off using plain old LIKE instead of CONTAINS.

http://msdn.microsoft.com/en-us/library/ms187787.aspx

枫以 2024-12-04 23:00:45

“*”仅用作后缀。如果用它作为前缀,无论如何都需要扫描表,索引就没用了。到时候,你不妨这样做

  Select * From Table Where (Name Like '%he%') And (Name Like '%ar%')

"*" only works as a suffix. If you use it as a prefix, the table needs to be scanned no matter what and the index is useless. At that point, you might as well do

  Select * From Table Where (Name Like '%he%') And (Name Like '%ar%')
暖心男生 2024-12-04 23:00:45

我会尝试用 % 替换 * 看看效果如何。

select * from tbl where contains([name], '"%he%" AND "%ar%"') 

I would try replacing * with % to see how it goes.

select * from tbl where contains([name], '"%he%" AND "%ar%"') 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文