Lucene TermQuery and QueryParser(Lucene TermQuery 和 QueryParser)
问题描述
我有 2 个 lucene 查询:
I have 2 lucene queries:
1)
Term term = new Term(Properties.LUCENE_APPARTMENT_ADDRESS,address);
Query termQuery = new TermQuery(term);
TopDocs topDocs = indexSearcher.search(termQuery, 20);
和2)
QueryParser queryParser = new QueryParser(Version.LUCENE_36, Properties.LUCENE_APPARTMENT_ADDRESS, analyzer);
Query query = queryParser.parse(address);
ScoreDoc[] queryResults = indexSearcher.search(query, 20).scoreDocs;
为什么第一个返回 1 个结果,而第二个什么也不返回?(地址为一个字以上)
Why the first one returns 1 result where the 2nd returns nothing? (the address is one word or more)
推荐答案
当您使用 QueryParser
时,它会使用分析器执行与索引期间相同的操作序列(标记化、小写、停用词等).
When you use QueryParser
, it uses analyzer which does the same sequence of actions as when during the indexing (tokenization, lowercasing, stopwords, etc.).
当您使用原始 TermQuery
时,您需要自己完成所有这些步骤.
When you use raw TermQuery
, you need to do all these steps yourself.
我猜你的分析器对 Properties.LUCENE_APPARTMENT_ADDRESS
做了一些特别的事情,而你在将地址传递给 TermQuery
时没有这样做,因此搜索结果存在差异.
I guess your analyzer does something special about Properties.LUCENE_APPARTMENT_ADDRESS
and you are not when passing the address to TermQuery
hence the search results discrepancy.
这篇关于Lucene TermQuery 和 QueryParser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Lucene TermQuery 和 QueryParser


基础教程推荐
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 降序排序:Java Map 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01