There are plenty of web-based applications that help users choose what they want to search for. One of the features that helps users is the autocomplete (or autosuggest) feature, like the one that most of the most used search engines have. Let's assume that we have an e-commerce library and we want to help the user to choose a book title—we want to enable autosuggest on the basis of the title. This recipe will show you how to do that.
Before you start reading this recipe, please take a look at the Getting the number of documents with the same field value recipe in this chapter.
Let's begin with the assumption of having the following index structure (just add this to your
schema.xml
file in the fields definition section):<field name="id" type="string" indexed="true" stored="true" required="true" /> <field name="title" type="text" indexed="true" stored="true" /> <field name="title_autocomplete" type...