1、1. 设置pom.xml
· 找到工程的pom.xml文件,增加依赖
2、 其需要依赖的JAR包包含 因一般工程里都会引用这些依赖jar包,在这里就不做pom.xml里的配置了,大家参照上面的图增加依赖和替换版本即可。 2. 设置solrcloud.properties · 在工程中新增properties配置,内容为 solr.solrcloudServer=192.168.169.129:2181,192.168.169.12:2181,192.168.169.15:2181/bjk solr.zkClientTimeout=2000 solr.zkConnectTimeout=2000 solr.solrcloudServer:
3、是solrcloud的zookeeper配置信息
solr.zkClientTimeout:当前应用与zookeeper连接超时时间
solr.zkConnectTimeout:当前应用与zookeeper连接超时时间
3. 增加java文件
· 在工程中util目录下增加
4. 修改applicationContext.xml文件
· 找到spring主配置文件applicationContext.xml,增加如下配置
4、ignore-resource-not-found="true"
location="classpath*:/environments/development/solrcloud.properties" />
6、询索引
/**
* 从solr查询每日入库
* @param query
* @param page
* @return
*/
public Page 7、ringBuffer("io:1 AND status:4 AND upDownTime:[2014-10-01T00:00:00Z TO 2015-10-01T00:00:00Z]");
if(query.getOrgId()!=null && query.getOrgId()>0){
queryStr.append(" AND newIdCompany:"+query.getOrgId());
}
if(query.getStoreId()!=null && query.getStoreId()>0){ 8、
queryStr.append(" AND storeAttr:"+query.getStoreId());
}
System.out.println("查询参数 "+queryStr);
//设置查询条件
solrQuery.setQuery(queryStr.toString());
//设置查询分页条件
solrQuery.set("start",(page.getPageNo()-1)*page.getPageSize());
so 9、lrQuery.set("rows",page.getPageSize());
//设置查询排序
solrQuery.setSort("upDownTime",SolrQuery.ORDER.desc);
List 10、 solrCloudUtils.getCloundSolrServer("transferdetail");
QueryResponse res = cloudSolrServer.query(solrQuery);
SolrDocumentList docs = res.getResults();
InBoundPo inBoundPo = null;
//循环将索引文档的信息转换到实体对象中
for(SolrDocument doc:docs){
11、 inBoundPo = new InBoundPo();
inBoundPo.setInBoundCode((Integer)doc.getFieldValue("transfer_id"));
inBoundPo.setOrgId((Integer)doc.getFieldValue("NewIdCompany"));
inBoundPo.setInType((Integer)doc.getFieldValue("type"));
inBoundPo 12、setStoreName((String)doc.getFieldValue("storeName"));
inBoundPo.setIdPart((String)doc.getFieldValue("idPart"));
inBoundPo.setWareName((String)doc.getFieldValue("wareName"));
inBoundPo.setWareId((Integer)doc.getFieldValue("wareId"));
13、 inBoundPo.setCid1((Integer)doc.getFieldValue("cid1"));
inBoundPo.setCid2((Integer) doc.getFieldValue("cid2"));
inBoundPo.setCid3((Integer) doc.getFieldValue("cid3"));
inBoundPo.setSupplierID((String)doc.getFieldValue("supplierID"));
14、 if((String)doc.getFieldValue("price")!=null){
inBoundPo.setCostPrice(new BigDecimal((String)doc.getFieldValue("price")));
}
inBoundPo.setLossType((Integer) doc.getFieldValue("losstype"));
inBoundPo.setXmlAttaches((String)doc. 15、getFieldValue("xmlAttaches"));
inBoundPo.setSalesPin((String)doc.getFieldValue("salesPin"));
list.add(inBoundPo);
}
long numFound = docs.getNumFound();
page.setTotalCount(numFound);
System.out.println("查询总数量:"+nu 16、mFound);
System.out.println("查询耗费时间:"+res.getQTime());
page.setResult(list);
} catch (SolrServerException e) {
e.printStackTrace();
} finally {
//关闭solrCloud连接
cloudSolrServer.shutdown();
}
return page; 17、
}
新增索引
//创建solrserver连接
CloudSolrServer solrServer = solrCloudUtils.getCloundSolrServer("transferdetail");
//需要提交的索引集合
Collection 18、ty:list){
doc = new SolrInputDocument();
//afs_transfer
doc.addField("transfer_id", bigEntity.getTransfer_id());
doc.addField("idStoreFrom", bigEntity.getIdStoreFrom());
doc.addField("idStoreTo", bigEntity.getIdStoreTo());
doc.addField("type", bigEntity.getType( 19、));
doc.addField("io", bigEntity.getIo());
doc.addField("status", bigEntity.getStatus());
doc.addField("yn", bigEntity.getYn());
doc.addField("fromPin", bigEntity.getFromPin());
doc.addField("fromName", bigEntity.getFromName());
if(bigEntity.getFromTime()!=null){
d 20、oc.addField("fromTime", solrUtil.solrTime(bigEntity.getFromTime()));
}
doc.addField("fromNotes", bigEntity.getFromNotes());
doc.addField("toPin", bigEntity.getToPin());
doc.addField("toName", bigEntity.getToName());
if(bigEntity.getToTime()!=null){
doc.addField("toTime", 21、solrUtil.solrTime(bigEntity.getToTime()));
}
doc.addField("toNotes", bigEntity.getToNotes());
doc.addField("idCompany", bigEntity.getIdCompany());
doc.addField("kdanhao", bigEntity.getKdanhao());
doc.addField("istemp", bigEntity.getIstemp());
doc.addField("getWare", bigEn 22、tity.getGetWare());
doc.addField("newIdCompany", bigEntity.getNewIdCompany());
doc.addField("idStore", bigEntity.getIdStore());
if(bigEntity.getTimeUpdated()!=null){
doc.addField("timeUpdated", solrUtil.solrTime(bigEntity.getTimeUpdated()));
}
doc.addField("manUpdated", 23、bigEntity.getManUpdated());
doc.addField("storeFrom", bigEntity.getStoreFrom());
doc.addField("storeTo", bigEntity.getStoreTo());
doc.addField("isApproved", bigEntity.getIsApproved());
if(bigEntity.getUpDownTime()!=null){
doc.addField("upDownTime", solrUtil.solrTime(bigEntit 24、y.getUpDownTime()));
}
doc.addField("inventory_status", bigEntity.getInventory_status());
doc.addField("inventory_name", bigEntity.getInventory_name());
doc.addField("inventory_pin", bigEntity.getInventory_pin());
doc.addField("inventory_check_notes", bigEntity.getInventory_c 25、heck_notes());
if(bigEntity.getInventory_time()!=null){
doc.addField("inventory_time", solrUtil.solrTime(bigEntity.getInventory_time()));
}
doc.addField("ts", bigEntity.getTs());
doc.addField("rfidType", bigEntity.getRfidType());
docs.add(doc);
}
//提交到solrcloud
solrServer.add(docs);
solrSmit();
//关闭solrcloud连接
solrServer.shutdown();
注意:时间处理需要将时间转换为yyyy-MM-ddThh:mm:ss:Z
千万不要忘了T和Z
因为SOLR存储索引的时候,默认是以格林威治时间进行存储,当创建索引的时候,时间会减去8小时,所以为了保证时间一致性,我们在操作时间的时候,要么在创建索引时时间增加8小时,要么在查询时,时间减去8小时。






