I need to sort the facets that come back from SOLR by relevancy

Posted by Pinguthepenguin on Stack Overflow See other posts from Stack Overflow or by Pinguthepenguin
Published on 2010-05-17T18:01:49Z Indexed on 2010/05/17 22:20 UTC
Read the original article Hit count: 202

I have within my SOLR index song objects which belong to a higher level album object. An example is shown below:

<song>
<album title>Blood Sugar Sex Magic</album title>
<song title>Under the Bridge</song title>
<description>A sad song about junkies</description>
</song>

What I can do at the moment is create a facet on the album title so that a search on songs will also show me what albums contain hits for that keyword.

The default behaviour for SOLR is that the facets are shown in the order of most hits to least. However what I want to achieve is the facet list to be sorted according to the relevancy of the top hit for that album.

For example a search on the word "sad" may show a facet with one hit for "Blood Sugar Sex Magic" and there may also be an album called "Sad Clown songs" where there are 10 hits. "Sad clown songs" will show as the first facet even though it may be that "Under the bridge" comes up as the most relevant song.

My question is how can I get all the facets back but then have them ordered by the relevancy of the songs within them? If I would need to change or extend some underlying SOLR code what would that be?

Thanks in advance.

© Stack Overflow or respective owner

Related posts about solr

Related posts about sorting