Highlighting in Hybris Search


Many applications like to highlight snippets of text from each search result so the user can see why the document matched the query. Hybris out-of-the-box isn’t able to highlight words in the search results. Hybris also doesn’t use a free text search for product attributes from the classification catalog. This post explains how to make these attributes searchable and how to highlight search results. image2016-6-28 18-21-12.png


Hybris does not support highlighting. However, Apache SOLR, a part of hybris, does. So the solution, and the complexity, is in the integration.


In my solution: (1) SOLR needs a designated field for highlighting. This field should contain the texts from all textual attributes of the product. (2) Additional parameters should be added to the SOLR query. (3) The highlighted fragments go separately from the products in the response.

Technical details

(1) I added the custom field Product.allFields to the Product model. Each time the product attributes are changed, the PrepareInterceptor rebuilds this field. For example, in the product #1934406 from the demo shop, the field is populated with the following data (CSV): HDR-CX105E  Red, – 1920x1080i HD video recording using AVCHD format<br/>-Records up to 3 hours HD video on 8 GB internal flash memory plus HYBRID recording on optional Memory Stick™<br/>-Exmor™ CMOS sensor for brilliant picture quality with high sensitivity and low noise<, 4905524596595, Sony, 2.36 Megapixel CCD (1/5″”), 8 GB Flash Memory, Memory Stick, MPEG2 (1920 × 1080), JPEG (max.2304 × 1728 Pixel), 10x Zoom, 120x Digitaler Zoom, SteadyShot image stabilization, 2.7” Wide LCD, PictBridge, Memory Stick (Duo/Pro Duo) Slot, USB 2.0 (Out), Video (Out), Audio (Out), S-Video (Out), Component Video (out), HDMI (out),Li-Ion, Camcorder tape type: Flash memory., Camera shutter speed: 1/2 – 1/1000s, Minimum illumination: 5.0lx, Source data-sheet: ICEcat.biz., Power consumption: 3.5W, Recording speed: HD, FH (1920x1080i, 16Mbps) / HQ (9Mbps) / SP (7Mbps) / LP (5Mbps) , SD., Internal memory: 8000.0MB, Display: LCD., Display diagonal: 2.7″, Display resolution: 211200.0pixels, Digital zoom: 120.0x, Aperture range: 1.8., 35 mm camera lens equivalent: 42.0mm, Focal length: 3.2mm, Filter size: 30.0mm, Megapixel: 2.36MP, Optical zoom: 10.0x, Lens system: Carl Zeiss Vario-Sonnar T*., USB 2.0 ports quantity: 1.0., Video out: 1.0., Audio output: 1.0., HDMI ports quantity: 1.0., S-Video out: 1.0., Depth: 107.0mm, Weight: 280.0g, Height: 60.0mm, Width: 55.0mm, Battery type: NP-FH60., Battery life: 1.5h, Audio system: Dolby Digital 2ch., Colour of product: Red., Compatible memory cards: Memory Stick., Optical sensor resolution: 2360000.0pixels, Effective sensor resolution: 1990000.0pixels, Optical sensor size: 1/5.0″, Sensor type: Exmor CMOS Sensor., Video capture resolution: 1920 × 1080pixels, Still image capture resolutions: 2304 × 1728%, Bundled software: Picture Motion Browser., (2) I implemented the custom FacetSearchStrategy (that extends DefaultFacetSearchStrategy) In the middle of the “search” method, before solrClient.query(solrQuery), I injected the configuration for the SOLR highlighter.
(3) I parse the response from SOLR. With the configuration above, the SOLR response will have an additional block for highlighting.
<lst name="highlighting">
<lst name="electronicsProductCatalog/Online/816379">
<arr name="allFields_text_en">
SAL-1680Z - DT 16-80mm F3.5-4.5 ZA <em>Carl</em> <em>Zeiss</em> Vario-Sonnar T* zoom lens, Minimum aperture: 22 - 29., Viewing
<lst name="electronicsProductCatalog/Online/23231">
<arr name="allFields_text_en">
and get better results. Armed with high-quality <em>Carl</em> <em>Zeiss</em> optics, ISO sensitivities of 100/200/400/800
5.2Mpix 8MB <em>Carl</em> <em>Zeiss</em> Lens Zoom ring High speed USB 10xdig.Zoom PEG, Display: LCD TFT 1.8"" color".,
I extended SearchResponseResultsPopulator to parse this information and replace product.summary with the snipped if it exists. Otherwise, the standard summary data is displayed.

© Rauf Aliev, July 2016

3 Responses

  1. Boufnichel Mohamed

    Boufnichel Mohamed


    1 September 2016 at 13:51

    Great job !

  2. Mikhail



    29 June 2017 at 11:51

    We’ve done something similar but had to turn it off because request time in solr increased significantly.

  3. Aliaksei



    21 September 2017 at 07:58

    Finally, it’s a part of 6.5

Leave a Reply