为什么SQL全文索引不返回包含#的单词的结果?

时间:2020-03-05 18:37:29  来源:igfitidea点击:

例如,我的查询类似于使用SQL Server 2005的以下查询:

SELECT * FROM Table WHERE FREETEXT(SearchField, 'c#')

我定义了全文索引以使用列SearchField,该列在使用时返回结果:

SELECT * FROM Table WHERE SearchField LIKE '%c#%'

我相信这是一个特殊的字母,那么如何允许FREETEXT在上述查询中正常工作?

解决方案

回答

引用有关索引服务查询语言的大量重复的帮助页面:

To use specially treated characters such as &, |, ^, #, @, $, (, ), in a query, enclose your query in quotation marks (“).

据我所知,索引服务也可以在MSSQL中进行全文搜索,因此这可能会有所帮助。

回答

char被标为标点符号,因此被忽略,因此看起来我们将从单词索引忽略列表中删除了字母C。

完成此操作并重建索引后,在本地对其进行了测试,我得到了结果!

考虑在索引列上使用其他分词系统语言,以便那些特殊字符不会被忽略。

编辑:我还发现此信息:

c# is indexed as c (if c is not in your noise word list, see more on noise word lists later), but C# is indexed as C# (in SQL 2005 and SQL 2000 running on Win2003 regardless if C or c is in your noise word list). It is not only C# that is stored as C#, but any capital letter followed by #. Conversely, c++ ( and any other lower-cased letter followed by a ++) is indexed as c (regardless of whether c is in your noise word list).