Project

General

Profile

Download (1.36 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2015 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.hibernate.search;
10

    
11
import org.apache.log4j.Logger;
12
import org.apache.lucene.document.Document;
13
import org.apache.lucene.document.Field;
14
import org.apache.lucene.index.DocValuesType;
15

    
16
/**
17
 * @author a.kohlbecker
18
 \* @since Nov 27, 2015
19
 *
20
 */
21
public class LuceneDocumentUtility {
22

    
23
    public static final Logger logger = Logger.getLogger(LuceneDocumentUtility.class);
24

    
25
    /**
26
     * @param field
27
     * @param document
28
     */
29
    public static void setOrReplaceDocValueField(Field field, Document document) {
30

    
31
        if(field.fieldType().docValuesType().equals(DocValuesType.NONE)) {
32
            throw new IllegalArgumentException("Supplied field is not a DocValuesField");
33
        }
34

    
35
        if(document.getField(field.name()) != null) {
36
            // need to manage update by first removing the field
37
            if(logger.isTraceEnabled()) {
38
                logger.trace("update DocValueField " + field.name() + " in " + document.get("_hibernate_class") + " " + document.get("uuid"));
39
            }
40
            document.removeField(field.name());
41
        }
42
        document.add(field);
43
    }
44

    
45
}
(10-10/18)