在Lucene中转义特殊字符并使用通配符查询 [英] Escaping special characters in lucene and query using wildcard
问题描述
当我尝试使用通配符查询具有特殊字符的术语时遇到问题.
例如,如果我索引"Test::Here"
,则使用通配符?
来搜索"TE?T\:\:Here"
(注意:我转义了':').我没有任何结果.我使用标准分析器和queryparser进行索引和搜索.
I have an issue when I try to query using wildcard in a term that has a special character in it.
As an example if I index "Test::Here"
,I search using this using wildcard ?
for "TE?T\:\:Here"
(NOTE: I escaped ':'). I do not get any results. I use standard analyser and queryparser for indexing and searching.
有人遇到类似的问题吗?
Anyone encountered similar issue?
推荐答案
StandardAnalyzer
使用StandardTokenizer
,因此Test::Here
被视为两个标记:Test
和Here
.通配符查询不会通过分析器运行,因此最终会使冒号与不包含通配符的术语匹配.您需要使用其他令牌生成器,例如WhitespaceTokenizer
.
StandardAnalyzer
uses StandardTokenizer
, so Test::Here
is seen as two tokens: Test
and Here
. Wildcard queries are not run through an analyzer, so you end up matching colons against the terms that do not contain them. You need to use different tokenizer, for example WhitespaceTokenizer
.
这篇关于在Lucene中转义特殊字符并使用通配符查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!