简体   繁体   English

SQL Server 2016,如何在数据库的多个单词搜索中使用CONTAINS()?

[英]SQL Server 2016, How to use CONTAINS() with multiple word search of database?

New to SQL for the most part so perhaps there is a better approach but I'm looking for a way to search through a database using a textbox which can take any number of words/numbers. 大多数情况下,SQL是新手,所以也许有更好的方法,但是我正在寻找一种使用文本框搜索数据库的方法,该文本框可以包含任意数量的单词/数字。 Basically like a search engine. 基本上就像一个搜索引擎。 Columns to be searched: [Col1], [Col2], and [Col3] 要搜索的列: [Col1], [Col2], and [Col3]

I have the table Full-Text indexed, is there a way I can use CONTAINS for this? 我已为表格全文索引,是否可以使用CONTAINS

DECLARE @Search nvarchar(500)
SET @Search = 'foo 7 bar' -- can have multiple words/numbers

SELECT *
FROM TableName
WHERE CONTAINS([Col1] or [Col2] or [Col3], @Search)

I realize the last line syntax is incorrect but that's basically what I'm looking for. 我意识到最后一行语法不正确,但这基本上就是我要寻找的。 Shouldn't be exact match or case sensitive, nor should the order of wording matter ('red cat' = 'cat red') . 不应完全匹配或区分大小写,也不应该是措辞顺序('red cat' = 'cat red') Also would like to show results for close matches, ie, some of the keywords don't match anything. 还希望显示紧密匹配的结果,即某些关键字不匹配任何内容。

Thank you! 谢谢!

Your each search word must be surrounded in quotes.. 您的每个搜索词都必须用引号引起来。

'"Hi" AND "I" AND "am" AND "Yogeesha"'

For more information, Have a look at https://msdn.microsoft.com/en-US/library/ms187787(v=SQL.90).aspx 有关更多信息,请参见https://msdn.microsoft.com/zh-CN/library/ms187787(v=SQL.90).aspx

事实证明,使用FREETEXT()得出我一直在寻找的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM