Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7191785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:48:10+00:00 2026-05-28T19:48:10+00:00

I need to sort the results I get back from apache solr based on

  • 0

I need to sort the results I get back from apache solr based on two factors:

There are three entities in our system that are indexed by solr (groups, projects and datasets) and in the results I want datasets to be displayed first, followed by projects and then groups; but I still want it to respect to score values for each of the types.

So, for example: results would be

  1. Dataset with score of 0.325
  2. Dataset with score of 0.282
  3. Dataset with score of 0.200
  4. Project with score of 0.298
  5. Project with score of 0.186
  6. Group with score of 0.360
  7. Group with score of 0.270

I’m doing this in java and using solrj to construct the solr queries. The problem is that when I try to add 2 sort fields to the SolrQuery object it only seems to use one of them. Also in the solr documents there isn’t anything to state the entity type but the document’s ID is prefixed with the entity name so I was planning to use that.

If anyone has got any ideas on how I could achieve this it would be greatly appreciated as I’ve been stuck on this for a while now!

Thanks in advance,
-Jake.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:48:11+00:00Added an answer on May 28, 2026 at 7:48 pm

    If it looks like solrj is using just one of the sort fields, maybe you’re using the SolrQuery#setSortField method instead of the addSortField like this:

    solrQuery.addSortField("field1", ORDER.desc);
    solrQuery.addSortField("field2", ORDER.desc);
    

    In order to sort the results as you described, a cleaner solution would be adding a field to your index containing a kind of weight based on the entity type. Then you could directly sort using that field: weight desc, score desc. Before doing this, just make sure the weight has always to win against the solr score, otherwise you should work on influencing the solr score.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need sphinx to sort the results by the sum of an attribute. I
I need some sort of interactive chart control for my .NET-based web app. I
I get some GPS coordinates from Google Maps and I need to find the
I need to get the sum of columns based on the name of the
I need to force my c++ QT4 application to read results from a linux
I need to sort tuples according to the second element of each tuple but
I need some sort of node-graph editor, that hopefully works on both Mac and
I need to sort on a date-field type, which name is mod_date. It works
I need to sort close to a 1,00,000 floating point entries in Delphi. I
I need to sort string, and I came up with the following function. def

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.