dotancohen
dotancohen

Reputation: 31481

How many groups of results are available?

Consider the following query:

/solr/select?q=linux

It returns this XML response:

<response>
    <lst name="responseHeader">
        <int name="status">0</int>
        <int name="QTime">0</int>
        <lst name="params">
            <str name="q">linux</str>
        </lst>
    </lst>
    <result name="response" numFound="10943" start="0">

From here we can see that there are 10943 documents which match our query. However, consider the same query with grouping:

/solr/select?q=linux&group=true&group.field=tag

It returns this XML response:

<response>
    <lst name="responseHeader">
        <int name="status">0</int>
        <int name="QTime">10</int>
        <lst name="params">
            <str name="group">true</str>
            <str name="group.field">tag</str>
            <str name="q">linux</str>
        </lst>
    </lst>
    <lst name="grouped">
        <lst name="tag">
            <int name="matches">10943</int>
            <arr name="groups">
                <lst>
                    <str name="groupValue">linux</str>
                    <result name="doclist" numFound="1224" start="0">

From here we can see that there are 10943 documents which meet our query (obviously, it is the same query as in the first example). We can also see that we have 1224 documents with the 'linux' tag. However, there is no mention of how many matched groups there are. Thus, one cannot use pagination to present a list of tags as there is no way to calculate how many pages will be needed.

How can one get the amount of groups returned, in order to calculate how many pages of pagination will be available?

Thanks.

Upvotes: 1

Views: 84

Answers (1)

Jayendra
Jayendra

Reputation: 52779

For the number of groups use the groups.ngroups request parameter which will give the count for the number of groups for pagination.

Documentation :-

group.ngroups
true/false
If true, includes the number of groups that have matched the query. Default is false.

Upvotes: 4

Related Questions