当前位置: 首页>>代码示例>>Java>>正文


Java DateUtil类代码示例

本文整理汇总了Java中org.apache.solr.common.util.DateUtil的典型用法代码示例。如果您正苦于以下问题:Java DateUtil类的具体用法?Java DateUtil怎么用?Java DateUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DateUtil类属于org.apache.solr.common.util包,在下文中一共展示了DateUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildSolrQueryValue

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
public static String buildSolrQueryValue(Object o){
    if(o != null){
        if(ZonedDateTime.class.isAssignableFrom(o.getClass())) {
            return ((ZonedDateTime)o).format(DateTimeFormatter.ISO_INSTANT);
        }
        if(Date.class.isAssignableFrom(o.getClass())) {
            return DateUtil.getThreadLocalDateFormat().format((Date)o);
        }
        if(DateMathExpression.class.isAssignableFrom(o.getClass())) {
            //TODO: Do not delegate on the toString DateMath, a solr specific parse would be better
            DateMathExpression dateMath = (DateMathExpression) o;
            return dateMath.toString();
        }
        if(ByteBuffer.class.isAssignableFrom(o.getClass())) {
            return new String (((ByteBuffer) o).array());
        }
        return o.toString(); //TODO check if this is this correct

    }
    return "";
}
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:22,代码来源:SolrUtils.java

示例2: transformValue

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
/**
 * Can be used to transform input values based on their {@link org.apache.solr.schema.SchemaField}
 * <p/>
 * This implementation only formats dates using the {@link org.apache.solr.common.util.DateUtil}.
 *
 * @param val    The value to transform
 * @param schFld The {@link org.apache.solr.schema.SchemaField}
 * @return The potentially new value.
 */
protected String transformValue(String val, SchemaField schFld) {
  String result = val;
  if (schFld != null && schFld.getType() instanceof DateField) {
    //try to transform the date
    try {
      Date date = DateUtil.parseDate(val, dateFormats);
      DateFormat df = DateUtil.getThreadLocalDateFormat();
      result = df.format(date);

    } catch (Exception e) {
      // Let the specific fieldType handle errors
      // throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Invalid value: " + val + " for field: " + schFld, e);
    }
  }
  return result;
}
 
开发者ID:europeana,项目名称:search,代码行数:26,代码来源:SolrContentHandler.java

示例3: testTransformValue

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
/**
 * Test that the ContentHandler properly strips the illegal characters
 */
@Test
public void testTransformValue() {
  String fieldName = "user_name";
  assertFalse("foobar".equals(getFoobarWithNonChars()));

  Metadata metadata = new Metadata();
  // load illegal char string into a metadata field and generate a new document,
  // which will cause the ContentHandler to be invoked.
  metadata.set(fieldName, getFoobarWithNonChars());
  StripNonCharSolrContentHandlerFactory contentHandlerFactory =
    new StripNonCharSolrContentHandlerFactory(DateUtil.DEFAULT_DATE_FORMATS);
  IndexSchema schema = h.getCore().getLatestSchema();
  SolrContentHandler contentHandler =
    contentHandlerFactory.createSolrContentHandler(metadata, new MapSolrParams(new HashMap()), schema);
  SolrInputDocument doc = contentHandler.newDocument();
  String foobar = doc.getFieldValue(fieldName).toString();
  assertTrue("foobar".equals(foobar));
}
 
开发者ID:europeana,项目名称:search,代码行数:22,代码来源:SolrCellMorphlineTest.java

示例4: getObjectFrom

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
public static Object getObjectFrom( String val, String type )
{
  if( type != null ) {
    try {
      if( "int".equals( type ) ) return Integer.valueOf( val );
      if( "double".equals( type ) ) return Double.valueOf( val );
      if( "float".equals( type ) ) return Float.valueOf( val );
      if( "date".equals( type ) ) return DateUtil.parseDate(val);
    }
    catch( Exception ex ) {
      throw new SolrException( ErrorCode.BAD_REQUEST,
          "Unable to parse "+type+"="+val, ex );
    }
  }
  return val;
}
 
开发者ID:europeana,项目名称:search,代码行数:17,代码来源:ValueAugmenterFactory.java

示例5: correctDate

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
private Object correctDate(Object mayBeDate) {
    try {
        Calendar calendar = Value.iso8601ToCalendar(String.valueOf(mayBeDate));
        return DateUtil.getThreadLocalDateFormat().format(calendar.getTime());
    } catch (ParseException e) {
        // Try with RFC
        try {
            Date contentAsDate = RFC822DateUtil.parse(String.valueOf(mayBeDate));
            // Convert RFC822 (Google connector dates) to Solr dates
            return DateUtil.getThreadLocalDateFormat().format(contentAsDate);
        } catch (ParseException ee) {
            // Ignored or is not a date
            return mayBeDate;
        }
    }
}
 
开发者ID:BassJel,项目名称:Jouve-Project,代码行数:17,代码来源:IndexFieldServicesImpl.java

示例6: addField

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
private static void addField(SolrInputDocument doc, Record record, String indexFieldName) {
    IndexField indexField = record.getConnectorInstance().getRecordCollection().getIndexField(
        indexFieldName);
    IndexFieldServices indexFieldServices = ConstellioSpringUtils.getIndexFieldServices();
    List<Object> fieldValues = indexFieldServices.extractFieldValues(record, indexField);
    for (Object fieldValue : fieldValues) {
        try {
            Calendar calendar = Value.iso8601ToCalendar(String.valueOf(fieldValue));
            fieldValue = DateUtil.getThreadLocalDateFormat().format(calendar.getTime());
        } catch (ParseException e) {
            // Try with RFC
            try {
                Date contentAsDate = RFC822DateUtil.parse(String.valueOf(fieldValue));
                // Convert RFC822 (Google connector dates) to Solr dates
                fieldValue = DateUtil.getThreadLocalDateFormat().format(contentAsDate);
            } catch (ParseException ee) {
                // Ignored
            }
        }
        doc.addField(indexFieldName, fieldValue);
    }
}
 
开发者ID:BassJel,项目名称:Jouve-Project,代码行数:23,代码来源:ServicesTestUtils.java

示例7: castForDescriptor

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
private static Object castForDescriptor(String s, Class<?> type) {

            if(Long.class.isAssignableFrom(type)) {
                return Long.valueOf(s);
            }
            if(Integer.class.isAssignableFrom(type)) {
                return Integer.valueOf(s);
            }
            if(Double.class.isAssignableFrom(type)) {
                return Double.valueOf(s);
            }
            if(Number.class.isAssignableFrom(type)) {
                return Float.valueOf(s);
            }
            if(Boolean.class.isAssignableFrom(type)) {
                return Boolean.valueOf(s);
            }
            if(ZonedDateTime.class.isAssignableFrom(type)) {
                return ZonedDateTime.parse(s);
            }
            if(Date.class.isAssignableFrom(type)) {
                try {
                    return DateUtil.parseDate(s);
                } catch (ParseException e) {
                    log.error("Unable to parse value '{}' to valid Date", s);
                    throw new RuntimeException(e);
                }
            }
            if(ByteBuffer.class.isAssignableFrom(type)) {
                return ByteBuffer.wrap(s.getBytes(UTF_8));
            }
            return s;
        }
 
开发者ID:RBMHTechnology,项目名称:vind,代码行数:34,代码来源:SolrUtils.java

示例8: write

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
public void write(NutchDocument doc) throws IOException {
  final SolrInputDocument inputDoc = new SolrInputDocument();

  for (final Entry<String, NutchField> e : doc) {
    for (final Object val : e.getValue().getValues()) {
      // normalise the string representation for a Date
      Object val2 = val;

      if (val instanceof Date) {
        val2 = DateUtil.getThreadLocalDateFormat().format(val);
      }

      if (e.getKey().equals("content") || e.getKey().equals("title")) {
        val2 = SolrUtils.stripNonCharCodepoints((String) val);
      }

      inputDoc.addField(solrMapping.mapKey(e.getKey()), val2, e.getValue()
          .getWeight());
      String sCopy = solrMapping.mapCopyKey(e.getKey());
      if (sCopy != e.getKey()) {
        inputDoc.addField(sCopy, val);
      }
    }
  }

  inputDoc.setDocumentBoost(doc.getWeight());
  inputDocs.add(inputDoc);
  totalAdds++;

  if (inputDocs.size() + numDeletes >= batchSize) {
    push();
  }
}
 
开发者ID:jorcox,项目名称:GeoCrawler,代码行数:34,代码来源:SolrIndexWriter.java

示例9: asTimestamp

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
public Date asTimestamp(Object obj) throws ParseException {
  Date ts;
  if (obj instanceof String) {
    ts = DateUtil.parseDate((String) obj);
  } else if (obj instanceof Date) {
    ts = (Date)obj;
  } else if (obj instanceof Calendar) {
    ts = ((Calendar)obj).getTime();
  } else if (obj instanceof Long) {
    ts = new Date((Long)obj);
  } else {
    ts = DateUtil.parseDate(obj.toString());
  }
  return ts;
}
 
开发者ID:lucidworks,项目名称:storm-solr,代码行数:16,代码来源:CollectionPerTimeFrameAssignmentStrategy.java

示例10: read

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
@Override 
public Date read( String txt ) { 
  try {
    return DateUtil.parseDate(txt);      
  }
  catch( Exception ex ) {
    ex.printStackTrace();
  }
  return null;
}
 
开发者ID:europeana,项目名称:search,代码行数:11,代码来源:XMLResponseParser.java

示例11: testFacetDateRange

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
public void testFacetDateRange() {
  SolrQuery q = new SolrQuery("dog");
  Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.UK);
  calendar.set(2010, 1, 1);
  Date start = calendar.getTime();
  calendar.set(2011, 1, 1);
  Date end = calendar.getTime();
  q.addDateRangeFacet("field", start, end, "+1MONTH");
  assertEquals("true", q.get(FacetParams.FACET));
  assertEquals("field", q.get(FacetParams.FACET_RANGE));
  assertEquals(DateUtil.getThreadLocalDateFormat().format(start), q.get("f.field." + FacetParams.FACET_RANGE_START));
  assertEquals(DateUtil.getThreadLocalDateFormat().format(end), q.get("f.field." + FacetParams.FACET_RANGE_END));
  assertEquals("+1MONTH", q.get("f.field." + FacetParams.FACET_RANGE_GAP));
}
 
开发者ID:europeana,项目名称:search,代码行数:15,代码来源:SolrQueryTest.java

示例12: getInitializedOn

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
/**
 * Returns this resource's initialization timestamp.
 */
public String getInitializedOn() {
  if (initializedOn == null)
    return null;
  
  StringBuilder dateBuf = new StringBuilder();
  try {
    DateUtil.formatDate(initializedOn, null, dateBuf);
  } catch (IOException e) {
    // safe to ignore
  }
  return dateBuf.toString();
}
 
开发者ID:europeana,项目名称:search,代码行数:16,代码来源:ManagedResource.java

示例13: getUpdatedSinceInitialization

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
/**
 * Returns the timestamp of the most recent update,
 * or null if this resource has not been updated since initialization.
 */
public String getUpdatedSinceInitialization() {
  String dateStr = null;
  if (lastUpdateSinceInitialization != null) {
    StringBuilder dateBuf = new StringBuilder();
    try {
      DateUtil.formatDate(lastUpdateSinceInitialization, null, dateBuf);
      dateStr = dateBuf.toString(); 
    } catch (IOException e) {
      // safe to ignore here
    }
  }
  return dateStr;
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:ManagedResource.java

示例14: parseDateLenient

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
/** Parse a date string in the standard format, or any supported by DateUtil.parseDate */
public Date parseDateLenient(String s, SolrQueryRequest req) throws ParseException {
  // request could define timezone in the future
  try {
    return fmtThreadLocal.get().parse(s);
  } catch (Exception e) {
    return DateUtil.parseDate(s);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:DateField.java

示例15: getDateRangeQuery

import org.apache.solr.common.util.DateUtil; //导入依赖的package包/类
/**
 * @param field range field name.
 * @param now   range upper bound.
 * @return a TermRangeQuery in an interval from infinity to now.
 */
private static TermRangeQuery getDateRangeQuery(String field, Date now) {
    return new TermRangeQuery(field,
            null,
            new BytesRef(DateUtil.getThreadLocalDateFormat().format(now)),
            true, true);
}
 
开发者ID:imCodePartnerAB,项目名称:imcms,代码行数:12,代码来源:LifeCyclePhase.java


注:本文中的org.apache.solr.common.util.DateUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。