package gw.solr.mapper uses gw.api.util.Range uses gw.api.util.UltraFastDateFormat uses gw.solr.utils.PLSolrDateUtil uses gw.solr.utils.PLSolrUtils uses gw.xsd.config.solr_search_config.DataProperty uses java.lang.ThreadLocal uses java.text.DateFormat uses java.text.SimpleDateFormat uses java.util.Date uses java.util.List @ReadOnly class BuildDate implements ISolrIndexMapper, ISolrQueryMapper> { /** * Parse dates in UTC (GMT) time when receiving Strings from Solr TrieDateField type. * Mirrors settings used inside Solr for interpreting and formatting these date strings. * See org.apache.solr.schema.DateField.ISO8601CanonicalDateFormat */ public static final var DATE_FORMAT : String = "yyyy-MM-dd'T'HH:mm:ss'Z'" public static final var DATE_FORMATTER : UltraFastDateFormat = UltraFastDateFormat.getInstance(DATE_FORMAT, PLSolrDateUtil.CANONICAL_TZ, PLSolrDateUtil.CANONICAL_LOCALE) public static final var DATE_PARSER : ThreadLocal = new ThreadLocal() { override function initialValue() : DateFormat { return new SolrCanonicalDateFormat(DATE_FORMAT) } } private static class SolrCanonicalDateFormat extends SimpleDateFormat { construct(format : String) { super(format, PLSolrDateUtil.CANONICAL_LOCALE) this.TimeZone = PLSolrDateUtil.CANONICAL_TZ } } /** * Converts an instance of Date type to the format expected by a Solr TrieDateField type. * * @param inputDataProperties array of entity properties * @param nameToIndexDataMap map of keys to data * * @return string in the format expected by a Solr TrieDateField type. */ override function mapIndex(inputDataProperties : List, dataHolder : IDataHolder) : Date { PLSolrUtils.validate(inputDataProperties.Count == 1, "Date index mapper only supports a single target field.") var date = dataHolder.lookup(inputDataProperties.get(0)) return date != null ? date : null } /** * Map a date range into the proper format for a Solr range query value */ override function mapQuery(queryDataProperties : List, dataHolder : IDataHolder) : Range { PLSolrUtils.validate( queryDataProperties.Count == 1, "Date query mapper only supports a single criterion.") // Can't look this up as Range because the part got erased var rawValue = dataHolder.lookup(queryDataProperties.get(0)) return rawValue as Range } }