Lucene 4.0 IndexWriter updateDocument 用于数字项 [英] Lucene 4.0 IndexWriter updateDocument for Numeric Term

查看:22
本文介绍了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 用于数字项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