We have a requirement to order search results based on the number of occurrence of the search term in a list of fields(not all the fields). We tried the below query in sort, but this does not provide the correct sort order.

sum(termfreq(field1,"searchQuery"), termfreq(field2,"searchQuery")<and other fields>)

We have tried using the "score" from solr but its not providing correct result based on the number of occurrence of the search term in the required fields.

Is there anything available out of the box form solr for this requirement or any other function available from solr other than termfreq ?

Sitecore 9.3 Solr 8.1.1

1 Answer 1


You can try using query-time boosting to achieve a similar result. Query-time boosting lets you add more weight to specific parts of the query. For example, you can add bosting to a Title field so that results with keyword matches in the Title field have a higher relevance score than matches in the Description field:

query.Where(x => x.Title.Contains(term).Boost(boostFactor) || 

Results are sorted by score by default so you will not need to apply additional sorting after this.

  • Thanks for the response Anna, we have tried boost, but the problem being, boost does not consider the number of occurrence. e.g. if 2 fields contains the term then the score is calculated as same irrespective of number of occurrence of the term in the fields
    – D J
    Nov 6, 2023 at 12:22
  • I see, term frequency is one of the main factors in the Solr scoring algorithm, but there are also additional factors such as frequency of rare terms and field length so the order may not be as precise as when using termfreq(). If the standard scoring does not work for you, then you can try constructing a SolrNet query as shown in the example here doc.sitecore.com/xp/en/developers/93/… and passing termfreq() function in the sort order field.
    – Anna Gevel
    Nov 7, 2023 at 8:06
  • 1
    Thanks for the response Anna, but LINQ is used in the existing implementation and it would be very tricky right now to change the search implementation and use ISolrQuery now. We are using IQueryable GetResults and building own query and facets using LINQ. Let me know, if there is any solution you could think of to implement sort in LINQ implementation.
    – D J
    Nov 8, 2023 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.