简体   繁体   English

全文搜索号码在SQL Server 2012中不起作用

[英]Fulltext search numbers does not work in SQL Server 2012

Fulltext search numbers does not work in SQL Server 2012. 全文搜索号码在SQL Server 2012中不起作用。

I tried to create an empty_stoplist and repopulate the index. 我试图创建一个empty_stoplist并重新填充索引。 Can anyone tell me what I am doing wrong here? 谁能告诉我我在做什么错?

CREATE FULLTEXT CATALOG Orders_FTS
WITH ACCENT_SENSITIVITY = OFF;
GO

CREATE FULLTEXT INDEX ON dbo.Orders
( 
     a Language 1031,
     b Language 1031,
     c Language 1031,
     d Language 1031
) 
KEY INDEX [PK_Orders]
ON Orders_FTS; 
GO

CREATE FULLTEXT STOPLIST EMPTY_STOPLIST;
ALTER FULLTEXT STOPLIST empty_stoplist DROP ALL;
ALTER FULLTEXT INDEX ON Orders SET STOPLIST EMPTY_STOPLIST;
ALTER FULLTEXT INDEX ON Orders SET STOPLIST = OFF;
ALTER FULLTEXT INDEX ON Orders START UPDATE POPULATION;

The SQL query: SQL查询:

SELECT
    T.*, R.RANK 
FROM  
    Orders As T 
INNER JOIN  
    CONTAINSTABLE(Orders, *, '"*007440147*"') AS R  On T.ID = R.[KEY]  
ORDER BY 
    RANK DESC, ID DESC

The problem is that leading wildcards (ex: *bcde ) are not supported by SQL Server. 问题是SQL Server不支持前导通配符(例如: *bcde )。 (More here .) The query will execute without any errors but will always return 0 results. (更多信息 。)查询将执行,没有任何错误,但始终返回0个结果。 You can only use wildcards in the middle of a string (ex: ab*de ) or the end of a string (ex: abcd* ). 您只能在字符串中间(例如: ab*de )或字符串末尾(例如: abcd* )使用通配符。

Usually this can be worked around by creating columns that contain the reverse string and searching on those columns (ex: Column1 = abcde , Column1Reverse = edcba , query has CONTAINS(Column1Reverse, '"edcb*"') ). 通常,可以通过创建包含反向字符串的列并在这些列上进行搜索来解决此问题(例如:Column1 = abcde ,Column1Reverse = edcba ,查询具有CONTAINS(Column1Reverse, '"edcb*"') ))。

However in your case you want to use a wildcard at the beginning and end of the string. 但是,在您的情况下,您想在字符串的开头结尾使用通配符。 I think your options are limited to: 我认为您的选择仅限于:

  1. If you don't need a leading wildcard, then don't use it. 如果您不需要前导通配符,请不要使用它。 For example, if the text you are trying to match is 007440147xxx then using 007440147* in your query will work fine. 例如,如果您尝试匹配的文本是007440147xxx则在查询中使用007440147*可以正常工作。
  2. Use LIKE instead of CONTAINSTABLE , for example: SELECT * FROM Orders WHERE Column1 LIKE '%007440147%' . 使用LIKE代替CONTAINSTABLE ,例如: SELECT * FROM Orders WHERE Column1 LIKE '%007440147%' The downside to this approach is that you won't get a rank value and queries may take a long time to execute. 这种方法的缺点是您不会获得等级值,并且查询可能需要很长时间才能执行。 (Then again, even if you could use a leading wildcard in full text searches, they would be slow.) (再次,即使您可以在全文搜索中使用前导通配符,它​​们的速度也会很慢。)
  3. Redesign how the data is stored and queried. 重新设计如何存储和查询数据。 I can't offer any suggestions without understanding what these numbers mean and how they need to be queried. 如果不了解这些数字的含义以及如何查询它们,我将无法提供任何建议。
  4. Consider using another search product. 考虑使用其他搜索产品。 I believe Lucene can perform leading wildcard searches but such searches tend to be slow. 我相信Lucene可以执行领先的通配符搜索,但是这种搜索往往很慢。

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

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