Highlighting fragments found in documents

Imagine a situation where you want show your users the words that were matching from the document, which were shown in the results list. For example, you want to show which words in the book name were matched and displayed to the user. Do you have to store the documents and do the matching on the application side? The answer is no—we can force Solr to do this for us, and this recipe will show you how to do this.

How to do it...

  1. We will begin with creating the following index structure (just add the following fields to your schema.xml file):
    <field name="id" type="string" indexed="true" stored="true" required="true" />
    <field name="name" type="text_general" indexed="true" stored="true" />
  2. For the purpose of ...

Get Solr Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.