SQL 包含问题
有人可以向我解释一下吗?我有两个查询及其结果如下。
查询:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为 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
“*”仅用作后缀。如果用它作为前缀,无论如何都需要扫描表,索引就没用了。到时候,你不妨这样做
"*" 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
我会尝试用 % 替换 * 看看效果如何。
I would try replacing * with % to see how it goes.