質問

Let's say I am running a solr query that sorts by score (the default). I have a field, "brand" that contains Ford, GM, Toyota, etc. I want the results of the query to be returned such that any particular brand can only have three consecutive results? Even if the top 100 results are Toyota for my query, I still want the 101st element to be taken and shown in 4th place (so that only three Toyota cars can show up in a sequence).

I need to be able to page through the results.

I am using RoR/sunspot FYI.

Is that possible?

役に立ちましたか?

解決

Not sure if you can get exactly what you want but I'd suggest to have a look at result grouping. It allows you to group results which have the same value for a specific field, like brand in your case. You can then define how many results you want per brand through the group.limit parameter (default 1). You can then paginate over your grouped results through the group.offset parameter.

It should work as long as your brand field is not multivalued.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top