本文整理汇总了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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}