package com.dragon.sephora.commerce.frontend.search;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
public class CatalogGroupSearchService {
/*
* 名称(品牌名称、分类名称)
*/
private String name = "";
/*
* 品牌英文名称
*/
private String brandNameEN = "";
/*
* 父级标识ID
*/
private String parentCatgroupId = "";
public void searchSolrResult(Integer storeId,Integer langId,String catGroupId){
try{
if(StringUtils.isNotEmpty(catGroupId)){
SolrServer solrServer = SolrServerUtil.initSolrServerInstatnce(storeId, langId, "IBM_extensionProfile_CatalogGroup");
SolrQuery query = new SolrQuery();
query.setQuery("catgroup_id:" + catGroupId);
QueryResponse rsp = solrServer.query( query );
SolrDocumentList docs = rsp.getResults();
for (SolrDocument doc : docs) {
String name = doc.getFieldValue("name") != null?(String)doc.getFieldValue("name"):"";
String brandENName = doc.getFieldValue("brandEnName") != null?(String)doc.getFieldValue("brandEnName"):"";
this.setName(name);
this.setBrandNameEN(brandENName);
List<Object> parentCatgroupIdList = (List<Object>)doc.getFieldValue("parentCatgroup_id_facet");
if(parentCatgroupIdList != null && !parentCatgroupIdList.isEmpty()){
Object oParentCatgroupId = parentCatgroupIdList.get(0);
if(oParentCatgroupId != null){
String strParentCatgroupId = (String)oParentCatgroupId;
String[] tempArray = strParentCatgroupId.split("_");
if(tempArray != null && tempArray.length == 2){
this.setParentCatgroupId(tempArray[1] == null?"":tempArray[1]);
}
}
}
break;
}
}
} catch (SolrServerException e) {
e.printStackTrace();
} catch (Exception ex){
ex.printStackTrace();
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBrandNameEN() {
return brandNameEN;
}
public void setBrandNameEN(String brandNameEN) {
this.brandNameEN = brandNameEN;
}
public String getParentCatgroupId() {
return parentCatgroupId;
}
public void setParentCatgroupId(String parentCatgroupId) {
this.parentCatgroupId = parentCatgroupId;
}
}