1 @Autowired2 Privatesolrtemplate solrtemplate;3 4 @Override5 PublicMap<string, object>Search (Map searchmap) {6 returnsearchlist (searchmap);7 }8 9 //called by this classTen Privatemap searchlist (map Searchmap) { One ASimplehighlightquery Highlightquery =NewSimplehighlightquery (NewCriteria ("Hyd_keywords"). Is (Searchmap.get ("keywords"))); -Highlightquery.sethighlightoptions (NewHighlightoptions (). AddField ("Hyd_title"). Setsimpleprefix ("<em style= ' color:red ' >"). Setsimplepostfix ("< /em> ")); -highlightpage<tbitem> page = Solrtemplate.queryforhighlightpage (Highlightquery, TbItem.class); the - for(highlightentry<tbitem>highlightEntry:page.getHighlighted ()) { -Tbitem Tbitem =highlightentry.getentity (); - + if(Highlightentry.gethighlights (). Size () >0 && highlightentry.gethighlights (). Get (0). Getsnipplets (). Size () >0){ -Tbitem.settitle (Highlightentry.gethighlights (). Get (0). Getsnipplets (). Get (0));//set the result of highlighting + } A } at -hashmap<string, object> HashMap =NewHashmap<>(); -Hashmap.put ("Rowshyd", Page.getcontent ()); - returnHashMap; -}
Search highlighting
Idea: Create a simplehighlightquery , throw a conditional on the criteria, what to do when you lose a satisfying condition (highlightoptions set) , throw the things in front of the query, and give a return what type (reflection), get something to click on the set, and finally through the getcontent () to get the set of things
SOLR Highlight SPRINGDATASOLR