Re: [EXTERNAL] Re: Facet Sorting
: Chris, I was trying the below method for sorting the faceted buckets but : am seeing that the function query query($q) applies only to the score : from “q” parameter. My solr request has a combination of q, “bq” and : “bf” and it looks like the function query query($q) is calculating the : scores only on q and not on the aggregate score of q, bq and bf right. ok -- yeah, that makes sense. The thing to udnerstand is that when you use request params as "variables" in functions like that, the function doesn't know the context of your request -- "query($q)" doesn't know/treat the "q" param special, it could just as easily be "query($make_up_a_param_name_thats_in_your_request)" awhen when the query() function goes and evalutes the param you specify, it's not going to know that you have a defType of e/dismax that affects "q" param when the main query is executed -- it just parses it as a lucene query. so what you need is something like "query({!dismax bf=$bf bq=$bq v=$q})" ... i think that should work, or if not then use "query($facet_sort)" where facet_sort is a new param you add that contains "{!dismax bf=$bf bq=$bq v=$q}" alternatively, you could change your "q" param to be very explicit about the query you want, w/o depending on defType, and use a custom param name for the original query string provided by the user -- that's what i frequently do... ie: q={!dismax bf=$bf bq=$bq v=$qq}=dogs and cats ...and then the "query($q)" i suggested before should work as is. does that make sense? -Hoss http://www.lucidworks.com/
Re: [EXTERNAL] Re: Facet Sorting
Chris, I was trying the below method for sorting the faceted buckets but am seeing that the function query query($q) applies only to the score from “q” parameter. My solr request has a combination of q, “bq” and “bf” and it looks like the function query query($q) is calculating the scores only on q and not on the aggregate score of q, bq and bf My solr query is something like this q=== when I apply json facet with the below sort by score, only the scores calculated from q seem to be applying and not the aggregate score of q,bf and bq Am I missing anything here? On 7/18/18, 3:45 PM, "Chris Hostetter" wrote: : If I want to plug in my own sorting for facets, what would be the best : approach. I know, out of the box, solr supports sort by facet count and : sort by alpha. I want to plug in my own sorting (say by relevancy). Is : there a way to do that? Where should I start with if I need to write a : Custom Facet Component? it sounds like you're talking about the "classic" facets (using "facet.field") where facet.sort only supports "count" (desc) and "index" (asc) Adding a custom sort option there would be close to impossible. The newer "json.facets" API supports a much more robust set of options, that includes the ability to sort on an "aggregate" function across all documents in the bucket... https://lucene.apache.org/solr/guide/7_4/json-facet-api.html some of the existing sort options there might solve your need, but it's also possible using that API to write your own ValueSourceParser plugin that can be used to sort facets as long as it returns ValueSources that extend "AggValueSource" : Basically I want to plug the scores calculated in earlier steps for the : documents matched, do some kind of aggregation of the scores of the : documents that fall under a facet and use this aggregate score to rank IIUC what you want is possibly something like... curl http://localhost:8983/solr/techproducts/query -d 'q=features:lcd=0& json.facet={ categories:{ type : terms, field : cat, sort : { x : desc }, facet:{ x : "sum(query($q))", } } } ' ...which will sort the buckets by the sum of the scores of every document in that bucket (using the original query .. but you could alternatively sort by any aggregation of the scores from any arbitrary query / document based function) -Hoss http://www.lucidworks.com/
Re: [EXTERNAL] Re: Facet Sorting
Thank You Chris for an immediate response. I am using json facets and my question was for json facets and using solr 7.2.1. Will try your approach. Basically I want to use an average of the scores than the sum of the scores and sort those buckets based on the average score. The scores am assuming would have already been calculated in the QueryComponent when those docs were collected from the original query and calculating the average and sorting the buckets may be simple enough with your approach. Thanks again for the reply. On 7/18/18, 3:45 PM, "Chris Hostetter" wrote: : If I want to plug in my own sorting for facets, what would be the best : approach. I know, out of the box, solr supports sort by facet count and : sort by alpha. I want to plug in my own sorting (say by relevancy). Is : there a way to do that? Where should I start with if I need to write a : Custom Facet Component? it sounds like you're talking about the "classic" facets (using "facet.field") where facet.sort only supports "count" (desc) and "index" (asc) Adding a custom sort option there would be close to impossible. The newer "json.facets" API supports a much more robust set of options, that includes the ability to sort on an "aggregate" function across all documents in the bucket... https://lucene.apache.org/solr/guide/7_4/json-facet-api.html some of the existing sort options there might solve your need, but it's also possible using that API to write your own ValueSourceParser plugin that can be used to sort facets as long as it returns ValueSources that extend "AggValueSource" : Basically I want to plug the scores calculated in earlier steps for the : documents matched, do some kind of aggregation of the scores of the : documents that fall under a facet and use this aggregate score to rank IIUC what you want is possibly something like... curl http://localhost:8983/solr/techproducts/query -d 'q=features:lcd=0& json.facet={ categories:{ type : terms, field : cat, sort : { x : desc }, facet:{ x : "sum(query($q))", } } } ' ...which will sort the buckets by the sum of the scores of every document in that bucket (using the original query .. but you could alternatively sort by any aggregation of the scores from any arbitrary query / document based function) -Hoss http://www.lucidworks.com/