SQL Contains() not returning results for 'The'

删除回忆录丶 提交于 2021-02-04 21:10:50

问题


I have SQL script as below for querying my ContactInfoes table

SELECT * 
FROM ContactInfoes
WHERE CONTAINS(Name, 'The') 

I am getting only empty result set. I have an entry in my table with Name 'The Company'.

Why I am not getting any data here and how this can be resolved. Any help is appreciated.

I am using SQL Server 2019


回答1:


You have created FULLTEXT index without specifying STOPLIST. Thus, the default STOPLIST was used. By default the word 'the' is the stop word, that removed from your text. If you want to search by word 'the' you should create an empty STOPLIST and then specify this STOPLIST in your FULLTEXT INDEX. The default stop words you can check by query:

SELECT *
FROM sys.fulltext_system_stopwords
WHERE language_id = 1033 -- English

Then you can create empty STOPLIST:

CREATE FULLTEXT STOPLIST MyEmptyStopList;  
GO 

Then set it into your FULLTEXT INDEX:

CREATE FULLTEXT INDEX ON table_name ... STOPLIST = MyEmptyStopList;



回答2:


The simple solution for me was to turn off the stop list using below script

ALTER FULLTEXT INDEX ON [tablename]  Set StopList = OFF

I already have an index configured, which was using the default stoplist. I am turning off the stoplist here



来源:https://stackoverflow.com/questions/62061744/sql-contains-not-returning-results-for-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!