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 用于数字项
基础教程推荐
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
