You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Roman Slavík <sl...@gmail.com> on 2012/11/30 14:17:18 UTC
[Solrj 4.0] No group response
Hi guys,
I have problem with grouping in Solr 4.0 using Solrj api. I need this:
search some documents limited with solr query, group them by one field
and return total count of groups.
There is param 'group.ngroups' for adding groups count into group
response. Sounds easy, so I wrote something like this:
SolrQuery query = new SolrQuery().setQuery(queryString);
query.addField("score");
query.setParam(GroupParams.GROUP, true);
query.setParam(GroupParams.GROUP_MAIN, true);
query.setParam(GroupParams.GROUP_FIELD, "group_field");
query.setParam(GroupParams.GROUP_LIMIT, "1");
query.setParam(GroupParams.GROUP_TOTAL_COUNT, true);
QueryResponse response =
solrServer.query(query); // contains found docs
GroupResponse groupResponse = response.getGroupResponse(); // null
Search result is ok, QueryResponse contains docs I searched for. But
group response is always null. Did I miss something, some magic
parameter for enabling group response?
Thanks for any advice
Roman
Re: [Solrj 4.0] No group response
Posted by Roman Slavik <sl...@gmail.com>.
Thanks! When I switched GroupParams.GROUP_MAIN to false it works.
--
View this message in context: http://lucene.472066.n3.nabble.com/Solrj-4-0-No-group-response-tp4023439p4023940.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: [Solrj 4.0] No group response
Posted by Chris Hostetter <ho...@fucit.org>.
: query.setParam(GroupParams.GROUP_MAIN, true);
...
: GroupResponse groupResponse = response.getGroupResponse(); // null
:
: Search result is ok, QueryResponse contains docs I searched for. But group
: response is always null. Did I miss something, some magic parameter for
: enabling group response?
By using GROUP_MAIN = true, you've told the grouping code you wnat it to
flatten the grouping results and return them in the format of a single
DocList result -- so there is no GroupResponse included...
https://wiki.apache.org/solr/FieldCollapsing
"We can optionally use the results of a group command as the "main" result
(i.e. a single flat document list that would normally be produced by a
non-grouped query request) by adding the parameter group.main=true.
Although this result format does not have as much information, it may be
easier for existing solr clients to parse."
If you want the "rich" grouping response, you need to use
GROUP_MAIN=false.
-Hoss
Re: [Solrj 4.0] No group response
Posted by Kissue Kissue <ki...@gmail.com>.
Here is how i have previously used grouping. Note i am using Solr 3.5:
SolrQuery query = new SolrQuery("");
query.setRows(GROUPING_LIMIT);
query.setParam("group", Boolean.TRUE);
query.setParam("group.field", "GROUP_FIELD");
This seems to work for me.
On Fri, Nov 30, 2012 at 1:17 PM, Roman Slavík <sl...@gmail.com> wrote:
> Hi guys,
>
> I have problem with grouping in Solr 4.0 using Solrj api. I need this:
> search some documents limited with solr query, group them by one field and
> return total count of groups.
> There is param 'group.ngroups' for adding groups count into group
> response. Sounds easy, so I wrote something like this:
>
> SolrQuery query = new SolrQuery().setQuery(**queryString);
> query.addField("score");
>
> query.setParam(GroupParams.**GROUP, true);
> query.setParam(GroupParams.**GROUP_MAIN, true);
> query.setParam(GroupParams.**GROUP_FIELD, "group_field");
> query.setParam(GroupParams.**GROUP_LIMIT, "1");
> query.setParam(GroupParams.**GROUP_TOTAL_COUNT, true);
>
> QueryResponse response = solrServer.query(query);
> // contains found docs
> GroupResponse groupResponse = response.getGroupResponse(); // null
>
> Search result is ok, QueryResponse contains docs I searched for. But group
> response is always null. Did I miss something, some magic parameter for
> enabling group response?
>
> Thanks for any advice
>
> Roman
>