We can use different highlighting tags for different fields. Let us highlight name
with a bold
tag and series
with an italics
tag. Set the per
field tag in our code as shown in the following:
$hl->getField('name')->setSimplePrefix('<strong>')->setSimplePostfix('</strong>'); $hl->getField('series_t')->setSimplePrefix('<em>')->setSimplePostfix('</em>');
The output shows that field name
is highlighted with a bold tag whereas the field series
is highlighted with an italics tag as shown in the following screenshot:
We can also use the setQuery()
function to set a separate query for highlighting results other than the normal query. In the earlier program, let us change the highlighting to happen on harry potter
on the search for harry
as shown in the following code:
$hl->setQuery('harry potter');
On checking Solr logs it is seen that the query to...