Use custom score in ConstantScoreQuery

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Use custom score in ConstantScoreQuery

Stamatis Zampetakis
Hi all,

Currently ConstantScoreQuery [1] returns a constant score equal to 1 for
every document that matches the query.

I would like to use the ConstantScoreQuery but with a different score value
that I can pass explicitly (via the constructor for instance).

This change may also benefit some other parts of Lucene where a
ConstantScoreQuery is wrapped around a BoostQuery simply for returning a
score of zero [2][3].

Does this change make sense? Shall I create a JIRA for it?

Best,
Stamatis

[1]
https://github.com/apache/lucene-solr/blob/master/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
[2]
https://github.com/apache/lucene-solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java#L253
[3]
https://github.com/apache/lucene-solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/java/org/apache/lucene/search/BoostQuery.java#L97
Reply | Threaded
Open this post in threaded view
|

Re: Use custom score in ConstantScoreQuery

Stamatis Zampetakis
Small reminder. Any input on this?

Thanks,
Stamatis

On Mon, Dec 2, 2019 at 12:10 PM Stamatis Zampetakis <[hidden email]>
wrote:

> Hi all,
>
> Currently ConstantScoreQuery [1] returns a constant score equal to 1 for
> every document that matches the query.
>
> I would like to use the ConstantScoreQuery but with a different score
> value that I can pass explicitly (via the constructor for instance).
>
> This change may also benefit some other parts of Lucene where a
> ConstantScoreQuery is wrapped around a BoostQuery simply for returning a
> score of zero [2][3].
>
> Does this change make sense? Shall I create a JIRA for it?
>
> Best,
> Stamatis
>
> [1]
> https://github.com/apache/lucene-solr/blob/master/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
> [2]
> https://github.com/apache/lucene-solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java#L253
> [3]
> https://github.com/apache/lucene-solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/java/org/apache/lucene/search/BoostQuery.java#L97
>
Reply | Threaded
Open this post in threaded view
|

Re: Use custom score in ConstantScoreQuery

Adrien Grand
Hi Stamatis,

I personally like the current way things work. If we added the ability
to set a custom score on ConstantScoreQuery, then we'd end up with two
ways to do the same thing, which I like to avoid whenever possible.

On Sun, Dec 8, 2019 at 10:07 PM Stamatis Zampetakis <[hidden email]> wrote:

>
> Small reminder. Any input on this?
>
> Thanks,
> Stamatis
>
> On Mon, Dec 2, 2019 at 12:10 PM Stamatis Zampetakis <[hidden email]>
> wrote:
>
> > Hi all,
> >
> > Currently ConstantScoreQuery [1] returns a constant score equal to 1 for
> > every document that matches the query.
> >
> > I would like to use the ConstantScoreQuery but with a different score
> > value that I can pass explicitly (via the constructor for instance).
> >
> > This change may also benefit some other parts of Lucene where a
> > ConstantScoreQuery is wrapped around a BoostQuery simply for returning a
> > score of zero [2][3].
> >
> > Does this change make sense? Shall I create a JIRA for it?
> >
> > Best,
> > Stamatis
> >
> > [1]
> > https://github.com/apache/lucene-solr/blob/master/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
> > [2]
> > https://github.com/apache/lucene-solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java#L253
> > [3]
> > https://github.com/apache/lucene-solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/java/org/apache/lucene/search/BoostQuery.java#L97
> >



--
Adrien

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Use custom score in ConstantScoreQuery

Stamatis Zampetakis
Thanks for you reply Adrien!
Can you clarify what is the second way?
At the moment I haven't found a way (apart from creating my own Query
classes) to say that a query will always return a score of 0.5 for each
document.

On Mon, Dec 9, 2019 at 8:16 AM Adrien Grand <[hidden email]> wrote:

> Hi Stamatis,
>
> I personally like the current way things work. If we added the ability
> to set a custom score on ConstantScoreQuery, then we'd end up with two
> ways to do the same thing, which I like to avoid whenever possible.
>
> On Sun, Dec 8, 2019 at 10:07 PM Stamatis Zampetakis <[hidden email]>
> wrote:
> >
> > Small reminder. Any input on this?
> >
> > Thanks,
> > Stamatis
> >
> > On Mon, Dec 2, 2019 at 12:10 PM Stamatis Zampetakis <[hidden email]>
> > wrote:
> >
> > > Hi all,
> > >
> > > Currently ConstantScoreQuery [1] returns a constant score equal to 1
> for
> > > every document that matches the query.
> > >
> > > I would like to use the ConstantScoreQuery but with a different score
> > > value that I can pass explicitly (via the constructor for instance).
> > >
> > > This change may also benefit some other parts of Lucene where a
> > > ConstantScoreQuery is wrapped around a BoostQuery simply for returning
> a
> > > score of zero [2][3].
> > >
> > > Does this change make sense? Shall I create a JIRA for it?
> > >
> > > Best,
> > > Stamatis
> > >
> > > [1]
> > >
> https://github.com/apache/lucene-solr/blob/master/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
> > > [2]
> > >
> https://github.com/apache/lucene-solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java#L253
> > > [3]
> > >
> https://github.com/apache/lucene-solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/java/org/apache/lucene/search/BoostQuery.java#L97
> > >
>
>
>
> --
> Adrien
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Use custom score in ConstantScoreQuery

