venkat
venkat

Reputation: 2310

Solr dynamic sorting

We have a website on which you can search through a large amount of products from different shops. Say we have 5 products per result page and the 10 best matches for a search have all the same score. 8 of the products are of one shop (A), and the two others by two other shops (B,C).

What we often get is (letter indicating a product of this shop)

  1. A
  2. A
  3. A
  4. A
  5. A

---- second result page ----

  1. A
  2. B
  3. A
  4. C
  5. A

but what we want to get is something like this:

  1. A
  2. C
  3. B
  4. A
  5. A

---- second result page ----

  1. A
  2. A
  3. A
  4. A
  5. A

Writing function query seems to be one option http://www.solrtutorial.com/custom-solr-functionquery.html

What is the best way to achieve this?

Upvotes: 1

Views: 637

Answers (1)

Srikanth Venugopalan
Srikanth Venugopalan

Reputation: 9049

You could group the results by shop using Field Collapsing and display the result either as a group or flattened list (depending on how you want it).

Another trick that I've seen in use to help the users see results from multiple group is to use Facets. You could have a sidebar (or something similar) that does two things:

  1. By default it lets the user know that there are other filter criteria (ex. shops) in the result. This helps a lot when the result is paginated.

  2. With facets being present, it is upto the user to choose whatever criteria she/he wishes to apply, thus relieving you of implementing heavy scenario based logic.

Read more about faceting here.

Edit:

If you have to use custom sort logic, you could write it down using Functions and use it in the sort when querying Solr. Here is the reference from the docs.

Upvotes: 2

Related Questions