lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexandre Drouin <>
Subject RE: How to create highlight search component using Config API
Date Fri, 15 Jul 2016 13:58:03 GMT

Thanks for info, however I got an error when adding the field using curl (sorry for the long
Command I used:
	curl -k -u user:password https://solr:8443/solr/q/config -H 'Content-type:application/json'
 -d '{ "add-searchcomponent": { "highlight": { "name": "myHighlight", "class": "srl'.HighlightComponent",
"": { "gap": { "default": "true", "name": "gap", "class": "solr.highlight.GapFragmente,"'
"defaults": { "hl.fragsize": 100 } } }, "html": [{ "default": "true", "name": "html", "class":
"solr.highlith'.HtmlFormatter", "defaults": { "hl.simple.pre": "before-", "":
"-after" }}, { "name": "html", "class": "solr.highlight.HtmlEncoder"}] }}}'

The error I got was : 
	'name' is a required field", "'class' is a required field"

I was able to figure out the correct format:
	curl -k -u user:password https://solr:8443/solr/q/config -H 'Content-type:application/json'
 -d '{ "add-searchcomponent": { "name": "highlight", "class": "solr.HighlightComponent", "":
{ "gap": { "default": "true", "name": "gap", "class": "solr.highlight.GapFragmenter", "defaults":
{ "hl.fragsize": 100 } } }, "html": [{ "default": "true", "name": "html", "class": "solr.highlight.HtmlFormatter",
"defaults": { "hl.simple.pre": before-", "": "-after" }}, { "name": "html",
"class": "solr.highlight.HtmlEncoder"}] }}'

It was accepted by Solr and I can see it when going to the url "solr/<collection>/config".
 As you can see I use the 'highlight' name to override the default one however my highlighter
is not picked up by my request handler.  If I remove my highlight search component from the
API and add it to solrconfig.xml it is picked up by my request handler.  

I compared the output of the url "solr/<collection>/config" (solrconfig.xml version)
and it was identical to what I had before when I added the search component using the API.
 I am at a loss why the search component works  when using solrconfig.xml but doesn't when
using the Config API.  Do you know why this is the case?

I am using Solr 6.0.1 with ZooKeeper.

Thanks for any help

Alexandre Drouin

-----Original Message-----
From: Cassandra Targett [] 
Sent: July 8, 2016 5:04 PM
Subject: Re: How to create highlight search component using Config API

If you already have highlighting defined from one of the default configsets, you can see an
example of how the JSON is structured with a Config API request. I assume you already tried
that, but pointing it out just in case.

Defining a highlighter with the Config API is a bit confusing to be honest, but I worked out
something that works:

{"add-searchcomponent": {"highlight": {"name":"myHighlight",
"class":"solr.HighlightComponent","": {"gap": {"default":"true",
"name": "gap", "class":"solr.highlight.GapFragmenter",
"defaults":{"hl.fragsize":100}}},"html":[{"default": "true","name":
"html","class": "solr.highlight.HtmlFormatter","defaults":
"":"<![CDATA[</em>]]>"}},{"name": "html","class":

Note there is an empty string after the initial class definition (shown as ""). That lets
you then add the fragmenters.

(I tried to prettify that, but my mail client isn't cooperating. I'm going to add this example
to the Solr Ref Guide, though so it might be easier to see there in a few minutes.)

Hope it helps -

On Wed, Jun 29, 2016 at 8:00 AM, Alexandre Drouin <> wrote:
> Hi,
> I'm trying to create a highlight search component using the Config API of Solr 6.0.1
however I cannot figure out how to include the elements fragmenter, formatter, encoder, etc...
> Let's say I have the following component:
>   <searchComponent class="solr.HighlightComponent" name="myHighlightingComponent">
>     <highlighting>
>       <fragmenter name="gap" default="true" class="solr.highlight.GapFragmenter">
>         <lst name="defaults">
>           <int name="hl.fragsize">100</int>
>         </lst>
>       </fragmenter>
>       <formatter name="html" default="true" class="solr.highlight.HtmlFormatter">
>         <lst name="defaults">
>           <str name="hl.simple.pre"><![CDATA[<em>]]></str>
>           <str name=""><![CDATA[</em>]]></str>
>         </lst>
>       </formatter>
>       <encoder name="html" class="solr.highlight.HtmlEncoder" />
>     </highlighting>
>   </searchComponent>
> From what I can see from the documentation my JSON should look a bit like this:
> {
>   "add-searchcomponent":{
>     "name":"myHighlightingComponent",
>     "class":"solr.HighlightComponent",
>     ??
>   }
> }
> However I have no idea how to defines the 2 fragmenters or the encoder.  Any help is
> Thanks
> Alex
View raw message