Aditya Varun Chadha
By wrapping the constant score query inside a BoostQuery?

That’s how elasticsearch handles boosts on arbitrary queries, for example.

On Mon 9. Dec 2019 at 10:42, Stamatis Zampetakis <[hidden email]> wrote:

> Thanks for you reply Adrien!
> Can you clarify what is the second way?
> At the moment I haven't found a way (apart from creating my own Query
> classes) to say that a query will always return a score of 0.5 for each
> document.
>
> On Mon, Dec 9, 2019 at 8:16 AM Adrien Grand <[hidden email]> wrote:
>
> > Hi Stamatis,
> >
> > I personally like the current way things work. If we added the ability
> > to set a custom score on ConstantScoreQuery, then we'd end up with two
> > ways to do the same thing, which I like to avoid whenever possible.
> >
> > On Sun, Dec 8, 2019 at 10:07 PM Stamatis Zampetakis <[hidden email]>
> > wrote:
> > >
> > > Small reminder. Any input on this?
> > >
> > > Thanks,
> > > Stamatis
> > >
> > > On Mon, Dec 2, 2019 at 12:10 PM Stamatis Zampetakis <[hidden email]
> >
> > > wrote:
> > >
> > > > Hi all,
> > > >
> > > > Currently ConstantScoreQuery [1] returns a constant score equal to 1
> > for
> > > > every document that matches the query.
> > > >
> > > > I would like to use the ConstantScoreQuery but with a different score
> > > > value that I can pass explicitly (via the constructor for instance).
> > > >
> > > > This change may also benefit some other parts of Lucene where a
> > > > ConstantScoreQuery is wrapped around a BoostQuery simply for
> returning
> > a
> > > > score of zero [2][3].
> > > >
> > > > Does this change make sense? Shall I create a JIRA for it?
> > > >
> > > > Best,
> > > > Stamatis
> > > >
> > > > [1]
> > > >
> >
> https://github.com/apache/lucene-solr/blob/master/lucene/core/src/java/org/apache/lucene/search/ConstantScoreQuery.java
> > > > [2]
> > > >
> >
> https://github.com/apache/lucene-solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/java/org/apache/lucene/search/BooleanQuery.java#L253
> > > > [3]
> > > >
> >
> https://github.com/apache/lucene-solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/java/org/apache/lucene/search/BoostQuery.java#L97
> > > >
> >
> >
> >
> > --
> > Adrien
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
--
Aditya Varun Chadha | http://www.adichad.com | +49 (0) 152 25914008 (M)
Reply | Threaded
Open this post in threaded view
|

RE: Use custom score in ConstantScoreQuery

Uwe Schindler
In reply to this post by Stamatis Zampetakis
Hi,

Just add a BoostQuery  with a boost factor of 0.5 around the ConstantScoreQuery. It's just one line more in your code. I don't understand why we would need separate query classes for this.

Uwe

-----
Uwe Schindler
Achterdiek 19, D-28357 Bremen
https://www.thetaphi.de
eMail: [hidden email]

> -----Original Message-----
> From: Stamatis Zampetakis <[hidden email]>
> Sent: Monday, December 9, 2019 10:42 AM
> To: [hidden email]
> Subject: Re: Use custom score in ConstantScoreQuery
>
> Thanks for you reply Adrien!
> Can you clarify what is the second way?
> At the moment I haven't found a way (apart from creating my own Query
> classes) to say that a query will always return a score of 0.5 for each
> document.
>
> On Mon, Dec 9, 2019 at 8:16 AM Adrien Grand <[hidden email]> wrote:
>
> > Hi Stamatis,
> >
> > I personally like the current way things work. If we added the ability
> > to set a custom score on ConstantScoreQuery, then we'd end up with two
> > ways to do the same thing, which I like to avoid whenever possible.
> >
> > On Sun, Dec 8, 2019 at 10:07 PM Stamatis Zampetakis
> <[hidden email]>
> > wrote:
> > >
> > > Small reminder. Any input on this?
> > >
> > > Thanks,
> > > Stamatis
> > >
> > > On Mon, Dec 2, 2019 at 12:10 PM Stamatis Zampetakis
> <[hidden email]>
> > > wrote:
> > >
> > > > Hi all,
> > > >
> > > > Currently ConstantScoreQuery [1] returns a constant score equal to 1
> > for
> > > > every document that matches the query.
> > > >
> > > > I would like to use the ConstantScoreQuery but with a different score
> > > > value that I can pass explicitly (via the constructor for instance).
> > > >
> > > > This change may also benefit some other parts of Lucene where a
> > > > ConstantScoreQuery is wrapped around a BoostQuery simply for
> returning
> > a
> > > > score of zero [2][3].
> > > >
> > > > Does this change make sense? Shall I create a JIRA for it?
> > > >
> > > > Best,
> > > > Stamatis
> > > >
> > > > [1]
> > > >
> > https://github.com/apache/lucene-
> solr/blob/master/lucene/core/src/java/org/apache/lucene/search/Constant
> ScoreQuery.java
> > > > [2]
> > > >
> > https://github.com/apache/lucene-
> solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/ja
> va/org/apache/lucene/search/BooleanQuery.java#L253
> > > > [3]
> > > >
> > https://github.com/apache/lucene-
> solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/ja
> va/org/apache/lucene/search/BoostQuery.java#L97
> > > >
> >
> >
> >
> > --
> > Adrien
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Use custom score in ConstantScoreQuery

