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 Jay Hill <ja...@gmail.com> on 2010/06/20 21:12:01 UTC

SolrJ: Setting multiple parameters

Working with SolrJ I'm doing a query using the StatsComponent, and the
stats.facet parameter. I'm not able to set multiple fields for the
"stats.facet" parameter using SolrJ. Here is the query I'm trying to create:

http://localhost:8983/solr/select/?q=*:*&stats=on&stats.field=fieldForStats&stats.facet=fieldA&stats.facet=fieldB&stats.facet=fieldC

This works perfectly, and I'm able to pull the "sum" value from all three
stats.facet fields, no problem.

Trying in SolrJ I have this:
  SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("*:*");

    solrQuery.setParam("stats", "on");
    solrQuery.setParam("stats.field", "fieldForStats");
*    solrQuery.setParam("stats.facet", "fieldA");
    solrQuery.setParam("stats.facet", "fieldB");
    solrQuery.setParam("stats.facet", "fieldC");*

But when I try to retrieve the "sum" values, it seems as if only the LAST
setParam I called on "stats.facet" is taking. So in this case I can get the
sum for fieldC, but not the other two:

//works
      Map<String, FieldStatsInfo> statsInfoMap =
queryResponse.getFieldStatsInfo();
      FieldStatsInfo roomCountElement = statsInfoMap.get("fieldForStats");

      ArrayList fsi = (ArrayList) roomCountElement.getFacets().get("field*C*
");
      for (int i = 0; i < fsi.size(); i++) {

        FieldStatsInfo m = (FieldStatsInfo) fsi.get(i);
        System.out.println("--> " + m.getName() + "   ---------------- " +
m.getSum());

      }

//doesn't work, get a null pointer as "fieldB" doesn't seem to have been
passed to "stats.facet"
      Map<String, FieldStatsInfo> statsInfoMap =
queryResponse.getFieldStatsInfo();
      FieldStatsInfo roomCountElement = statsInfoMap.get("fieldForStats");

      ArrayList fsi = (ArrayList) roomCountElement.getFacets().get("field*B*
");
      for (int i = 0; i < fsi.size(); i++) {

        FieldStatsInfo m = (FieldStatsInfo) fsi.get(i);
        System.out.println("--> " + m.getName() + "   ---------------- " +
m.getSum());

      }

Is there a way to set multiple values for "stats.facet" using the "setParm"
method?  I noticed that there is a "setGetFieldStatistics" method which can
be used to set the stats.field, but there don't seem to be any methods that
reach as deep as setting the stats.facet.

Thanks,
-Jay

Re: SolrJ: Setting multiple parameters

Posted by Jan Høydahl / Cominvent <ja...@cominvent.com>.
Or simply use add(), because setParam overrides existing hashMap key:

   solrQuery.setParam("stats.facet", "fieldA");
   solrQuery.add("stats.facet", "fieldB");
   solrQuery.add("stats.facet", "fieldC");

--
Jan Høydahl, search solution architect
Cominvent AS - www.cominvent.com
Training in Europe - www.solrtraining.com

On 20. juni 2010, at 21.17, Chris Hostetter wrote:

> 
> : *    solrQuery.setParam("stats.facet", "fieldA");
> :     solrQuery.setParam("stats.facet", "fieldB");
> :     solrQuery.setParam("stats.facet", "fieldC");*
> : 
> : But when I try to retrieve the "sum" values, it seems as if only the LAST
> : setParam I called on "stats.facet" is taking. So in this case I can get the
> : sum for fieldC, but not the other two:
> 
> It's a vararg method...
> 	setParam(String name, String... values) 
> 
> ...so use...
> 
>  solrQuery.setParam("stats.facet", "fieldA", "fieldB", "fieldC");
> 
> ...or if your list of fields is being dynamicly generated...
> 
>  String[] fieldsForStatFaceting = getStatsFacetFields();
>  solrQuery.setParam("stats.facet", fieldsForStatFaceting);
> 
> 
> 
> -Hoss
> 


Re: SolrJ: Setting multiple parameters

Posted by Chris Hostetter <ho...@fucit.org>.
: *    solrQuery.setParam("stats.facet", "fieldA");
:     solrQuery.setParam("stats.facet", "fieldB");
:     solrQuery.setParam("stats.facet", "fieldC");*
: 
: But when I try to retrieve the "sum" values, it seems as if only the LAST
: setParam I called on "stats.facet" is taking. So in this case I can get the
: sum for fieldC, but not the other two:

It's a vararg method...
	setParam(String name, String... values) 

...so use...

  solrQuery.setParam("stats.facet", "fieldA", "fieldB", "fieldC");

...or if your list of fields is being dynamicly generated...

  String[] fieldsForStatFaceting = getStatsFacetFields();
  solrQuery.setParam("stats.facet", fieldsForStatFaceting);



-Hoss