All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.lumongo.server.index.field.DateFieldIndexer Maven / Gradle / Ivy

There is a newer version: 0.52
Show newest version
package org.lumongo.server.index.field;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.LongPoint;

import java.util.Date;

public class DateFieldIndexer extends FieldIndexer {

	public static final DateFieldIndexer INSTANCE = new DateFieldIndexer();

	protected DateFieldIndexer() {

	}

	@Override
	protected void handleValue(Document d, String storedFieldName, Object value, String indexedFieldName) throws Exception {
		if (value instanceof Date) {
			d.add(createField((Date) value, indexedFieldName));
		}
		else {
			throw new Exception(
					"Expecting collection of Date or Date for field <" + storedFieldName + "> and found <" + value.getClass().getSimpleName() + ">");
		}
	}

	protected Field createField(Date o, String indexedFieldName) {
		return new LongPoint(indexedFieldName, o.getTime());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy