使用solr的时候如果把date类型转换成tlong型数据,非常不方便,写入的时候要转换,返回的时候要转换,查询的时候要转换非常不方便,可以用tdate这个类型,使用这个有关注意事项是solr是用世界标准时间去格式化时间,所以在浏览器中你查询的出来的结果会和你传递的过去的时间不一样
solr中可以如下配置了 <field name="create_time" type="date" indexed="false" stored="true" required="true"/>
使用tdate的数据, solrj会自己转换他是把时间转换成标准时区的时间格式 如下代码
org.apache.solr.client.solrj.util.ClientUtils 中的方法writeXML中的107行
v = DateUtil.getThreadLocalDateFormat().format( (Date)v ); 调用他用org.apache.solr.common.util.DateUtil 格式化
org.apache.solr.common.util.DateUtil 初始化的SimpleDateFormat 使用的TimeZone 是utc 如下
public static TimeZone UTC = TimeZone.getTimeZone("UTC");
private static ThreadLocalDateFormat fmtThreadLocal = new ThreadLocalDateFormat();
private static class ThreadLocalDateFormat extends ThreadLocal<DateFormat> {
DateFormat proto;
public ThreadLocalDateFormat() {
super();
//2007-04-26T08:05:04Z
SimpleDateFormat tmp = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
tmp.setTimeZone(UTC);
proto = tmp;
}
@Override
protected DateFormat initialValue() {
return (DateFormat) proto.clone();
}
}
在查询的时候 q中如果有时间 也要以上的时间这样格式化代码,因为发过的url 中的q中的 时间类型要转化成xml date的格式
DateUtil.getThreadLocalDateFormat().format(date).replace(":", "\\:");
solr 中
DateField 转化代码如下
public Date parseMath(Date now, String val) {
String math = null;
final DateMathParser p = new DateMathParser(MATH_TZ, MATH_LOCALE);
if (null != now) p.setNow(now);
if (val.startsWith(NOW)) {
math = val.substring(NOW.length());
} else {
final int zz = val.indexOf(Z);
if (0 < zz) {
math = val.substring(zz+1);
try {
// p.setNow(toObject(val.substring(0,zz)));
p.setNow(parseDate(val.substring(0,zz+1)));
} catch (ParseException e) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
"Invalid Date in Date Math String:'"
+val+'\'',e);
}
} else {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
"Invalid Date String:'" +val+'\'');
}
}
if (null == math || math.equals("")) {
return p.getNow();
}
try {
return p.parseMath(math);
} catch (ParseException e) {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
"Invalid Date Math String:'" +val+'\'',e);
}
}
分享到:
相关推荐
solr-solrj-4.9.0.jar
solr-solrj-4.4.0.jar
solr-solrj-6.6.0.jar
压缩文件里面有solr-solrj-4.10.3.jar和solr-solrj-5.0.0.jar两个jar
apache-solr-solrj-3.5.0.jar
solrJ是Java连接solr进行查询检索和索引更新维护的jar包。
solr-solrj 5.0.0 和自己搭建的solr服务交互
solr-solrj-4.10.3.jar。
solr的核心jar,大家可以一起好好学习一下,还是很优秀的
jar包,亲测可用
jar包,亲测可用
下载后会获得名为:solr_core.4.6.0 的zip包,解压后会获得solr-core-4.6.0.jar和 solr-solrj-4.6.0.jar两个文件,搭建solr全文检索环境必须要添加的包
Solr是一个独立的企业级搜索应用服务器,它对外提供类似于Web-service的API接口。用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文
放了SolrJ6.3.0所有web工程下的Jar包。solr-solrj6.3.0.jar等。放了SolrJ6.3.0所有web工程下的Jar包。放了SolrJ6.3.0所有web工程下的Jar包。
solr详细配置教程与solrj的使用
solr5.5的jar包,solr4、solr5、solr6由于solr-core-x.jar的源码的调整,不能使用同一个jar包。solr4由于版本过老就暂时不做介绍,solr5所需jar包下载
jar包,亲测可用
jar包,亲测可用
jar包,亲测可用
jar包,亲测可用