sorting - Sum field and sort on Solr -
i'm implementing grouped search in solr. i'm looking way of summing 1 field , sort results sum. following data example hope clearer.
{ [ { "id" : 1, "parent_id" : 22, "valuetobesummed": 3 }, { "id" : 2, "parent_id" : 22, "valuetobesummed": 1 }, { "id" : 3, "parent_id" : 33, "valuetobesummed": 1 }, { "id" : 4, "parent_id" : 5, "valuetobesummed": 21 } ] } if search made on data i'd obtain
{ [ { "numfound": 1, "summedvalue" : 21, "parent_id" : 5 }, { "numfound": 2, "summedvalue" : 4, "parent_id" : 22 }, { "numfound": 1, "summedvalue" : 1, "parent_id" : 33 } ] } do have advice on ?
solr 5.1+ (and 5.3) introduces solr facet functions solve exact issue.
from yonik's introduction of feature:
$ curl http://localhost:8983/solr/query -d 'q=*:*& json.facet={ categories:{ type : terms, field : cat, sort : "x desc", // can use sort:{x:desc} facet:{ x : "avg(price)", y : "sum(price)" } } } ' so suggestion upgrade newest version of solr (the recent version 5.2.1, advised of syntax that's on above link landed in 5.3 - current release target).
Comments
Post a Comment