Example usage for org.apache.lucene.index IndexWriter updateDocValues

List of usage examples for org.apache.lucene.index IndexWriter updateDocValues

Introduction

In this page you can find the example usage for org.apache.lucene.index IndexWriter updateDocValues.

Prototype

public long updateDocValues(Term term, Field... updates) throws IOException 

Source Link

Document

Updates documents' DocValues fields to the given values.

Usage

From source file:com.xiaomi.linden.core.search.LindenCoreImpl.java

License:Apache License

public Response updateDocValues(LindenDocument lindenDoc) throws IOException {
    Document doc = LindenDocParser.parse(lindenDoc, config);
    if (doc != null) {
        IndexWriter writer = trackingIndexWriter.getIndexWriter();
        List<Field> fields = new ArrayList<>();
        for (int i = 0; i < doc.getFields().size(); ++i) {
            Field field = (Field) doc.getFields().get(i);
            final FieldInfo.DocValuesType dvType = field.fieldType().docValueType();
            if (dvType == FieldInfo.DocValuesType.NUMERIC || dvType == FieldInfo.DocValuesType.BINARY) {
                fields.add(field);//w  w w . j  a va 2 s .  com
            }
        }
        if (!fields.isEmpty()) {
            writer.updateDocValues(new Term(idFieldName, lindenDoc.getId()),
                    fields.toArray(new Field[fields.size()]));
        }
        return ResponseUtils.SUCCESS;
    } else {
        return ResponseUtils.FAILED;
    }
}