当前位置: 首页>>代码示例>>Java>>正文


Java QueryResponse.getHighlighting方法代码示例

本文整理汇总了Java中org.apache.solr.client.solrj.response.QueryResponse.getHighlighting方法的典型用法代码示例。如果您正苦于以下问题:Java QueryResponse.getHighlighting方法的具体用法?Java QueryResponse.getHighlighting怎么用?Java QueryResponse.getHighlighting使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.solr.client.solrj.response.QueryResponse的用法示例。


在下文中一共展示了QueryResponse.getHighlighting方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fromQueryResponse

import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的package包/类
private static <T> SearchResult<T> fromQueryResponse(QueryResponse solrQueryResponse, Function<Group, T> resultMapper) {
    final List<Group> results = solrQueryResponse.getGroupResponse().getValues().get(0).getValues();

    int numFound = solrQueryResponse.getGroupResponse().getValues().get(0).getNGroups();
    //TODO paging
    int start = 0;

    final SearchResult<T> searchResult = new SearchResult<>(numFound, start,
            results.stream().map(resultMapper).collect(Collectors.toList()));

    //TODO
    // if (results.getMaxScore() != null) {
    //    searchResult.setMaxScore(results.getMaxScore());
    //}
    if(solrQueryResponse.getHighlighting() != null){
        searchResult.getParams().put("highlighting", solrQueryResponse.getHighlighting());
    }
    if(solrQueryResponse.getHeader() != null){
        searchResult.getParams().put("header", solrQueryResponse.getHeader().asMap(Integer.MAX_VALUE));
    }
    //TODO: maybe we want fact data
    
    return searchResult;
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:25,代码来源:ConversationSearchService.java

示例2: buildJsonResponse

import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public MainSearchBuilder buildJsonResponse(QueryResponse queryResponse) {
	jsonBuilder.totalResults((int)queryResponse.getResults().getNumFound());
	highlights = queryResponse.getHighlighting();
	if(queryResponse.getResults() != null && !queryResponse.getResults().isEmpty()) {
		for(SolrDocument document : queryResponse.getResults()) {
			addResult(document);
		}
	}
	SimpleOrderedMap<String> params = (SimpleOrderedMap<String>) queryResponse.getResponseHeader().get("params");
	setParams(params);
	return jsonBuilder;
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:14,代码来源:ResponseBuilder.java

示例3: setSummaryItemHighlight

import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的package包/类
public void setSummaryItemHighlight(SummaryItem summaryItem, QueryResponse response) {
    if (response.getHighlighting() != null && response.getHighlighting().get(summaryItem.uid) != null) {
        List<String> highlightSnippets = new ArrayList<String>();
        for (Entry<String, List<String>> entry : response.getHighlighting().get(summaryItem.uid).entrySet()) {
            highlightSnippets.addAll(entry.getValue());
        }
        
        summaryItem.highlights = highlightSnippets;
    }
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:11,代码来源:SolrSearchAction.java

示例4: getPageModel

import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的package包/类
/**
     * 根据SolrServer与SolrQuery查询并获取FileModel
     *
     * @param solrServer, query。
     * @return List<FileModel>
     */
    public PageModel getPageModel(SolrServer solrServer, PageModel pageModel, SolrQuery query) {
        List<FileModel> fileModels = new ArrayList<FileModel>();
        try {
            QueryResponse rsp = solrServer.query(query);
            SolrDocumentList docs = rsp.getResults();

            System.out.println("docs num:" + docs.getNumFound());


            Map<String,Map<String,List<String>>> highlightMap=rsp.getHighlighting(); //获取所有高亮的字段

            Iterator<SolrDocument> iter = docs.iterator();
            while (iter.hasNext()) {
                SolrDocument doc = iter.next();

//                System.out.println("resource_name: " + doc.getFieldValue("resource_name").toString());

                String type = getFileTypeName(doc.getFieldValue("content_type").toString());
                String id = doc.getFieldValue("id").toString();
                String name = doc.getFieldValue("file_name").toString();
                String modifyTime  = doc.getFieldValue("file_last_modified").toString();

//                Date date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US).parse(modifyTime);
//                modifyTime = date.toLocaleString();//日期转换成如:2015-9-10 13:06:33
//                System.out.println(doc.getFieldValue("last_modified"));
                String author = null;
                if(doc.getFieldValue("author") == null) {
                    author = "微软用户";
                } else {
                    author = doc.getFieldValue("author").toString();
                }

                String indexTime = doc.getFieldValue("upload_time").toString();
                String hdfsPath = doc.getFieldValue("file_path").toString();
                String fileSize = doc.getFieldValue("file_length").toString();

                FileModel fileModel = new FileModel();
                fileModel.setId(id);
                fileModel.setName(name);
                fileModel.setType(type);
                fileModel.setAuthor(author);
                fileModel.setSize(fileSize);
                fileModel.setModifyTime(modifyTime);
                fileModel.setIndexTime(indexTime);
                fileModel.setHdfsPath(hdfsPath);

                List<String> titleList = highlightMap.get(id).get("file_name");
                List<String> contentList = highlightMap.get(id).get("content_text");
                //获取并设置高亮的字段title
                if (titleList != null && titleList.size() > 0) {
                    fileModel.setHighlightName(titleList.get(0));
                }
                //获取并设置高亮的字段content
                if (contentList != null && contentList.size() > 0) {
                    fileModel.setHighlightContent(contentList.get(0));
                }
                fileModels.add(fileModel);
            }
            pageModel.setDatas(fileModels);
            pageModel.setCount(docs.getNumFound());

        } catch (Exception e) {
            log.error("从solr根据Page查询分页文档时遇到错误", e);
        }
        return pageModel;
    }
 
开发者ID:hackty,项目名称:hadooptools,代码行数:73,代码来源:QueryFileServiceSolrMRImpl.java

示例5: search

import org.apache.solr.client.solrj.response.QueryResponse; //导入方法依赖的package包/类
@Override
public SearchResult search(String queryString, Integer page, Integer rows) throws Exception {

    SearchResult searchResult = new SearchResult();

    SolrQuery query = new SolrQuery();

    //设置查询条件
    query.setQuery(queryString);

    //设置分页
    query.setStart((page - 1) * rows);

    query.setRows(rows);

    //设置默认搜素域
    query.set("df", "item_keywords");

    query.setHighlight(true);

    query.addHighlightField("item_title");

    query.setHighlightSimplePre("<em style=\"color:red\">");

    query.setHighlightSimplePost("</em>");

    QueryResponse response = solrClient.query(query);

    SolrDocumentList results = response.getResults();

    searchResult.setRecordCount(results.getNumFound());

    List<SolrItem> solrItems = new ArrayList<SolrItem>();

    Map<String, Map<String, List<String>>> highlighting = response.getHighlighting();

    for (SolrDocument result : results) {

        SolrItem solrItem = new SolrItem();

        solrItem.setId((String) result.get("id"));

        List<String> strings = highlighting.get(result.get("id")).get("item_title");
        if (strings != null && strings.size() > 0) {
            solrItem.setTitle(strings.get(0));
        } else {
            solrItem.setTitle((String) result.get("item_title"));
        }
        solrItem.setCategory_name((String) result.get("item_category_name"));
        solrItem.setImage((String) result.get("item_image"));
        solrItem.setSell_point((String) result.get("item_sell_point"));
        solrItem.setItem_desc((String) result.get("item_desc"));
        solrItem.setPrice((Long) result.get("item_price"));

        solrItems.add(solrItem);

    }

    searchResult.setItemList(solrItems);
    searchResult.setCurPage(page);

    long recordCount = searchResult.getRecordCount();
    long pageCount = recordCount / rows;

    if (recordCount % rows > 0) {
        pageCount++;
    }

    searchResult.setPageCount(pageCount);

    return searchResult;

}
 
开发者ID:xubinux,项目名称:xbin-store,代码行数:74,代码来源:SearchServiceImpl.java


注:本文中的org.apache.solr.client.solrj.response.QueryResponse.getHighlighting方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。