Jinyoung Kim
Jinyoung Kim

Reputation: 2211

Is it possible to tweak Solr hit relevance score based on length of content?

I have a Rails app using sunspot to do searches against a table with records of varying sizes. I want to adjust the score of the hit depending on how large a certain field is. This is to punish articles that have very little content but happens to have the term being searched for showing up at the top. Is that possible?

Upvotes: 0

Views: 608

Answers (2)

Cody Caughlan
Cody Caughlan

Reputation: 32748

One technique: compute the body length at insertion time and give the whole document a Boost based on its higher length - you'd supply this Boost manually, for each document at index-time.

See this FAQ: http://wiki.apache.org/solr/SolrRelevancyFAQ#How_can_I_increase_the_score_for_specific_documents

Upvotes: 2

Cody Caughlan
Cody Caughlan

Reputation: 32748

This mailing list thread seems to kind of answer your question - and brings up another point that you might be thinking about this wrong.

http://osdir.com/ml/solr-user.lucene.apache.org/2010-05/msg00916.html

This quote is illustrative: "I have to ask, though, why you want to sort this way? The relevance calculations already factor in both term frequency and field length. What's the use-case for sorting by field length given the above?"

Upvotes: 0

Related Questions