[英]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:
我认为您的选择仅限于:
007440147xxx
then using 007440147*
in your query will work fine. 007440147xxx
则在查询中使用007440147*
可以正常工作。 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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.