Search Smith

ColdFusion, SQL queries, and, of course, searching

Solr: Knowing which fields match

Posted by David Faber on March 9, 2012

How do you know which fields match your query? For example, if we search our articles index for “malaria,” and we want to know whether we matched the term in title, description, and/or journal_name, how do we go about doing that?

The answer is to turn on highlighting for those fields: hl=on&hl.fl=title,description,journal_name . Solr will return a highlighting structure containing the unique keys for each record match, along with the field that matched and a snippet of that field’s contents with the matching text highlighted. N.B.: Fields to be highlighted must be stored, but not actually indexed. How cool is that?

One Response to “Solr: Knowing which fields match”

  1. Jeff Especial said

    This isn’t necessarily viable for large documents. Highlighting slows down quite a bit. You can use the FastVectorHighlighter but the you lose some of the niceties of the default highlighter.

Leave a Comment

Your email address will not be published. Required fields are marked *