Lucene 4.0 IndexWriter更新数字术语的文档 [英] Lucene 4.0 IndexWriter updateDocument for Numeric Term

查看:144
本文介绍了Lucene 4.0 IndexWriter更新数字术语的文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道如何根据数字字段更新(删除/插入)文档。
到目前为止我做到了这一点:

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 ,然后使用 addDocument 。据我所知,这基本上就是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更新数字术语的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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