问题描述
在Lucene中,使用标准分析器,我想使带有空格和特殊字符(下划线,!,@,#,....)的字段可搜索.
In Lucene, using a Standard Analyzer, I want to make fields with spaces and special characters(underscore,!,@,#,....) searchable.
我将IndexField设置为NOT_ANALYZED_NO_NORMS和Field.Store.YES
I set IndexField to NOT_ANALYZED_NO_NORMS and Field.Store.YES
当我在LUKE中查看索引时,这些字段符合我的预期,例如:
When I look at my index in LUKE, the fields are as I expected, a value such as:
"SKU编号",但是当我搜索"SKU"或"SKU *"时,什么都没有出现.
'SKU Number', yet when I search for 'SKU' or 'SKU*' nothing comes up.
我想念什么?
推荐答案
搜索"SKU"将不起作用,因为您已使用NOT_ANALYZED进行了索引; "SKU编号"是整个索引词.如果您想按空格分隔单词,那就是ANALYZED的目的.
Searching for 'SKU' won't work because you indexed with NOT_ANALYZED; 'SKU Number' is the entire indexed term. If you want words split by whitespace, that's what ANALYZED is for.
现在,除了默认情况下,lucene QueryParser小写的扩展术语之外,现在可以进行前缀搜索"SKU *".设置 lowercaseExpandedTerms 在解析器上设置为False.
Now doing a prefix search, 'SKU*', would work except by default the lucene QueryParser lowercases expanded terms. Set lowercaseExpandedTerms on the parser to False.
这篇关于在Lucene中,使用标准分析器,我想使带有空格和特殊字符的字段可搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!