當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。