我的团队也遇到了这种奇怪的标记化行为。我们的解决方法是将LOWER应用于查询和搜索文本。
正如Haroon 之前指出的那样,问题似乎源于标记器识别数字附近的某些大写货币代码并区别对待它们。以下查询说明了这一点:
SELECT * FROM sys.dm_fts_parser ('"syp 123"', 1033, 0, 0) -- Works fine
SELECT * FROM sys.dm_fts_parser ('"SYP 123"', 1033, 0, 0) -- Doesn't work
我们编写了一个脚本来识别所有表现出这种行为的 1-4 字母字符组合:
DECLARE @CurrencyCodes TABLE (CurrencyCode varchar(4), TokenCount int)
DECLARE @Start int = 65 -- A
DECLARE @End int = 90 -- Z
DECLARE @A int, @B int, @C int, @D int
SET @A = @Start
WHILE NOT (@A > @End) BEGIN
INSERT INTO @CurrencyCodes VALUES (CHAR(@A), NULL)
SET @B = @Start
WHILE NOT (@B > @End) BEGIN
INSERT INTO @CurrencyCodes VALUES (CHAR(@A) + CHAR(@B), NULL)
SET @C = @Start
WHILE NOT (@C > @End) BEGIN
INSERT INTO @CurrencyCodes VALUES (CHAR(@A) + CHAR(@B) + CHAR(@C), NULL)
SET @D = @Start
WHILE NOT (@D > @End) BEGIN
INSERT INTO @CurrencyCodes VALUES (CHAR(@A) + CHAR(@B) + CHAR(@C) + CHAR(@D), NULL)
SET @D = @D + 1
END
SET @C = @C + 1
END
SET @B = @B + 1
END
SET @A = @A + 1
END
UPDATE @CurrencyCodes SET TokenCount = (SELECT COUNT(1) FROM sys.dm_fts_parser ('"' + CurrencyCode + '123,456"', 1033, 0, 0))
SELECT CurrencyCode FROM @CurrencyCodes WHERE TokenCount = 2
从该查询中,我们发现以下 273 代码中的任何一个都会出现问题:
ADF ADP AED AFA AFN ALK ALL AMD ANG AOA AON AOR ARA ARL ARM ARP ARS ATS AUD AWG AZM AZN BAM BBD BDT BEC BEF BEL BGJ BGK BGL BGN BHD BIF BMD BND BOB BOP BOV BRB BRC BRE BRL BRN BRR BRZ BSD BTN BWP BYR BZD CAD CDF CFP CHE CHF CHW CLF CLP CNX CNY COP COU CRC CSD CSJ CSK CUP CVE CYP CZK DDM DEM DJF DKK DM DOP DZD ECS ECV EEK EGP EQE ERN ESA ESB ESP ETB EUR EURO FF FIM FJD FKP FRF GBP GEL GHC GHS GIP GMD GNE GNF GRD GTQ GWP GYD HKD HNL HRK HTG HUF IDR IEP ILP ILR ILS INR IQD IRR ISJ ISK ITL JMD JOD JPY KES KGS KHR KMF KPW KRW KWD KYD KZT LAJ LAK LBP LKR LRD LSL LTL LUF LVL LYD MAD MAF MCF MDL MGA MGF MKD MKN MMK MNT MOP MRO MTL MUR MVQ MVR MWK MXN MXP MXV MYR MZM MZN NAD NGN NIO NLG NOK NPR NZD OMR PAB PEH PEI PEN PGK PHP PKR PLN PLZ PTE PYG QAR ROL RON RSD RUB RUR RWF SAR SBD SCR SDD SDG SEK SGD SHP SIT SKK SLL SML SOS SRD SRG STD SUR SVC SYP SZL THB TJR TJS TMM TND TOP TPE TRL TRY TTD TWD TZS UAH UAK UGS UGX USD USN USS UYI UYN UYU UZS VAL VEB VEF VNC VND VUV WST XAF XAG XAU XBA XBB XBC XBD XCD XDR XEC XEU XFO XFU XOF XPD XPF XPT XTS YDD YER YUD YUM ZAL ZAR ZMK ZRN ZRZ ZWC ZWD