在Lucene中转义特殊字符并使用通配符查询 [英] Escaping special characters in lucene and query using wildcard

查看:393
本文介绍了在Lucene中转义特殊字符并使用通配符查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用通配符查询具有特殊字符的术语时遇到问题. 例如,如果我索引"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被视为两个标记:TestHere.通配符查询不会通过分析器运行,因此最终会使冒号与不包含通配符的术语匹配.您需要使用其他令牌生成器,例如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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