Sql-Server

全文搜尋找不到不完整的單詞

  • December 25, 2021

我使用的是sql server 2019,我根據微軟的例子創建了全文索引,但是有一個問題,在文本中搜尋部分單詞時,沒有結果

sql伺服器版本:

Microsoft SQL Server 2019 (RTM-CU13) (KB5005679) - 15.0.4178.1 (X64) 
   Sep 23 2021 16:47:49 
   Copyright (C) 2019 Microsoft Corporation
   Enterprise Edition (64-bit) on Windows Server 2019 Datacenter 10.0 <X64> (Build 17763: ) (Hypervisor)

例如 :

CREATE TABLE Flags (Country nvarchar(30) NOT NULL, FlagColors varchar(200));  
CREATE UNIQUE CLUSTERED INDEX FlagKey ON Flags(Country);  
INSERT Flags VALUES ('France', 'Blue and White and Red');  
INSERT Flags VALUES ('Italy', 'Green and White and Red');  
INSERT Flags VALUES ('Tanzania', 'Green and Yellow and Black and Yellow and Blue');  
SELECT * FROM Flags;  
GO  
 
CREATE FULLTEXT CATALOG TestFTCat;  
CREATE FULLTEXT INDEX ON Flags(FlagColors) KEY INDEX FlagKey ON TestFTCat;  
GO   

現在我搜尋這個詞blu,但儘管這個詞沒有結果blue(我需要一個模糊搜尋)

像這樣的查詢:

SELECT * FROM FREETEXTTABLE (Flags, FlagColors, 'Blu');  

是什麼原因?

試試這個:

SELECT *  FROM flags WHERE CONTAINS(FlagColors,'"Blu*"') ;

https://docs.microsoft.com/en-gb/archive/blogs/sqlforum/faq-how-can-i-perform-wildcard-searches-in-full-text-search

引用自:https://dba.stackexchange.com/questions/305230