简体   繁体   中英

Sunspot: How to implement a Search Result Hierarchy?

I`m currently working on implementing Solr through Sunspot in a Rails project.

Looking at documentation I don`t see how I would implement a hierarchy of search results, by that I mean:

  • All users that match the query & have profile pictures should be displayed first.

  • All users that match the query & don`t have a profile picture should be displayed underneath.

  • And so on... .

I would appreciate any guidance or references on how to implement such a system.

If you want to display users with profile pictures first and the ones who don't later -
you can use sorting with sortMissingLast , this will cause all the records which do not have any value to appear last.
else have a default value for the records not having a value so that they appear last when sorted.

I've heard this request many times over the years, and it doesn't work quite like people expect. The worst case behavior is pretty bad and pretty common.

You may not want to do exactly that. As soon as you include a common term, like "Jr", you will have to show thousands of results with pictures before the first profile without a picture, even if that one is the right result.

This will happen more often than you expect, because common names are, well, common, so they show up in queries a lot and match a lot of documents. This may happen for your most common queries. Oops.

Instead, boost results with a quality factor. If there are two "Joe Smith" profiles, the one with the picture is better and should be shown first. You can do this with the "boost" parameter of the edismax result handler. If a profile has a photo, use a boost of 2, otherwise a boost of 1. You may have to play with the exact values to get what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM