You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Stamatis Zampetakis <za...@gmail.com> on 2019/12/02 11:10:31 UTC
Use custom score in ConstantScoreQuery
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
Re: Use custom score in ConstantScoreQuery
Posted by Aditya Varun Chadha <ad...@gmail.com>.
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 <za...@gmail.com> 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 <jp...@gmail.com> 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 <za...@gmail.com>
> > wrote:
> > >
> > > Small reminder. Any input on this?
> > >
> > > Thanks,
> > > Stamatis
> > >
> > > On Mon, Dec 2, 2019 at 12:10 PM Stamatis Zampetakis <zabetak@gmail.com
> >
> > > 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: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
>
--
Aditya Varun Chadha | http://www.adichad.com | +49 (0) 152 25914008 (M)
Re: Use custom score in ConstantScoreQuery
Posted by Stamatis Zampetakis <za...@gmail.com>.
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 <uw...@thetaphi.de> 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: uwe@thetaphi.de
>
> > -----Original Message-----
> > From: Stamatis Zampetakis <za...@gmail.com>
> > Sent: Monday, December 9, 2019 10:42 AM
> > To: java-user@lucene.apache.org
> > 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 <jp...@gmail.com> 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
> > <za...@gmail.com>
> > > wrote:
> > > >
> > > > Small reminder. Any input on this?
> > > >
> > > > Thanks,
> > > > Stamatis
> > > >
> > > > On Mon, Dec 2, 2019 at 12:10 PM Stamatis Zampetakis
> > <za...@gmail.com>
> > > > 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: java-user-unsubscribe@lucene.apache.org
> > > For additional commands, e-mail: java-user-help@lucene.apache.org
> > >
> > >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
RE: Use custom score in ConstantScoreQuery
Posted by Uwe Schindler <uw...@thetaphi.de>.
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: uwe@thetaphi.de
> -----Original Message-----
> From: Stamatis Zampetakis <za...@gmail.com>
> Sent: Monday, December 9, 2019 10:42 AM
> To: java-user@lucene.apache.org
> 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 <jp...@gmail.com> 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
> <za...@gmail.com>
> > wrote:
> > >
> > > Small reminder. Any input on this?
> > >
> > > Thanks,
> > > Stamatis
> > >
> > > On Mon, Dec 2, 2019 at 12:10 PM Stamatis Zampetakis
> <za...@gmail.com>
> > > 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: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Use custom score in ConstantScoreQuery
Posted by Stamatis Zampetakis <za...@gmail.com>.
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 <jp...@gmail.com> 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 <za...@gmail.com>
> wrote:
> >
> > Small reminder. Any input on this?
> >
> > Thanks,
> > Stamatis
> >
> > On Mon, Dec 2, 2019 at 12:10 PM Stamatis Zampetakis <za...@gmail.com>
> > 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: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Re: Use custom score in ConstantScoreQuery
Posted by Adrien Grand <jp...@gmail.com>.
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 <za...@gmail.com> wrote:
>
> Small reminder. Any input on this?
>
> Thanks,
> Stamatis
>
> On Mon, Dec 2, 2019 at 12:10 PM Stamatis Zampetakis <za...@gmail.com>
> 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: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Use custom score in ConstantScoreQuery
Posted by Stamatis Zampetakis <za...@gmail.com>.
Small reminder. Any input on this?
Thanks,
Stamatis
On Mon, Dec 2, 2019 at 12:10 PM Stamatis Zampetakis <za...@gmail.com>
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
>