guo173024192 2015-04-30 03:01 采纳率: 0%
浏览 1590

有知道Solr的吗,帮我看看这段代码的意思,加些注释

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;
}

}

  • 写回答

3条回答 默认 最新

  • wxshi_java 2015-04-30 07:39
    关注

    通过solr获取相应的域的索引值。

    评论

报告相同问题?

悬赏问题

  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号