Commit b0744e26 authored by Quxl's avatar Quxl

搜索引擎接口

parent 1e29492f
......@@ -73,6 +73,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>6.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
......
package com.egolm.shop.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.Page;
import com.egolm.shop.service.SolrGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api
@Controller
@RequestMapping("solr/goods")
public class SolrGoodsController {
@Autowired
private SolrGoodsService service;
@ResponseBody
@RequestMapping("query")
@ApiOperation("搜索引擎商品搜索")
public Object query(Page page, String queryKey, String[] keywords, String[] orders, String[] facetFields, String[] facetPivotFields) {
return service.query(page, queryKey, keywords, orders, facetFields, facetPivotFields);
}
@ResponseBody
@RequestMapping("update")
@ApiOperation("搜索引擎更新全部商品索引")
public Object update() {
service.update();
return Rjx.jsonOk();
}
@ResponseBody
@RequestMapping("updateByDistrictID")
@ApiOperation("搜索引擎按区域编号更新商品索引")
public Object updateByDistrictID(String sDistrictID) {
service.update(sDistrictID);
return Rjx.jsonOk();
}
}
package com.egolm.shop.service;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.Page;
public interface SolrGoodsService {
public Rjx query(Page page, String queryKey, String[] keywords, String[] orders, String[] facetFields, String[] facetPivotFields);
public void update();
public void update(String sDistrictID);
public void deleteByQuery(String queryKey);
public void deleteById(String[] documentIds);
}
package com.egolm.shop.service.impl;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.log4j.Logger;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrQuery.ORDER;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.FacetField;
import org.apache.solr.client.solrj.response.FacetField.Count;
import org.apache.solr.client.solrj.response.PivotField;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList;
import org.springframework.scheduling.annotation.Async;
import com.egolm.common.DateUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.Util;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.Page;
import com.egolm.shop.config.XException;
import com.egolm.shop.service.SolrGoodsService;
public class SolrGoodsServiceImpl implements SolrGoodsService {
private static final Logger logger = Logger.getLogger(SolrGoodsService.class);
private JdbcTemplate jdbcTemplate;
private HttpSolrClient solrClient;
@Override
public Rjx query(Page page, String queryKey, String[] keywords, String[] orders, String[] facetFields, String[] facetPivotFields) {
logger.info("收到商品检索请求:" + Rjx.json().set("page", page).set("queryKey", queryKey).set("keywords", keywords).set("orders", orders).set("facetFields", facetFields).set("facetPivotFields", facetPivotFields));
if(page == null) {
page = new Page(1L, 20L);
}
queryKey = queryKey.toUpperCase();
String query = queryKey;
query = query.replaceAll("[-~!@#\\$%\\^&\\(\\)=_\\+\\[\\]\\{\\}|\\\\;':\",\\./<>\\?]", " ").replaceAll("[\\*]+", "*").replaceAll("\\s+", " ").trim();
logger.info("处理后搜索关键字:" + query);
SolrQuery solrQuery = new SolrQuery(query);
if(keywords != null) {
for(String keyword : keywords) {
solrQuery.addFilterQuery(keyword);
}
}
if(orders != null) {
for(String order : orders) {
String[] kv = order.split(":", 2);
ORDER sc = kv[1] == null || kv[1].trim().length() == 0 || kv[1].equalsIgnoreCase("asc") ? ORDER.asc : ORDER.desc;
solrQuery.addSort(kv[0], sc);
}
}
solrQuery.setFacet(true);
solrQuery.addFacetField(facetFields);
solrQuery.addFacetPivotField(facetPivotFields);
solrQuery.setRows((int)(long)page.getLimit());
solrQuery.setStart(Util.objTo(page.getFirstRowNumber(), Integer.class) - 1);
try {
QueryResponse response = solrClient.query(solrQuery);
Map<String, List<String>> groups = new HashMap<String, List<String>>();
List<FacetField> facetFieldList = response.getFacetFields();
for (FacetField facet : facetFieldList) {
String fieldName = facet.getName();
if(StringUtil.isNotBlank(fieldName)) {
List<Count> values = facet.getValues();
for(int i = 0; i < values.size(); i++) {
Count count = values.get(i);
List<String> list = groups.get(fieldName);
if(list == null) {
list = new ArrayList<String>();
}
if(count.getCount() > 0) {
list.add(count.getName());
} else {
break;
}
groups.put(fieldName, list);
}
}
}
NamedList<List<PivotField>> namedList = response.getFacetPivot();
Map<String, List<Map<String, Object>>> pivots = new HashMap<String, List<Map<String, Object>>>();
if(namedList != null) {
for(int i = 0; i < namedList.size(); i++) {
List<Map<String, Object>> _l = new ArrayList<Map<String, Object>>();
String name = namedList.getName(i);
List<PivotField> list1 = namedList.getVal(i);
for(PivotField pivotField1 : list1) {
Map<String, Object> _m = new HashMap<String, Object>();
Object _v1 = pivotField1.getValue();
String _f1 = pivotField1.getField();
_m.put(_f1, _v1);
List<PivotField> list2 = pivotField1.getPivot();
for(PivotField pivotField2 : list2) {
Object _v2 = pivotField2.getValue();
String _f2 = pivotField2.getField();
_m.put(_f2, _v2);
}
_l.add(_m);
}
pivots.put(name, _l);
}
}
Rjx result = Rjx.jsonOk();
SolrDocumentList docList = response.getResults();
if(docList != null) {
page.setTotal(docList.getNumFound());
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
for(SolrDocument doc : docList) {
Map<String, Object> map = new HashMap<String, Object>();
for(String key : doc.keySet()) {
Object objValue = doc.get(key);
map.put(key, objValue);
}
list.add(map);
}
result = Rjx.jsonOk().set("datas", list).set("page", page).set("groups", groups).set("pivots", pivots);
}
return result;
} catch (Exception e) {
throw new XException("SolrQuery:" + queryKey + "," + StringUtil.toJson(keywords), e);
}
}
@Override
public void deleteByQuery(String queryKey) {
try {
solrClient.deleteByQuery(queryKey);
solrClient.commit();
} catch (SolrServerException | IOException e) {
throw new XException("SolrDelete:" + queryKey, e);
}
}
@Override
public void deleteById(String... documentIds) {
try {
solrClient.deleteById(Arrays.asList(documentIds));
solrClient.commit();
} catch (SolrServerException | IOException e) {
throw new XException("SolrDelete:" + StringUtil.toJson(documentIds), e);
}
}
@Async
public void update() {
this.update(null);
}
@Async
public void update(String sDistrictID) {
List<String> strs = new ArrayList<String>();
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
if(StringUtil.isBlank(sDistrictID)) {
String sql = "SELECT DISTINCT sDistrictID FROM tShop WHERE sDistrictID IS NOT NULL AND sDistrictID != ''";
Page pageShop = new Page(1L, 5000L, "sDistrictID");
list = jdbcTemplate.limitAll(sql, pageShop);
} else {
list.add(Rjx.json().set("sDistrictID", sDistrictID).toMap());
}
String sIndexID = null;
for(Map<String, Object> map : list) {
try {
sIndexID = (String)map.get("sDistrictID");
if(StringUtil.isBlank(sIndexID)) {
continue;
}
logger.info(DateUtil.format(new Date()) + "-重建区域[" + sIndexID + "]索引... " + SolrGoodsServiceImpl.class.getResource("/").getPath());
String queryKey = "sDistrictID:" + sIndexID;
solrClient.deleteByQuery(queryKey);
String sqlGoods = "SELECT ttt.*, ssoc.sCategoryDesc sTopOrgCategoryDesc, ssocc.sScopeTypeID sDefScopeTypeID, ssocc.sScopeType sDefScopeType FROM ( SELECT tt.*, ss.sCategoryDesc sTopCategoryDesc, soc.sUpCategoryNO sTopOrgCategoryNO, soc.sScopeTypeID sTopOrgScopeTypeID FROM ( SELECT t.nTag, t.nCaseUnits, t.sDistrictID, t.sWarehouseNO, t.sAgentContractNO, t.nGoodsID, t.sOrgNO, t.sGoodsDesc, t.sBrand, t.sBrandID, t.nAgentID, t.sMainBarcode, t.sSpec, t.sUnit, t.nMinSaleQty, t.nRealSalePrice, t.nSaleUnits, t.sOrgCategoryNO, t.sCategoryNO, t.sCategoryDesc, t.sUpCategoryNO, cc.sCategoryDesc sUpCategoryDesc, t.sOrgScopeType, t.sOrgScopeTypeID, t.sGoodsName, t.sAgentName, t.sURL, t.sWarehouseName, t.nRetailPrice, t.sRetailPriceUnit, t.sOrgCategoryDesc, t.sUpOrgCaregoryNO, t.nTotalSaleQty, cccc.sCategoryDesc sUpOrgCategoryDesc, cc.sUpCategoryNO sTopCategoryNO, oc.sScopeTypeID, oc.sScopeType, aso.nStockQty - aso.nLockedQty nStockQty, t.dCreateDate FROM ( SELECT awda.*, ogc.sCategoryNO sOrgCategoryNO, ogc.sCategoryDesc sOrgCategoryDesc, ogc.sUpCategoryNO sUpOrgCaregoryNO, ogc.sScopeType sOrgScopeType, ogc.sScopeTypeID sOrgScopeTypeID, g.sGoodsName, a.sAgentName, ( CASE WHEN agp.sURL IS NULL THEN p.sURL ELSE agp.sURL END ) sURL, w.sWarehouseName, gmp.nPrice nRetailPrice, gmp.sUnit sRetailPriceUnit, ccc.sCategoryDesc, ccc.sUpCategoryNO FROM ( SELECT GG.*, acg.nTag, acg.sOrgNO, acg.sGoodsDesc, acg.sBrand, acg.sBrandID, acg.nAgentID, acg.sMainBarcode, acg.sSpec, acg.sUnit, acg.nMinSaleQty, acg.nRealSalePrice, acg.nSaleUnits, acg.sCategoryNO, acg.nTotalSaleQty, acg.dCreateDate, acg.nCaseUnits FROM ( SELECT f1.sDistrictID, f1.sWarehouseNO, f1.sAgentContractNO, f1.nGoodsID, f2.nMaxDCPriority FROM ( SELECT wd.sDistrictID, wd.sWarehouseNO, acw.sAgentContractNO, acg.nGoodsID, wd.nDCPriority FROM tWarehouseDistrict wd LEFT JOIN tAgentContractWarehouse acw ON acw.sWarehouseNO = wd.sWarehouseNO AND acw.nTag & 1 = 0 LEFT JOIN tAgentContractGoods acg ON acg.sAgentContractNO = acw.sAgentContractNO AND acg.nTag & 1 = 0 WHERE wd.sDistrictID = '" + sIndexID + "' AND wd.nTag & 1 = 0 GROUP BY wd.sDistrictID, wd.sWarehouseNO, acw.sAgentContractNO, acg.nGoodsID, wd.nDCPriority ) f1, ( SELECT wd.sDistrictID, acw.sAgentContractNO, acg.nGoodsID, MIN (wd.nDCPriority) nMaxDCPriority FROM tWarehouseDistrict wd LEFT JOIN tAgentContractWarehouse acw ON acw.sWarehouseNO = wd.sWarehouseNO AND acw.nTag & 1 = 0 LEFT JOIN tAgentContractGoods acg ON acg.sAgentContractNO = acw.sAgentContractNO AND acg.nTag & 1 = 0 WHERE wd.sDistrictID = '" + sIndexID + "' AND wd.nTag & 1 = 0 GROUP BY wd.sDistrictID, acw.sAgentContractNO, acg.nGoodsID ) f2 WHERE f1.sDistrictID = f2.sDistrictID AND f1.sAgentContractNO = f2.sAgentContractNO AND f1.nGoodsID = f2.nGoodsID AND f1.nDCPriority = f2.nMaxDCPriority ) GG LEFT JOIN tAgentContractGoods acg ON acg.sAgentContractNO = GG.sAgentContractNO AND acg.nTag & 1 = 0 AND GG.nGoodsID = acg.nGoodsID ) awda LEFT JOIN ( SELECT ogcc.*, c.sCategoryDesc, c.sUpCategoryNO FROM tOrgGoodsCategory ogcc LEFT JOIN tCategory c ON c.sCategoryNO = ogcc.sCategoryNO AND c.nTag & 1 = 0 ) ogc ON ogc.sOrgNO = awda.sOrgNO AND ogc.nGoodsID = awda.nGoodsID LEFT JOIN tCategory ccc ON ccc.sCategoryNO = awda.sCategoryNO AND ccc.nTag & 1 = 0 LEFT JOIN tGoods g ON g.nGoodsID = awda.nGoodsID AND g.nTag & 1 = 0 LEFT JOIN tAgent a ON a.nAgentID = awda.nAgentID AND a.nTag & 1 = 0 LEFT JOIN tGoodsPic p ON p.nGoodsID = awda.nGoodsID AND p.nTag & 1 = 0 AND p.sPicTypeID = '1' AND p.nIdx = 1 LEFT JOIN tAgentGoodsPic agp ON agp.nAgentID = awda.nAgentID AND agp.nGoodsID = awda.nGoodsID AND agp.nTag & 1 = 0 AND agp.sPicTypeID = '1' AND agp.nIdx = 1 LEFT JOIN tWarehouse w ON w.sWarehouseNO = awda.sWarehouseNO AND w.nTag & 1 = 0 LEFT JOIN tGoodsMarketPrice gmp ON gmp.nGoodsID = awda.nGoodsID AND gmp.nTag & 1 = 0 AND gmp.sOrgNO = awda.sOrgNO WHERE awda.sAgentContractNO IS NOT NULL AND awda.nGoodsID IS NOT NULL AND awda.nTag & 1 = 0 AND awda.nTag & 256 = 0 ) t LEFT JOIN tCategory cc ON cc.sCategoryNO = t.sUpCategoryNO AND cc.nTag & 1 = 0 LEFT JOIN tCategory cccc ON cccc.sCategoryNO = t.sUpOrgCaregoryNO AND cccc.nTag & 1 = 0 LEFT JOIN tOrgCategory oc ON oc.sCategoryNO = t.sOrgCategoryNO AND oc.nTag & 1 = 0 AND oc.sOrgNO = t.sOrgNO LEFT JOIN tAgentStockOnline aso ON aso.nGoodsID = t.nGoodsID AND aso.sAgentContractNO = t.sAgentContractNO AND aso.sWarehouseNO = t.sWarehouseNO ) tt LEFT JOIN tCategory ss ON ss.sCategoryNO = tt.sTopCategoryNO AND ss.nTag & 1 = 0 LEFT JOIN tOrgCategory soc ON soc.sCategoryNO = tt.sUpOrgCaregoryNO AND soc.nTag & 1 = 0 AND soc.sScopeTypeID = tt.sOrgScopeTypeID AND soc.sOrgNO = tt.sOrgNO ) ttt LEFT JOIN tOrgCategory ssoc ON ssoc.sCategoryNO = ttt.sTopOrgCategoryNO AND ssoc.nTag & 1 = 0 AND ssoc.sScopeTypeID = ttt.sTopOrgScopeTypeID AND ssoc.sOrgNO = ttt.sOrgNO LEFT JOIN tOrgCategory ssocc ON ssocc.sCategoryNO = ttt.sCategoryNO AND ssocc.nTag & 1 = 0 AND ssocc.sOrgNO = ttt.sOrgNO WHERE ttt.sWarehouseName IS NOT NULL AND ttt.sWarehouseNO IS NOT NULL " + StringUtil.join(" AND ", " AND ", strs);
Long goodsPageIndex = 1L;
Page pageGoods = new Page(goodsPageIndex, 5000L, "sDistrictID", "sScopeTypeID", "sAgentContractNO", "nGoodsID");
List<Map<String, Object>> goodsList = null;
do {
pageGoods.setIndex(goodsPageIndex++);
goodsList = jdbcTemplate.limit(sqlGoods, pageGoods);
List<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
for(Map<String, Object> goods : goodsList) {
SolrInputDocument solrInputDocument = new SolrInputDocument();
String sDistrictID_DOC = Util.objTo(goods.get("sDistrictID"), String.class, "");
String sAgentContractNO_DOC = Util.objTo(goods.get("sAgentContractNO"), String.class, "");
String nGoodsID_DOC = Util.objTo(goods.get("nGoodsID"), String.class, "");
String sGoodsDesc = Util.objTo(goods.get("sGoodsDesc"), String.class, "");
String sGoodsName = Util.objTo(goods.get("sGoodsName"), String.class, "");
String sURL = Util.objTo(goods.get("sURL"), String.class, "");
String sBrand = Util.objTo(goods.get("sBrand"), String.class, "");
String sBrandID = Util.objTo(goods.get("sBrandID"), String.class, "");
String sCategoryNO = Util.objTo(goods.get("sCategoryNO"), String.class, "");
String sCategoryDesc = Util.objTo(goods.get("sCategoryDesc"), String.class, "");
String sUpCategoryNO = Util.objTo(goods.get("sUpCategoryNO"), String.class, "");
String sUpCategoryDesc = Util.objTo(goods.get("sUpCategoryDesc"), String.class, "");
String sTopCategoryNO = Util.objTo(goods.get("sTopCategoryNO"), String.class, "");
String sTopCategoryDesc = Util.objTo(goods.get("sTopCategoryDesc"), String.class, "");
String sOrgCategoryNO = Util.objTo(goods.get("sOrgCategoryNO"), String.class, "");
String sOrgCategoryDesc = Util.objTo(goods.get("sOrgCategoryDesc"), String.class, "");
String sUpOrgCategoryNO = Util.objTo(goods.get("sUpOrgCategoryNO"), String.class, "");
String sUpOrgCategoryDesc = Util.objTo(goods.get("sUpOrgCategoryDesc"), String.class, "");
String sTopOrgCategoryNO = Util.objTo(goods.get("sTopOrgCategoryNO"), String.class, "");
String sTopOrgCategoryDesc = Util.objTo(goods.get("sTopOrgCategoryDesc"), String.class, "");
sCategoryNO = StringUtil.isBlank(sOrgCategoryNO) ? sCategoryNO : sOrgCategoryNO;
sCategoryDesc = StringUtil.isBlank(sOrgCategoryDesc) ? sCategoryDesc : sOrgCategoryDesc;
sUpCategoryNO = StringUtil.isBlank(sUpOrgCategoryNO) ? sUpCategoryNO : sUpOrgCategoryNO;
sUpCategoryDesc = StringUtil.isBlank(sUpOrgCategoryDesc) ? sUpCategoryDesc : sUpOrgCategoryDesc;
sTopCategoryNO = StringUtil.isBlank(sTopOrgCategoryNO) ? sTopCategoryNO : sTopOrgCategoryNO;
sTopCategoryDesc = StringUtil.isBlank(sTopOrgCategoryDesc) ? sTopCategoryDesc : sTopOrgCategoryDesc;
String sScopeTypeID_DOC = Util.objTo(goods.get("sScopeTypeID"), String.class, "");
String sScopeType = Util.objTo(goods.get("sScopeType"), String.class, "");
String sDefScopeTypeID = Util.objTo(goods.get("sDefScopeTypeID"), String.class, "");
String sDefScopeType = Util.objTo(goods.get("sDefScopeType"), String.class, "");
sScopeTypeID_DOC = StringUtil.isBlank(sScopeTypeID_DOC) ? sDefScopeTypeID : sScopeTypeID_DOC;
sScopeType = StringUtil.isBlank(sScopeType) ? sDefScopeType : sScopeType;
String nAgentID = Util.objTo(goods.get("nAgentID"), String.class, "");
String sAgentName = Util.objTo(goods.get("sAgentName"), String.class, "");
String sMainBarcode = Util.objTo(goods.get("sMainBarcode"), String.class, "");
String sSpec = Util.objTo(goods.get("sSpec"), String.class, "");
String sUnit = Util.objTo(goods.get("sUnit"), String.class, "");
String nMinSaleQty = Util.objTo(goods.get("nMinSaleQty"), String.class, "");
String nRealSalePrice = Util.objTo(goods.get("nRealSalePrice"), String.class, "");
String nSaleUnits = Util.objTo(goods.get("nSaleUnits"), String.class, "");
String nRetailPrice = Util.objTo(goods.get("nRetailPrice"), String.class, "");
String sRetailPriceUnit = Util.objTo(goods.get("sRetailPriceUnit"), String.class, "");
String sWarehouseNO = Util.objTo(goods.get("sWarehouseNO"), String.class, "");
String sWarehouseName = Util.objTo(goods.get("sWarehouseName"), String.class, "");
String sOrgNO = Util.objTo(goods.get("sOrgNO"), String.class, "");
Date dCreateDate = Util.objTo(goods.get("dCreateDate"), Date.class, null);
Integer nStockQty = Util.objTo(goods.get("nStockQty"), Integer.class, 0);
Integer nTotalSaleQty = Util.objTo(goods.get("nTotalSaleQty"), Integer.class, 0);
Integer nTag = Util.objTo(goods.get("nTag"), Integer.class, null);
Integer nCaseUnits = Util.objTo(goods.get("nCaseUnits"), Integer.class, 0);
solrInputDocument.addField("id", StringUtil.join("$", Arrays.asList(sDistrictID_DOC, sScopeTypeID_DOC, sAgentContractNO_DOC, nGoodsID_DOC)));
solrInputDocument.addField("sDistrictID", sDistrictID_DOC);
solrInputDocument.addField("sAgentContractNO", sAgentContractNO_DOC);
solrInputDocument.addField("nGoodsID", nGoodsID_DOC);
solrInputDocument.addField("sGoodsDesc", sGoodsDesc);
solrInputDocument.addField("sGoodsName", sGoodsName);
solrInputDocument.addField("sURL", sURL);
solrInputDocument.addField("sBrand", sBrand);
solrInputDocument.addField("sBrandID", sBrandID);
solrInputDocument.addField("sCategoryNO", sCategoryNO);
solrInputDocument.addField("sCategoryDesc", sCategoryDesc);
solrInputDocument.addField("sUpCategoryNO", sUpCategoryNO);
solrInputDocument.addField("sUpCategoryDesc", sUpCategoryDesc);
solrInputDocument.addField("sTopCategoryNO", sTopCategoryNO);
solrInputDocument.addField("sTopCategoryDesc", sTopCategoryDesc);
solrInputDocument.addField("nAgentID", nAgentID);
solrInputDocument.addField("sAgentName", sAgentName);
solrInputDocument.addField("sMainBarcode", sMainBarcode);
solrInputDocument.addField("sSpec", sSpec);
solrInputDocument.addField("sUnit", sUnit);
solrInputDocument.addField("nMinSaleQty", nMinSaleQty);
solrInputDocument.addField("nRealSalePrice", nRealSalePrice);
solrInputDocument.addField("nSaleUnits", nSaleUnits);
solrInputDocument.addField("nRetailPrice", nRetailPrice);
solrInputDocument.addField("sRetailPriceUnit", sRetailPriceUnit);
solrInputDocument.addField("sWarehouseNO", sWarehouseNO);
solrInputDocument.addField("sWarehouseName", sWarehouseName);
solrInputDocument.addField("sScopeTypeID", sScopeTypeID_DOC);
solrInputDocument.addField("sScopeType", sScopeType);
solrInputDocument.addField("sOrgNO", sOrgNO);
solrInputDocument.addField("dCreateDate", dCreateDate == null ? 0 : dCreateDate.getTime());
solrInputDocument.addField("nStockQty", nStockQty == 0 ? 0 : 1);
solrInputDocument.addField("nTotalSaleQty", nTotalSaleQty == null ? 0 : nTotalSaleQty);
solrInputDocument.addField("nOnShelves", (((nTag.intValue()&16) == 16) ? "1" : "0"));
solrInputDocument.addField("nGoodsTypeID", (((nTag.intValue()&512) == 512) ? 1 : 0));
solrInputDocument.addField("nChoiceness", (((nTag.intValue()&64) == 64) ? 1 : 0));
solrInputDocument.addField("nTag", nTag);
solrInputDocument.addField("nCaseUnits", nCaseUnits);
Set<String> set = new HashSet<String>();
String sSimplePinyin = StringUtil.SimplePinyin(sGoodsDesc);
set.addAll(Arrays.asList(StringUtil.PinyinKAnalyzer(sSimplePinyin, 2, 4)));
String sPinyin = StringUtil.join(" ", set);
String code4 = sMainBarcode.length() >= 4 ? sMainBarcode.substring(sMainBarcode.length() - 4, sMainBarcode.length()) : "";
String code5 = sMainBarcode.length() >= 5 ? sMainBarcode.substring(sMainBarcode.length() - 5, sMainBarcode.length()) : "";
String code6 = sMainBarcode.length() >= 6 ? sMainBarcode.substring(sMainBarcode.length() - 6, sMainBarcode.length()) : "";
String manu = StringUtil.join(" ", Arrays.asList(code4, sGoodsDesc, code6, sBrand, sCategoryDesc, sUpCategoryDesc, code5, sAgentName, sMainBarcode, sScopeType, sPinyin));
manu = manu.replaceAll("[-~!@#\\$%\\^&\\*\\(\\)=_+\\[\\]\\{\\}|\\\\;':\",\\./<>\\?]", " ").replaceAll("\\s+", " ").trim();
docs.add(solrInputDocument);
}
List<List<SolrInputDocument>> cdocs = Util.split(docs, 500);
for(List<SolrInputDocument> cdoc : cdocs) {
solrClient.add(cdoc);
}
} while(goodsList.size() > 0);
solrClient.commit();
} catch (IOException | SolrServerException e) {
logger.error("重建区域[" + sIndexID + "]索引失败", e);
try {
solrClient.rollback();
} catch (IOException | SolrServerException ex) {
logger.error("重建区域[" + sIndexID + "]索引异常回滚失败", ex);
}
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment