Hi Mikhail,

I'm trying to apply the scale function only to the result set (and not to
the entire collection).
And I discovered that adding "query($q)" to the scale function does the
trick.
In other words, adding "query($q)" forces solr to restrict the scale
function only to the result set.

But if I add an fq to the query parameters the scale function applies only
to the q param.
For example:

http://localhost:8983/solr/techproducts/select?q=manu_id_s:(corsair%20belkin%20canon%20viewsonic)&fq=price:[0%20TO%20200]&rows=100&fl=price,scale(sum(price,query($q)),%200,%201),manu_id_s

{
  "responseHeader":{
    "status":0,
    "QTime":8,
    "params":{
      "q":"*:*",
      "fl":"price,scale(sum(price,query($q)), 0, 1)",
      "fq":"popularity:(1 OR 7)",
      "rows":"100"}},
  "response":{"numFound":6,"start":0,"numFoundExact":true,"docs":[
      {
        "price":74.99,
        "scale(sum(price,query($q)), 0, 1)":0.034101862},
      {
        "price":19.95,
        "scale(sum(price,query($q)), 0, 1)":0.009072306},
      {
        "price":11.5,
        "scale(sum(price,query($q)), 0, 1)":0.0052296496},
      {
        "price":329.95,
        "scale(sum(price,query($q)), 0, 1)":0.15004548},
      {
        "price":479.95,
        "scale(sum(price,query($q)), 0, 1)":0.2182583},
      {
        "price":649.99,
        "scale(sum(price,query($q)), 0, 1)":0.29558435}]
  }}

I can avoid this problem by adding a new parameter query($fq) to the scale
function, but this solution is cumbersome and not maintainable.
For example:

http://localhost:8983/solr/techproducts/select?q=manu_id_s:(corsair%20belkin%20canon%20viewsonic)&fq=price:[0%20TO%20200]&rows=100&fl=price,scale(sum(sum(price,query($q)),query($fq)),%200,%201),manu_id_s

{
  "responseHeader":{
    "status":0,
    "QTime":1,
    "params":{
      "q":"manu_id_s:(corsair belkin canon viewsonic)",
      "fl":"price,scale(sum(sum(price,query($q)),query($fq)), 0,
1),manu_id_s",
      "fq":"price:[0 TO 200]",
      "rows":"100"}},
  "response":{"numFound":5,"start":0,"numFoundExact":true,"docs":[
      {
        "manu_id_s":"belkin",
        "price":19.95,
        "scale(sum(sum(price,query($q)),query($fq)), 0, 1)":0.048746154},
      {
        "manu_id_s":"belkin",
        "price":11.5,
        "scale(sum(sum(price,query($q)),query($fq)), 0, 1)":0.0},
      {
        "manu_id_s":"canon",
        "price":179.99,
        "scale(sum(sum(price,query($q)),query($fq)), 0, 1)":0.97198087},
      {
        "manu_id_s":"corsair",
        "price":185.0,
        "scale(sum(sum(price,query($q)),query($fq)), 0, 1)":1.0},
      {
        "manu_id_s":"corsair",
        "price":74.99,
        "scale(sum(sum(price,query($q)),query($fq)), 0, 1)":0.3653772}]
  }}




On Tue, May 31, 2022 at 2:48 PM Mikhail Khludnev <[email protected]> wrote:

> Hello Vincenzo,
>
> I'm not getting your point:
>
> > if I add an fq parameter the scale function still continues to work only
> on
> the q param .
>
> well, but the function actually refers to q param:
> scale(sum(price,query($q)), 0, 1).
>
> What's your expectation values of  query($q) with  "q":"popularity:(1 OR
> 7)"? I suggest to check it with fl=score
>
>
> On Tue, May 31, 2022 at 2:05 PM Vincenzo D'Amore <[email protected]>
> wrote:
>
> > Hi all,
> >
> > playing with the solr scale function I found a few corner cases where I
> > need to scale only the results set.
> >
> > I found a workaround that works but it does not seem to be viable,
> because
> > if I add an fq parameter the scale function still continues to work only
> on
> > the q param .
> >
> > For example with q=popularity:(1 OR 7):
> >
> > http://localhost:8983/solr/techproducts/select?q=popularity:(1 OR
> > 7)&rows=100&fl=price,scale(sum(price,query($q)), 0, 1)
> >
> > {
> >   "responseHeader":{
> >     "status":0,
> >     "QTime":1,
> >     "params":{
> >       "q":"popularity:(1 OR 7)",
> >       "fl":"price,scale(sum(price,query($q)), 0, 1)",
> >       "rows":"100"}},
> >   "response":{"numFound":6,"start":0,"numFoundExact":true,"docs":[
> >       {
> >         "price":74.99,
> >         "scale(sum(price,query($q)), 0, 1)":0.099437736},
> >       {
> >         "price":19.95,
> >         "scale(sum(price,query($q)), 0, 1)":0.013234352},
> >       {
> >         "price":11.5,
> >         "scale(sum(price,query($q)), 0, 1)":0.0},
> >       {
> >         "price":329.95,
> >         "scale(sum(price,query($q)), 0, 1)":0.49875492},
> >       {
> >         "price":479.95,
> >         "scale(sum(price,query($q)), 0, 1)":0.7336842},
> >       {
> >         "price":649.99,
> >         "scale(sum(price,query($q)), 0, 1)":1.0}]
> >   }}
> >
> > but moving the filter in fq:
> >
> >
> >
> http://localhost:8983/solr/techproducts/select?q=*:*&fq=popularity:(1%20OR%207)&rows=100&fl=price,scale(sum(price,query($q)),%200,%201)
> >
> > {
> >   "responseHeader":{
> >     "status":0,
> >     "QTime":8,
> >     "params":{
> >       "q":"*:*",
> >       "fl":"price,scale(sum(price,query($q)), 0, 1)",
> >       "fq":"popularity:(1 OR 7)",
> >       "rows":"100"}},
> >   "response":{"numFound":6,"start":0,"numFoundExact":true,"docs":[
> >       {
> >         "price":74.99,
> >         "scale(sum(price,query($q)), 0, 1)":0.034101862},
> >       {
> >         "price":19.95,
> >         "scale(sum(price,query($q)), 0, 1)":0.009072306},
> >       {
> >         "price":11.5,
> >         "scale(sum(price,query($q)), 0, 1)":0.0052296496},
> >       {
> >         "price":329.95,
> >         "scale(sum(price,query($q)), 0, 1)":0.15004548},
> >       {
> >         "price":479.95,
> >         "scale(sum(price,query($q)), 0, 1)":0.2182583},
> >       {
> >         "price":649.99,
> >         "scale(sum(price,query($q)), 0, 1)":0.29558435}]
> >   }}
> >
> >
> > On the other hand, I was thinking of implementing a custom scale function
> > that by default works only on the current result set and not on the
> entire
> > collection.
> >
> > Any suggestions on how to solve this problem?
> >
> > Best regards,
> > Vincenzo
> >
> >
> > --
> > Vincenzo D'Amore
> >
>
>
> --
> Sincerely yours
> Mikhail Khludnev
>


-- 
Vincenzo D'Amore

Reply via email to