Stamatis Zampetakis
Many thanks for the replies.

Intuitively, I was hoping that this could be done with a single query class
especially since ConstantScoreQuery seems to be made for that. I've seen
the pattern of wrapping a BoostQuery around a ConstantScoreQuery but this
seemed to me like a workaround. Anyways, I understand that finally this is
a well adopted pattern so I am not going to insist more on this.

Best,
Stamatis

On Mon, Dec 9, 2019 at 10:50 AM Uwe Schindler <[hidden email]> wrote:

> Hi,
>
> Just add a BoostQuery  with a boost factor of 0.5 around the
> ConstantScoreQuery. It's just one line more in your code. I don't
> understand why we would need separate query classes for this.
>
> Uwe
>
> -----
> Uwe Schindler
> Achterdiek 19, D-28357 Bremen
> https://www.thetaphi.de
> eMail: [hidden email]
>
> > -----Original Message-----
> > From: Stamatis Zampetakis <[hidden email]>
> > Sent: Monday, December 9, 2019 10:42 AM
> > To: [hidden email]
> > Subject: Re: Use custom score in ConstantScoreQuery
> >
> > Thanks for you reply Adrien!
> > Can you clarify what is the second way?
> > At the moment I haven't found a way (apart from creating my own Query
> > classes) to say that a query will always return a score of 0.5 for each
> > document.
> >
> > On Mon, Dec 9, 2019 at 8:16 AM Adrien Grand <[hidden email]> wrote:
> >
> > > Hi Stamatis,
> > >
> > > I personally like the current way things work. If we added the ability
> > > to set a custom score on ConstantScoreQuery, then we'd end up with two
> > > ways to do the same thing, which I like to avoid whenever possible.
> > >
> > > On Sun, Dec 8, 2019 at 10:07 PM Stamatis Zampetakis
> > <[hidden email]>
> > > wrote:
> > > >
> > > > Small reminder. Any input on this?
> > > >
> > > > Thanks,
> > > > Stamatis
> > > >
> > > > On Mon, Dec 2, 2019 at 12:10 PM Stamatis Zampetakis
> > <[hidden email]>
> > > > wrote:
> > > >
> > > > > Hi all,
> > > > >
> > > > > Currently ConstantScoreQuery [1] returns a constant score equal to
> 1
> > > for
> > > > > every document that matches the query.
> > > > >
> > > > > I would like to use the ConstantScoreQuery but with a different
> score
> > > > > value that I can pass explicitly (via the constructor for
> instance).
> > > > >
> > > > > This change may also benefit some other parts of Lucene where a
> > > > > ConstantScoreQuery is wrapped around a BoostQuery simply for
> > returning
> > > a
> > > > > score of zero [2][3].
> > > > >
> > > > > Does this change make sense? Shall I create a JIRA for it?
> > > > >
> > > > > Best,
> > > > > Stamatis
> > > > >
> > > > > [1]
> > > > >
> > > https://github.com/apache/lucene-
> > solr/blob/master/lucene/core/src/java/org/apache/lucene/search/Constant
> > ScoreQuery.java
> > > > > [2]
> > > > >
> > > https://github.com/apache/lucene-
> > solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/ja
> > va/org/apache/lucene/search/BooleanQuery.java#L253
> > > > > [3]
> > > > >
> > > https://github.com/apache/lucene-
> > solr/blob/1d238c844e45f088a942aec14750c186c7a66d92/lucene/core/src/ja
> > va/org/apache/lucene/search/BoostQuery.java#L97
> > > > >
> > >
> > >
> > >
> > > --
> > > Adrien
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>