SOLR Learning Document highlighting

Source: Internet
Author: User
Tags solr

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.