Lucene 4.0 IndexWriter updateDocument for Numeric Term(Lucene 4.0 IndexWriter updateDocument 用于数字项)
问题描述
我只是想知道如何根据数字字段更新(删除/插入)文档.到目前为止,我这样做了:
I just wanted to know how it is possible to to update (delete/insert) a document based on a numeric field. So far I did this:
LuceneManager.updateDocument(writer, new Term("id", NumericUtils.intToPrefixCoded(sentenceId)), newDoc);
但现在在 Lucene 4.0 中,NumericUtils 类已更改为 this 我不太明白.有什么帮助吗?
But now with Lucene 4.0 the NumericUtils class has changed to this which I don't really understand. Any help?
推荐答案
我会建议,如果可能的话,最好将 ID 存储为关键字字符串,而不是数字.如果它只是一个唯一标识符,那么将索引作为关键字更有意义.这消除了任何与数字格式混淆的需要.
I would recommend, if possible, it would be better to store an ID as a keyword string, rather than a number. If it is simply a unique identifier, indexing as a keyword makes much more sense. This removes any need to mess with numeric formatting.
如果它实际上被用作数字,那么您可能需要手动执行更新.也就是说,搜索并获取要更新的文档,使用 tryDeleteDocument,然后用 添加文档.据我所知,这基本上就是 updateDocument 所做的.
If it is actually being used as a number, then you might need to perform the update manually. That is, search for and fetch the document you wish to update, delete the old document with tryDeleteDocument, and then add the updated version with addDocument. This is basically what updateDocument does anyway, to my knowledge.
不过,第一个选项肯定是更好的方法.用作更新 ID 的非数字字段会让生活更轻松.
The first option would certainly be the better way, though. A non-numeric field to use as an update ID would make life easier.
这篇关于Lucene 4.0 IndexWriter updateDocument 用于数字项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Lucene 4.0 IndexWriter updateDocument 用于数字项


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