简体   繁体   English

Lucene:如何从索引中获取LongField

[英]Lucene : How to get LongField from index

I add a LongField into index. 我将LongField添加到索引中。

The method 方法

IndexSearcher.doc() 

returns a document, within which all fields are either 返回一个文档,其中所有字段都是

org.apache.lucene.document.Field or org.apache.lucene.document.StoredField org.apache.lucene.document.Fieldorg.apache.lucene.document.StoredField

How do I get a document from index with same field type as I put into. 如何从索引中获取与我输入的字段类型相同的文档。 So then I copy this document to another index with the same field type. 因此,然后将此文档复制到具有相同字段类型的另一个索引。

At last , I find another method IndexSearcher.doc(int, StoredFieldVisitor) (I am using lucene 4.3) 最后,我找到了另一个方法IndexSearcher.doc(int, StoredFieldVisitor) (我正在使用IndexSearcher.doc(int, StoredFieldVisitor) 4.3)

And create a custom StoredFieldVisitor 并创建一个自定义的StoredFieldVisitor

public class StaySameFieldVisitor extends DocumentStoredFieldVisitor {
@Override
public void intField(FieldInfo fieldInfo, int value) {
    getDocument().add(new IntField(fieldInfo.name, value, Store.YES));
}

@Override
public void longField(FieldInfo fieldInfo, long value) {
    getDocument().add(new LongField(fieldInfo.name, value, Store.YES));
}

@Override
public void doubleField(FieldInfo fieldInfo, double value) {
    getDocument().add(new DoubleField(fieldInfo.name, value, Store.YES));
}

@Override
public void floatField(FieldInfo fieldInfo, float value) {
    getDocument().add(new FloatField(fieldInfo.name, value, Store.YES));
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM