Book Image

Solr Cookbook - Third Edition

By : Rafal Kuc
Book Image

Solr Cookbook - Third Edition

By: Rafal Kuc

Overview of this book

Table of Contents (18 chapters)
Solr Cookbook Third Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Using position aware queries


Most of the queries exposed by Lucene and Solr are not position-aware, which means that the query doesn't care about the place in the document where the word comes from. Of course, we have phrase queries that we can use for phrase searching, and even introduce the phrase slop, but this is not always enough. Sometimes, we might want to search for words with their positions in the searched documents. Let's assume that we allow our users to search for book titles and descriptions and specify how these words should be positioned related to each other. Solr provides us with such functionalities, and this recipe will show you how to use them.

How to do it...

Let's start with a simple index structure. For the purpose of this recipe, we will use the following fields:

  1. Add the following sections to the schema.xml file:

    <field name="id" type="string" indexed="true" stored="true" required="true" />
    <field name="title" type="text_general" indexed="true" stored="true...