You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Michael Ryan <mr...@moreover.com> on 2011/10/28 05:37:23 UTC

Applying hl.requireFieldMatch to "groups" of fields

I am trying to highlight FieldA when a user searches on either FieldA or FieldB,
but I do not want to highlight FieldA when a user searches on FieldC.

To explain further: I have a field named "content" and a field named
"contentCS". The content field is a stored text field that uses
LowerCaseFilterFactory (i.e., case-insensitive). The contentCS field is a copy
of the content field, but is not stored and does not use LowerCaseFilterFactory
(i.e., case-sensitive).

My query looks like "q=...&fl=content&hl.requireFieldMatch=true&hl.fl=content".
I use requireFieldMatch because I do not want certain other things I put in the
query to be highlighted in the content field.

When I search on either the content or the contentCS fields, I would like the
content field to be highlighted. But when searching on any other fields, I do
not want the terms for those fields to be highlighted in the content field.

I was thinking I could hack this into DefaultSolrHighlighter, QueryTermScorer,
and QueryTermExtractor. Perhaps the syntax could look like
"hl.content.useMatchesFromTheseFields=content,contentCS", and then I would
pass an array of field names down into QueryTermExtractor. Anyone have any
tips/comments on this? I never looked at the highlighting code before, so not
sure what I'm getting myself into...

-Michael