Enabling Hit-Highlighting on Drupal via SearchStax


The SearchStax Site Search solution allows users to enable the Hit Highlighting feature, highlighting words in the results that match the search term.

This article assumes that you have already set up a Site Search app, and connected Drupal to Site Search.

Before you begin, ensure that the following modules are installed and enabled:

To enable the modules, go to the Extend tab on your Drupal Admin dashboard, search for the module name, check the relevant box, and hit Install.

Basic Steps

  1. Enable SearchStax module and route searches through it
  2. Configure Fields for Indexing on Drupal
  3. Configure Fields for Results on Site Search
  4. Configure Fields for Search Page on Drupal
  5. Enable the server to retrieve highlighted snippets on Drupal
  6. Enable Hit Highlighting on Site Search
  7. Validate

Step 1: Enable SearchStax module and route searches through it

Follow the instructions to enable the SearchStax module, and routing the API through Site Search and add the analytics information, available at Set Up Drupal Module under the Configure the SearchStax Module section.

After it’s done, your Searchstax settings page on the Drupal Admin dashboard under Configuration > Search and metadata > SearchStax settings should look somewhat like this:

Step 2: Configure Fields for Indexing on Drupal

Configure the fields you want to be displayed and used for relevancy, following the information at Results and Display.

For the purpose of this article, we will be using the Title and Body fields as an example.
Whenever you see [your_index] in the following sections, make sure to select the correct index which you want to use for searching.

Add the fields by selecting [your_index] > Fields > Add fields if not already done so.

Make sure the fields you want to search by are of type “Fulltext”.

Then, re-index the data on Drupal by going to [your_index] > Queue all items for reindexing.

Click Confirm and then hit the Index now button for the indexing process to start immediately.

Once the indexing process is successful, the Index status progress bar at the top should be completely filled, stating the number of items that got indexed.

Step 3: Configure Fields for Results on Site Search

Next, log in to your Site Search Account dashboard, and select the app connected with Drupal.

Hit the circular Reload Schema icon to the right of Return Field under Results Configuration > Results and Display on Site Search.

Then, using the dropdown just below Return Field, add the corresponding entries for the fields added on Drupal (identified by their machine names) under the Results Configuration > Results and Display section.

For this example, the field name mappings are as follows:
Title → tm_X3b_en_title
Body → tm_X3b_en_body

Add the same fields under the Relevance Modeling > Main Profile > Search Fields section, so that while testing the search page, matches in those fields come up in the results.

Remember to add all the relevant fields (Title and Body in this example) in both places, i.e., Results Configuration and Relevance Modeling. These additions are essential for the hit-highlighting feature to work correctly.

Make sure to save your changes using the Save Draft and Publish buttons.

Step 4: Configure Fields for Search Page on Drupal

Create a Search page on Drupal by going to Structure > Views > + Add View, and selecting the Index [your_index] option from the Show dropdown menu under View settings.

Check the box that says Create a Page and hit Save and edit.

In the Search page Edit view, under the Fields section, add the Title (Indexed field) and Body (Indexed field) fields to be included in the search results. Then, click on Add and configure fields.

Check the box which says Use highlighted field data for each field, and hit Apply.

Then, add a filter under Filter criteria.

After clicking on Add and configure filter criteria, expose the newly created filter so that you are able to perform searches. Again, hit Apply and then Save for the changes to take effect.

Even without the Hit Highlighting feature enabled, you should still see the search results. Perform a test search by going to the newly created search page.

Step 5: Enable the server to retrieve highlighted snippets on Drupal

Go to Configuration > Search and metadata > Search API and edit the server.

Then, under Advanced, check the box that says Retrieve highlighted snippets and hit Save.

Step 6: Enable Hit Highlighting on Site Search

Check the box for Hit Highlighting on SearchStax Site Search dashboard, then hit Save Draft, and finally Publish for the changes to take effect.

Step 7: Validate

Once the Site Search changes are published, go back to your Drupal Search page and search for something. The matched terms in the search results should be highlighted now, appearing italicized.

That’s it! You have now successfully enabled the Hit Highlighting feature on your Drupal Search page via SearchStax Site Search.

Questions?

Do not hesitate to contact the SearchStax Support Desk.