Book Image

Solr Cookbook - Third Edition - Third Edition

By : Rafal Kuc
Book Image

Solr Cookbook - Third Edition - Third Edition

By: Rafal Kuc

Overview of this book

This book is for intermediate Solr Developers who are willing to learn and implement Pro-level practices, techniques, and solutions. This edition will specifically appeal to developers who wish to quickly get to grips with the changes and new features of Apache Solr 5.
Table of Contents (18 chapters)
Solr Cookbook Third Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

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 this recipe, we will use the following test data:

    <add>
     <doc>
      <field name="id">1</field>
      <field name="name">Solr Cookbook first edition</field>
     </doc>
     <doc>
      <field name="id"&gt...