Search in sources :

Example 1 with Store

use of org.apache.lucene.document.Field.Store in project gerrit by GerritCodeReview.

the class AbstractLuceneIndex method add.

void add(Document doc, Values<V> values) {
    String name = values.getField().getName();
    FieldType<?> type = values.getField().getType();
    Store store = store(values.getField());
    if (type == FieldType.INTEGER || type == FieldType.INTEGER_RANGE) {
        for (Object value : values.getValues()) {
            Integer intValue = (Integer) value;
            if (schema.useLegacyNumericFields()) {
                doc.add(new LegacyIntField(name, intValue, store));
            } else {
                doc.add(new IntPoint(name, intValue));
                if (store == Store.YES) {
                    doc.add(new StoredField(name, intValue));
                }
            }
        }
    } else if (type == FieldType.LONG) {
        for (Object value : values.getValues()) {
            addLongField(doc, name, store, (Long) value);
        }
    } else if (type == FieldType.TIMESTAMP) {
        for (Object value : values.getValues()) {
            addLongField(doc, name, store, ((Timestamp) value).getTime());
        }
    } else if (type == FieldType.EXACT || type == FieldType.PREFIX) {
        for (Object value : values.getValues()) {
            doc.add(new StringField(name, (String) value, store));
        }
    } else if (type == FieldType.FULL_TEXT) {
        for (Object value : values.getValues()) {
            doc.add(new TextField(name, (String) value, store));
        }
    } else if (type == FieldType.STORED_ONLY) {
        for (Object value : values.getValues()) {
            doc.add(new StoredField(name, (byte[]) value));
        }
    } else {
        throw FieldType.badFieldType(type);
    }
}
Also used : IntPoint(org.apache.lucene.document.IntPoint) StoredField(org.apache.lucene.document.StoredField) StringField(org.apache.lucene.document.StringField) Store(org.apache.lucene.document.Field.Store) TextField(org.apache.lucene.document.TextField) LegacyIntField(org.apache.lucene.document.LegacyIntField)

Aggregations

Store (org.apache.lucene.document.Field.Store)1 IntPoint (org.apache.lucene.document.IntPoint)1 LegacyIntField (org.apache.lucene.document.LegacyIntField)1 StoredField (org.apache.lucene.document.StoredField)1 StringField (org.apache.lucene.document.StringField)1 TextField (org.apache.lucene.document.TextField)1