本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery.addHighlightField方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery.addHighlightField方法的具體用法?Java SolrQuery.addHighlightField怎麽用?Java SolrQuery.addHighlightField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.client.solrj.SolrQuery
的用法示例。
在下文中一共展示了SolrQuery.addHighlightField方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processHighlightOptions
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Append highlighting parameters to {@link org.apache.solr.client.solrj.SolrQuery}
*
* @param solrQuery
* @param query
*/
protected void processHighlightOptions(SolrQuery solrQuery, HighlightQuery query) {
if (query.hasHighlightOptions()) {
HighlightOptions highlightOptions = query.getHighlightOptions();
solrQuery.setHighlight(true);
if (!highlightOptions.hasFields()) {
solrQuery.addHighlightField(HighlightOptions.ALL_FIELDS.getName());
} else {
for (Field field : highlightOptions.getFields()) {
solrQuery.addHighlightField(field.getName());
}
for (FieldWithHighlightParameters fieldWithHighlightParameters : highlightOptions
.getFieldsWithHighlightParameters()) {
addPerFieldHighlightParameters(solrQuery, fieldWithHighlightParameters);
}
}
for (HighlightParameter option : highlightOptions.getHighlightParameters()) {
addOptionToSolrQuery(solrQuery, option);
}
if (highlightOptions.hasQuery()) {
solrQuery.add(HighlightParams.Q, getQueryString(highlightOptions.getQuery()));
}
}
}
示例2: prepareQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery prepareQuery(PatientSearch search, boolean highlight) {
SolrQuery query = search.initQuery();
query.addFilterQuery("domain:med");
query.addSort("overall_stop", ORDER.desc);
query.addField("qualified_name");
query.addField("va_type");
query.addField("last_filled");
query.addField("last_give");
query.addField(CLASS_FIELD);
query.set(GroupParams.GROUP, true);
query.set(GroupParams.GROUP_FIELD, "kind");
query.add(GroupParams.GROUP_FIELD, "qualified_name");
if (highlight) {
query.setHighlight(true);
query.addHighlightField("administration_comment");
query.addHighlightField("prn_reason");
query.setHighlightFragsize(72);
query.setHighlightSnippets(5);
}
return query;
}
示例3: getSolrQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* 分頁查詢,包含查詢,分頁,高亮及獲取高亮處摘要等內容;不同於數據庫的查詢分頁,
* solr的查詢返回值中有文檔總數,所以無需再次查詢總條數。
*
* @param solrServer, page 自定義的翻頁對象,包含查詢信息及當前頁數據列表。
* @return List<FileModel>
*/
public PageModel getSolrQuery(SolrServer solrServer, PageModel pageModel, Map filterQuery) {
String type = (String) filterQuery.get("type");
if(type == null || "".equals(type)) {
type = "*";
}
String role = (String) filterQuery.get("role");
if(role == null || "".equals(role)) {
role = "anonymous";
}
SolrQuery query = new SolrQuery();
// 獲取查詢參數
String para = pageModel.getParameter();
// System.out.println("para: " + para + "; type: " + type);
//TODO
// 過濾文件與權限類型
// query.setQuery("content_text:" + para);
query.setQuery(para);
query.setFilterQueries(
"(" + getTypeFilter(type) + ")"
+ "AND (" + getRoleFilter(role) + ")"
);
query.set("defType","edismax");
query.set("qf","file_name^10 content_text^1");
// query.addSort("upload_time", SolrQuery.ORDER.desc);
query.setStart((int)pageModel.getStart());
query.setRows(pageModel.getSize());
// System.out.println(page.getStart() + " " + page.getSize());
//設置高亮
query.setHighlight(true);// 開啟高亮組件
query.addHighlightField("file_name");// 高亮字段
query.addHighlightField("content_text");// 高亮字段
query.setHighlightSimplePre("<hlt>");//標記,高亮關鍵字前綴
query.setHighlightSimplePost("</hlt>");//後綴
query.setHighlight(true).setHighlightSnippets(2); //獲取高亮分片數,一般搜索詞可能分布在文章中的不同位置,其所在一定長度的語句即為一個片段,默認為1,但根據業務需要有時候需要多取出幾個分片。 - 此處設置決定下文中titleList, contentList中元素的個數
query.setHighlightFragsize(150);//每個分片的最大長度,默認為100。適當設置此值,如果太小,高亮的標題可能會顯不全;設置太大,摘要可能會太長。
return getPageModel(solrServer, pageModel, query);
}
示例4: search
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的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;
}