简体   繁体   English

在SQL Server中使用全文本搜索来搜索字符串的中间部分

[英]Searching middle part of the string using Full Text Search in sql server

我无法使用全文搜索索引来搜索字符串的中间部分,例如::有一个字符串“我喜欢音乐”,我无法搜索类似的字符串中间部分。

Try LIKE operator. 尝试使用LIKE运算子。

SELECT 
    * 
FROM 
    YourTABLE 
WHERE 
    ColumnName LIKE '%like%'

Use Like keyword in query as follows: 在查询中使用Like关键字,如下所示:

select * from tablename where col like '%like%'

Here is the tutorial of like in sql: 这是sql中的like教程:

http://www.w3schools.com/sql/sql_like.asp http://www.w3schools.com/sql/sql_like.asp

Here is the MSDN: 这是MSDN:

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

Hope its helpful. 希望对您有所帮助。

Well, in order to still use the fulltext index and to avoid a table scan, try this 好吧,为了仍然使用全文索引并避免进行表扫描,请尝试以下操作

 select * 
   from yourTable
  where contains (ColumnName,'like')
    and (ColumnName not like 'like%' or ColumnName like '_%like%')

However, the query optimizer might decide that a full table scan is more effective. 但是,查询优化器可能会决定全表扫描更有效。

Check if statistics of your table out of date, especially check the statistics relates to your fulltext index. 检查表的统计信息是否过时,尤其是检查与全文索引有关的统计信息。 Since you are using SQl Server 2008, so, you can query DMV to get statistics information of your index or using DBCC to see the statistics detail information 由于使用的是SQl Server 2008,因此,您可以查询DMV以获取索引的统计信息,也可以使用DBCC查看统计信息的详细信息

DBCC SHOW_STATISTICS ("[schema].[table]",indexname);

Check the first return result, [Updated], [rows], [rows sampled], if the statistics out of date, or [rows sampled] far less than [rows], which many cause SQL Engine decided to use table scan instead of using your index. 如果统计信息已过期或[采样的行]远少于[行],请检查第一个返回结果[更新],[行],[采样的行],这很多原因是SQL引擎决定使用表扫描代替使用您的索引。

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

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