Chapter 5. Advanced search techniques

 

This chapter covers

  • Loading field values for all documents
  • Filtering and sorting search results
  • Span and function queries
  • Leveraging term vectors
  • Stopping a slow search

Many applications that implement search with Lucene can do so using the API introduced in chapter 3. Some projects, though, need more than the basic searching mechanisms. Perhaps you need to use security filters to restrict which documents are searchable for certain users, or you’d like to see search results sorted by a specific field, such as title, instead of by relevance. Using term vectors, you can find documents similar to an existing one, or automatically categorize documents. Function queries allow you to use arbitrary logic when computing scores for each hit, enabling you to boost relevance scores according to recency. We’ll cover all of these examples in this chapter.

Rounding out our advanced topics are

  • Creating span queries, advanced queries that pay careful attention to positional information of every term match within each hit
  • Using MultiPhraseQuery, which enables synonym searching within a phrase
  • Using FieldSelector, which gives fine control over which fields are loaded for a document
  • Searching across multiple Lucene indexes
  • Stopping a search after a specified time limit
  • Using a variant of QueryParser that searches multiple fields at once

5.1. Lucene’s field cache

5.2. Sorting search results

5.3. Using MultiPhraseQuery

5.4. Querying on multiple fields at once

5.5. Span queries

5.6. Filtering a search

5.7. Custom scoring using function queries

5.8. Searching across multiple Lucene indexes

5.9. Leveraging term vectors

5.10. Loading fields with FieldSelector

5.11. Stopping a slow search

5.12. Summary

sitemap