在SQL Server中,如何配置全文检索索引1/2,1/3,1/4,等等
问题描述:
我已经创建了替代辞典条目以下:在SQL Server中,如何配置全文检索索引1/2,1/3,1/4,等等
Pair: 1/2, half
Pair: 1/3, third
Pair: 1/4, quarter
Pair: 1/8, eighth
当我做一个搜索一个搜索词,如“1/2英寸管道”,我应该找回包含“1/2”以及“half”的行。我有两个这样的行。但是,通过默认全文搜索,似乎“1/2”未包含在所讨论列的全文索引结果中。
我还没有找到一个明确的答案,关于什么,在哪里,如何配置全文索引的重新索引,以便全文搜索条件包括允许1/2,1/3等。对于这个问题,我还需要在全文搜索中使用单个数字。
如果有人能指导我介绍一些文件,说明我可以完成这项任务的步骤,我将不胜感激。
答
sys.dm_fts_parser是一个很棒的DMF,它可以帮助您了解Fulltext如何解析句子以及哪些单词将存储在内部索引中。关于第一个例子中我看到下面的输出 -
select * from sys.dm_fts_parser(N'"Pair: 1/2, half"', 1033, 0, 0)
keyword group_id phrase_id occurrence special_term display_term expansion_type source_term
0x0070006100690072 1 0 1 Exact Match pair 0 Pair: 1/2, half
0x0031 1 0 2 Noise Word 1 0 Pair: 1/2, half
0x006E006E0031 1 0 2 Noise Word nn1 0 Pair: 1/2, half
0x0032 1 0 3 Noise Word 2 0 Pair: 1/2, half
0x006E006E0032 1 0 3 Noise Word nn2 0 Pair: 1/2, half
0x00680061006C0066 1 0 4 Exact Match half 0 Pair: 1/2, half
FT打破了“1/2”和索引它为1,NN1,2和NN2(“N-N”为数字值的内部表示)。在这种情况下,正在使用默认停止列表,这另外导致这些值被标记为噪音词,因此它们不会被添加到索引中。通过从停止列表中删除条目或创建新的空白停止列表并将其与索引关联起来,这很简单。
到目前为止,根本没有任何方法让FT忽略在这种情况下它被视为字分隔符的'/'符号。
编辑 - 显然,有一个解决方法,它涉及到创建一个自定义字典为detailed here。因此,对于英文,我在Binn目录中创建了一个'Custom0009.lex'文件,并为'/'添加了一个条目。这样做显示sys.dm_fts_parser以下输出(不要忘记fdhost重启) -
select * from sys.dm_fts_parser(N'"Pair: 1/2, half"', 1033, NULL, 0)
keyword group_id phrase_id occurrence special_term display_term expansion_type source_term
0x0070006100690072 1 0 1 Exact Match pair 0 Pair: 1/2, half
0x0031 1 0 2 Exact Match 1 0 Pair: 1/2, half
0x006E006E0031 1 0 2 Exact Match nn1 0 Pair: 1/2, half
0x002F 1 0 3 Exact Match/ 0 Pair: 1/2, half
0x0032 1 0 4 Exact Match 2 0 Pair: 1/2, half
0x006E006E0032 1 0 4 Exact Match nn2 0 Pair: 1/2, half
0x00680061006C0066 1 0 5 Exact Match half 0 Pair: 1/2, half
希望这有助于。
只有评论。什么是单词的规则尚不清楚。停用词可以用来消除。看起来单个数字不被视为一个单词,并且/被视为单词中断。我希望你能得到答案。不知道Lucene有多少控制权,但需要考虑。 – Paparazzi 2013-04-04 20:54:52
不知道我明白你的意思,“当我用搜索词搜索例如”1/2英寸管道“时,我应该找回包含”1/2“以及”half“的行!你是否希望Fulltext将“1/2”和“half”解释为等同的表示? – aks 2013-07-09 00:50:35