views:

486

answers:

1

I have an object

Title   : foo
Summary : foo bar
Body    : this is a published story about a foo and a bar

All three are set up as fields with stored=true.

The user searches across my system for the word

"foo"

I would like to highlight foo in all three places.

The user searches for the word foo in the title

"title:foo"

I only want to highlight foo within the title.

When I added hl.requireFieldMatch=true and hl.usePhraseHighlighter=true as part of my query over to SOLR I am unable to get the highlighting in all three places when doing a generic non fielded search. Is there a way to get both scenarios to work?

I had these two items turned off, but I am adding in some fielded portions of the query that the user does not see which only display Published items for instance. the problem is

(foo AND status:published)

is causing the word published in the body to highlight when the user only searched for the word "foo".

+1  A: 

Turns out that this may be more of a quirk with act_as_solr than it is with solr / lucene.

I took advantage of the fq option within solr http://wiki.apache.org/solr/CommonQueryParameters#fq

the query no longer looks like

(foo AND status:published)

Looks more like

q=foo&fq=status:published

when it hits solr

The fq does not impact highlighting and it seems like a better way to do this since you get some solr caching benefits.

There is still a bug / feature not implemented with acts_as_solr which needs to take advantage of this as well.

For instance if my model is named article, and the user searches for the word article, AAS is building a query behind the scenes that looks like

(article AND type_t:article)

This causes the same problem that the word article highlights all over the place when you don't want it to, as well as when the user searches for the term "article" they get back every single object in the system.

Took a quick look at GitHub forks of acts_as_solr and didn't see anyone that has implemented this yet. There is nice #TODO sitting there within parser_methods.rb

Mark Redding