How to get results according to distribution?

Viewed 62

Is there a way in solr to get results according to some distribution of one of the indexed fields?

For example, imagine I have a catalog of books with fields synopsis, publication_year and genre.

I would like to build a query that returns the most relevant results according to synopsis favoring the most recently published books. However, in the final results (let's say 1000) I would like the genre to be distributed as closely as possible according to some given distribution. For example: 50% Science-Fiction, 25% Non-Fiction, 10% Politics and so on..

I know I could get a large result set and do some sort of weighted reservoir sampling to get the final 1000 books outside solr, but I am looking for a solution that would be solr only.

Is this possible and if yes, how?

1 Answers

While you won't be able to plugin your distribution, but you can use Collapse and Expand or Result Grouping to get n number of results for each genre. You then ignore any result returned above your threshold for that group.

You'll have to set the number of documents for each group to the maximum bucket size in your distribution of the total number of hits, i.e. 500 in your example above. This can give you a very large set of documents to work with, so I'd try to keep the total number returned pr. genre rather small at the start at least.

There might be some way to make the group sizes more dynamic by extending either of the two features above and adding your own code for limiting the number of documents collected per genre.

Related