In the "SOLR Learning document Add Word Thesaurus" article, we learned how to extract a word from a phrase, this chapter will use the word thesaurus, and how to highlight
Before we do this, let's look at some of the highlighted parameters
HL : If the highlight component is turned on, true to open, false to not open
HL.FL : Highlight field to open, multiple comma separated
Hl.simple.pre : Highlight field prefix
Hl.simple.post : Highlight field suffix
(Other temporarily do not introduce, want to know can self-Baidu)
To highlight the station, you need to Schema.xml Place your field name (for example, topiccontent ) of type set to Word type, we are using the Text_ik , so you need to rewrite your fields like this
<field name= "topiccontent" type= "Text_ik" indexed= "true" stored= "true"/>
After you have finished rebuilding the index and clicking HL in the query of SOLR (browser interface) and correctly configuring the parameters described above, you will see the following
The Java implementation highlighting code is as follows:
public static void Main (string[] args) {String url = "HTTP://LOCALHOST:8080/SOLR"; Solrserver Server = new Httpsolrserver (URL); Solrquery query = new Solrquery (); Query.setquery ("topiccontent:\" I am not a good person \ ")"; Query.addfield ("id"); Query.addfilterquery ("Topiccontent"); Query.setstart (0); Query.setrows (10); Set the Highlight Query.sethighlight (true); Turn on the Highlight component Query.addhighlightfield ("topiccontent");//Highlight Field Query.sethighlightsimplepre ("<font color= ' Red ' >"); /tag, highlight keyword prefix query.sethighlightsimplepost ("</font>");//suffix query.sethighlightsnippets (3);//result shard number, default is 1 quer Y.sethighlightfragsize (100);//maximum length of each shard, default is try {queryresponse response = server.query (query); Solrdocumentlist docs = Response.getresults (); Map<string, map<string, list<string>>> map=response.gethighlighting (); for (Solrdocument Doc:docs) {SysTem.out.println (Map.get (Doc.getfieldvalue ("id"). toString ())); }} catch (Solrserverexception e) {e.printstacktrace (); } }
In addition, I found a problem, that is, the value behind the Q parameter, try entering "topiccontent: I am not a good person" and "topiccontent:" I am not a good person "to see their differences by themselves, Huu
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
SOLR Learning Document highlighting