SQL Contains Question

帅比萌擦擦* 提交于 2019-12-01 06:05:41

问题


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!


回答1:


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




回答2:


"*" 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%')



回答3:


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

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


来源:https://stackoverflow.com/questions/6962270/sql-contains-question

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!