Lucene的新手在这里。我在Java客户端中将它与Hibernate一起使用,并且在特定查询中遇到此错误:
HSEARCH000146: The query string 'a' applied on field 'name' has no meaningfull tokens to be matched. Validate the query input against the Analyzer applied on this field.
搜索适用于所有其他查询,即使结果集为空。我的测试数据库确实具有“ a”的记录。这有什么问题吗?
“ a”是停用词,StandardAnalyzer会将其从查询中过滤掉。停用词是在您使用的搜索语言中足够普遍的词,并且对生成搜索结果没有意义。这是一个简短的列表,但是“ a”是英语中的一个。
由于分析器已经摆脱了该术语,并且它是当前存在的唯一术语,因此您现在正在发送一个空查询,这是不可接受的,并且搜索失败。
出于好奇,这些是标准的Lucene英语停用词:
"a", "an", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"
如果您不希望删除停用词,则应设置Analyzer不带StopFilter或设置为空的停用词的。对于StandardAnalyzer,您可以将自定义停止集传递给构造函数:
Analyzer
StopFilter
StandardAnalyzer
Analyzer analyzer = new StandardAnalyzer(CharArraySet.EMPTY_SET);