SolrJ查詢使用,高亮查詢

2021-06-25 23:41:44 字數 1154 閱讀 9754

main方法測試

public static void main{

string zkhost="";

string defaultcollection="collection1";

cloudsolrserver solr =new cloudsolrserver(zkhost);

solr.setdefaultcollection(defaultcollection);

solrquery query=new solrquery();

query.setquery(" id:?  content:??  name:??  ");--每個字段中間需要乙個空格,必須的。或者用or連線

query.sethighlight(true).sethighlightsnippets(1);--分片使用,也就是檢索出檔案的部分內容。顯示

query.sethighlight******pre("");

query.sethighlight******post("");

query.addhightlightfield("content");--新增要進行高亮查詢的欄位名稱

queryresponse queryresponse =solr.query(query);

querydocumentlist list=queryresponse.getresults();

map>>  iter=queryresponse.gethighlight();------得到高亮查詢結果,是個map型別

for(solrdocument lstl list){

string id=(string) lst.getfilevalue("id");

map> map_temp=iter.get(id);

if(queryresponse.gethightlighting().get(id)!=null){

listhighlightsnippets=map_temp.get("mycontent");

string mycontent=highlightsnippets.get(0).trim();

system.out.print(mycontent);---已經是個string型別的字串了

highlightsnippets如果需要所有的分片,遍歷下就可以了(for迴圈)

使用solrj索引查詢

1 查詢 solrj提供的查詢功能比較強大,可以進行結果中查詢 範圍查詢 排序等。下面是筆者封裝的乙個查詢函式 public static queryresponse search string field,string key,int start,int count,string sortfiel...

solrj 等價sql查詢

solrj 等價sql查詢 除日期型別資料需要進行特殊解析外,其它型別直接使用 dateformat sdf new dateformat yyyy mm dd dateformat sdfin new dateformat yyyy mm dd t hh mm ss z preparing sol...

elasticsearch高亮查詢

pageinfo elasticsearchtemplate.queryforpage query,article.class 帶條件的分頁查詢 test public void testselectpagebyid 建立querybuilder查詢條件 querybuilder querybuil...