2
votes

I'm using Solr with an ASP.NET application using SolrNet.

My index has documents with title and description fields with varying lengths. This is typically queried using the dismax handler with different boosts applied to each field via the bq parameter - eg. (is_curated:true^100 OR is_curated:false^0) (title:foo^50) (description:bar^30).

I'd like to give documents with shorter titles and descriptions less prominence in search results when no search term has been specified (a default search term of *:* is specified via the q.alt parameter).

So, if a user searches for "apples", then the boost should work normally, where documents with shorter titles and descriptions that match should be weighted more heavily, but if no search term is specified, then the documents with short titles and descriptions should be weighted less heavily.

The Solr query doesn't necessarily need to account for non-empty queries, as I can perform this check from the C# code and only append any additional parameters used to reduce the weight of shorter fields if the query is empty.

Presumably I'll need to use a FunctionQuery of some sort as a boost parameter, but any advice on how to achieve this would be most appreciated. Thanks.

1
Per field index time boosting is also an option. You will have more control in c# to calculate boost factor. Performs faster too.user1452132

1 Answers

2
votes

Solr takes into account the length of the field when it calculates the Score.

lengthNorm - matches on a smaller field score higher than matches on a larger field

You can customize the Similarity Class to override the behavior.