“Car sale application”– Result Grouping, two additional parameters description (part 7)

In the last “car sale application” related post we have described the result grouping functionality. Today I would like to show you how easily we can determine the groups amount and how to sort documents within every group.

Requirements specification

I would like to be able to create a grouping query, that will show me the number of generated groups and provide only one result within every group – the one with the lowest price in its year group.

New functionality request parameters description

What we need is:

  • group.ngroups – boolean type parameter that allows us to include the number of generated groups
  • group.sort – parameter describing how to sort documents within a group

Let’s create query

Using the query example from the previous post, let’s add two new parameters:

As you see, we’ve also set the group.limit parameter to 1 (in order to have the only one result within every group) and extended the value of fl parameter by adding the price field. As a result we have the response:

As we see in the response, we have a new element that shows us how many groups are generated:

We also have only one document in each year group – the car with the lowest price in its year group. You don’t believe me ? Look at the query responses from the previous post and compare the prices 🙂

The end

It was a fast review of yet two another grouping parameters. Big thanks to David Martin who gave me the subject by asking some questions in the previous post 🙂

One thought on ““Car sale application”– Result Grouping, two additional parameters description (part 7)

  • 31 January 2012 at 16:32
    Permalink

    Grouping is a very useful feature, but it has some pitfall too.
    If you are using paging for your results and “5” is your referenz for count, you may have problems to visualize your results. Eg. count is 100 and your result-set are only 20 grouped array items, you have no page 3 (for 10 elements per page).

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.