Reputation: 2864
When I use SolrQuery's add(SolrParams params) method to add two "facet.fields" the last one overwrites the first, because the SolrQuery.add() method internally delegates to a put() method of a LinkedHashMap and a LinkedHashMap has unique keys.
How would I add two facet.field values to a SolrQuery? Do I really have to use the more specific SolrQuery.addFacetField() method (and use other methods to set things like mincount and sort for my facetfield)?
Upvotes: 0
Views: 1003
Reputation: 2864
It seems that SolrQuery.add(SolrParams params)
overwrites identical keys:
ModifiableSolrParams params1 = getParamsForTagsFacet(); // this has a 'facet.field'
ModifiableSolrParams params2 = getParamsForRegionsFacet(); // this has a 'facet.field'
SolrQuery q = new SolrQuery() // extends ModifiableSolrParams
q.add(params1); // adds first 'facet.field'
q.add(params2); // overwrites first 'facet.field'
Use q.add(String key, String... value)
instead to retain both 'facet.field' keys
ModifiableSolrParams solrParams = facet.createSolrParams();
Iterator<String> iterator = solrParams.getParameterNamesIterator();
while(iterator.hasNext()){
String param = iterator.next();
String value = solrParams.get(param);
// adding multiple identical params like this works.
// It creates a single key with multiple values in the underlying LinkedHashMap
q.add(param, value);
}
Upvotes: 3