Highlighting search results

How to highlight search results in Search API Solr View in Drupal 8

In Search API, there is a field for a search excerpt that you can use on field views to highlight search results. In this article, I’m going to show you how to enable excerpt and set it using views. Here I’m assuming that you have already set the Search API module and has a Search API Solr view.

Follow the steps:

Go to Manage -> Configuration -> Search and Metadata -> Search API.

In your search API index ‘processors’ tab, enable Highlight Processor as shown below.

search API index ‘processors’ tab

In the processor settings tab, check “Create excerpt” field. You can also set the fields to generate excerpt.

Create excerpt field

Save the configurations and re-index all the data so that the added configuration will take effect.

GreenBook Data Solutions

Greenbook Solution

Valuebound helped Farm Journal Media’s Greenbook to provide its end users with a user-friendly interface. Greenbook caters specifically to the North American region with 800 manufacturers listing ten thousand labels. Valuebound migrated this directory based site from a legacy based system to new architecture based on Drupal 8 for easy search of information, highly categorized indexing with options like active ingredient contained, label, crop, manufacturer, pest and so on.

Farm Journal Media is America’s leading business information and media company serving the agricultural market. Started 139 years ago with the pre-eminent Farm Journal magazine, the company serves the row crop, livestock, produce and retail sectors through 26 branded websites, e-newsletters and phone apps; 11 business magazines; 70 events; six nationally broadcasted television and radio programs; a robust mobile text marketing business; and an array of data-driven paid information products. Greenbook is owned and maintained by the Farm Journal Media. For more than 30 years Greenbook has collected, maintained, and disseminated the most useful plant protection chemical dataset available. Working in direct cooperation with pesticide companies Greenbook transforms product labeling into indexed, actionable data in an unbiased presentation, that is easily accessible.

Edit your Search API Solr view. You can display highlighted results only if your view is displaying fields. However, if you need to build a custom view based search_api search that renders entities instead of using fields, the excerpt info stays hidden in the view result array.

custom view based search_api


Click on Add fields and select the excerpt field

Create excerpt field

You can add other fields along with Excerpt field as per your requirements. Save the view and check the search results, You will be able to see highlighted output!! 

Hope now you know how to highlight search results in Search API Solr View for Drupal 8 website. If you have any suggestions or queries please comment below let me try to answer.


comments powered by Disqus