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 "Sowmya V.B." <vb...@gmail.com> on 2011/06/09 17:10:06 UTC

Boosting a document at query time, based on a field value/range

Hi All

I have joined the group only today..and began working with lucene only
recently.

My problem: I want to boost the ranking of certain documents, based on the
values of certain fields.

For example, if the field has  a range of values from 0 to 100 and the user
chooses something like 20 to 30, as an option, along with the query; I want
the documents which satisfy that condition (The field value being between 20
and 30) to get a boost during ranking.

Is there a way to do that in Lucene? I could not find an understandable
explanation in the past mails about this. Hence, starting a fresh thread.

Sowmya.

-- 
Sowmya V.B.
----------------------------------------------------
Losing optimism is blasphemy!
http://vbsowmya.wordpress.com
----------------------------------------------------

Re: Boosting a document at query time, based on a field value/range

Posted by Erick Erickson <er...@gmail.com>.
I take it from this that you want documents with values #outside# 20-30
to still be found? In that case you can do something like add a clause like:

OR field:[20 TO 30]^10

or similar.

Best
Erick

BTW, is there a reason you decided not to use Solr? In many ways it's
easier than straight Lucene....

On Thu, Jun 9, 2011 at 11:10 AM, Sowmya V.B. <vb...@gmail.com> wrote:
> Hi All
>
> I have joined the group only today..and began working with lucene only
> recently.
>
> My problem: I want to boost the ranking of certain documents, based on the
> values of certain fields.
>
> For example, if the field has  a range of values from 0 to 100 and the user
> chooses something like 20 to 30, as an option, along with the query; I want
> the documents which satisfy that condition (The field value being between 20
> and 30) to get a boost during ranking.
>
> Is there a way to do that in Lucene? I could not find an understandable
> explanation in the past mails about this. Hence, starting a fresh thread.
>
> Sowmya.
>
> --
> Sowmya V.B.
> ----------------------------------------------------
> Losing optimism is blasphemy!
> http://vbsowmya.wordpress.com
> ----------------------------------------------------
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Boosting a document at query time, based on a field value/range

Posted by Elmer <ev...@gmail.com>.
Hmm, something went wrong. My mail client swapped dates or displayed
your initial question as new :? Threading fail ;)
Sorry for this :)

On Wed, 2011-06-15 at 12:28 +0200, Elmer wrote:
> Let's try again ;)
> 
> If I understand you correctly, you want the returned results to include
> all documents matching some query, also documents that not satisfy the
> specified range ("like 20 to 30"), but results that satisfy this range
> should appear higher in the list.
> 
> If so, first you have to find out how you can build a range query.
> Enough documentation on that. This results in a RangeQuery, let's call
> it R.
> I assume that the user can enter its search query (words) in another
> field. For this you create another query (for example by using the
> QueryParser), let's call this one Q. 
> Now you have 2 queries (Q and R) which needs to be combined in a Boolean
> query, so you get a boolean query: Q OR R
> This can be done by specifying Q as boolean 'should' clause and R as
> boolean 'should' clause. The BooleanQuery is the one to be used, and
> documents matching the entered range will appear higher, because it
> matches both clauses, and docs matching Q, but are outside that range
> only match the first clause.
> 
> Br,
> Elmer
> 
> 
> On Thu, 2011-06-09 at 17:10 +0200, Sowmya V.B. wrote:
> > Hi All
> > 
> > I have joined the group only today..and began working with lucene only
> > recently.
> > 
> > My problem: I want to boost the ranking of certain documents, based on the
> > values of certain fields.
> > 
> > For example, if the field has  a range of values from 0 to 100 and the user
> > chooses something like 20 to 30, as an option, along with the query; I want
> > the documents which satisfy that condition (The field value being between 20
> > and 30) to get a boost during ranking.
> > 
> > Is there a way to do that in Lucene? I could not find an understandable
> > explanation in the past mails about this. Hence, starting a fresh thread.
> > 
> > Sowmya.
> > 
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Boosting a document at query time, based on a field value/range

Posted by Elmer <ev...@gmail.com>.
Let's try again ;)

If I understand you correctly, you want the returned results to include
all documents matching some query, also documents that not satisfy the
specified range ("like 20 to 30"), but results that satisfy this range
should appear higher in the list.

If so, first you have to find out how you can build a range query.
Enough documentation on that. This results in a RangeQuery, let's call
it R.
I assume that the user can enter its search query (words) in another
field. For this you create another query (for example by using the
QueryParser), let's call this one Q. 
Now you have 2 queries (Q and R) which needs to be combined in a Boolean
query, so you get a boolean query: Q OR R
This can be done by specifying Q as boolean 'should' clause and R as
boolean 'should' clause. The BooleanQuery is the one to be used, and
documents matching the entered range will appear higher, because it
matches both clauses, and docs matching Q, but are outside that range
only match the first clause.

Br,
Elmer


On Thu, 2011-06-09 at 17:10 +0200, Sowmya V.B. wrote:
> Hi All
> 
> I have joined the group only today..and began working with lucene only
> recently.
> 
> My problem: I want to boost the ranking of certain documents, based on the
> values of certain fields.
> 
> For example, if the field has  a range of values from 0 to 100 and the user
> chooses something like 20 to 30, as an option, along with the query; I want
> the documents which satisfy that condition (The field value being between 20
> and 30) to get a boost during ranking.
> 
> Is there a way to do that in Lucene? I could not find an understandable
> explanation in the past mails about this. Hence, starting a fresh thread.
> 
> Sowmya.
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Boosting a document at query time, based on a field value/range

Posted by Toke Eskildsen <te...@statsbiblioteket.dk>.
On Fri, 2011-06-10 at 10:38 +0200, Sowmya V.B. wrote:
> I am looking for a possibility of boosting a given document at query-time,
> based on the values of a particular field : instead of plainly sorting the
> normal lucene results based on this field.

I think you misunderstand Eric's answer, as his suggestion does exactly
what you ask for. Have you tried the "OR *field*:[20 TO 30]^10" method?


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: Boosting a document at query time, based on a field value/range

Posted by Uwe Schindler <uw...@thetaphi.de>.
Query q = NumericRangeQuery.newIntRange(...) or Query q = new TermRangeQuery(....)
(depending on your field type)

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de


> -----Original Message-----
> From: Sowmya V.B. [mailto:vbsowmya@gmail.com]
> Sent: Wednesday, June 15, 2011 11:22 AM
> To: java-user@lucene.apache.org
> Subject: Re: Boosting a document at query time, based on a field value/range
> 
> Hi
> 
> I am not getting the replies to my inbox ...hence the delay in responding.
> 
> >>I think you misunderstand Eric's answer, as his suggestion does
> >>exactly
> what you ask for. Have you tried the "OR **field**:[20 TO 30]^10" method?
> 
> Well, my question is partly answered with this clarification. But, I am still
> wondering how to do that programmatically.
> the (20-30) range is not a fixed range. Its chosen by the user. It can as well be
> (12-34) too. I am not able to figure out if there is any function in the searcher
> classs, which will enable me give these specifications ...something like... a
> setboost(), which exists during index time.
> 
> S.
> 
> On Fri, Jun 10, 2011 at 10:38 AM, Sowmya V.B. <vb...@gmail.com>
> wrote:
> 
> > Hi Erick
> >
> > Thanks for the response.
> >
> > I would want the documents with values within #20-30# be ranked above
> > the documents with some other values.
> > Well, since there might be a case where there are no documents in that
> > range, I would also prefer to have other documents listed too,
> > somewhere lower down the rankings.
> >
> > Also, I don't want to do a simple sort on the results what lucene
> > gives, with its own ranking function.
> > I am looking for a possibility of boosting a given document at
> > query-time, based on the values of a particular field : instead of
> > plainly sorting the normal lucene results based on this field.
> > Is that possible, without going in to the scoring function?
> >
> > Sowmya.
> >
> > *************
> > I take it from this that you want documents with values #outside#
> > 20-30 to still be found? In that case you can do something like add a
> > clause
> > like:
> >
> > OR *field*:[20 TO 30]^10
> >
> > or similar.
> >
> > Best
> > Erick
> >
> > On Thu, Jun 9, 2011 at 5:10 PM, Sowmya V.B. <vb...@gmail.com>
> wrote:
> >
> >> Hi All
> >>
> >> I have joined the group only today..and began working with lucene
> >> only recently.
> >>
> >> My problem: I want to boost the ranking of certain documents, based
> >> on the values of certain fields.
> >>
> >> For example, if the field has  a range of values from 0 to 100 and
> >> the user chooses something like 20 to 30, as an option, along with
> >> the query; I want the documents which satisfy that condition (The
> >> field value being between 20 and 30) to get a boost during ranking.
> >>
> >> Is there a way to do that in Lucene? I could not find an
> >> understandable explanation in the past mails about this. Hence, starting a
> fresh thread.
> >>
> >> Sowmya.
> >>
> >> --
> >> Sowmya V.B.
> >> ----------------------------------------------------
> >> Losing optimism is blasphemy!
> >> http://vbsowmya.wordpress.com
> >> ----------------------------------------------------
> >>
> >
> >
> >
> > --
> > Sowmya V.B.
> > ----------------------------------------------------
> > Losing optimism is blasphemy!
> > http://vbsowmya.wordpress.com
> > ----------------------------------------------------
> >
> 
> 
> 
> --
> Sowmya V.B.
> ----------------------------------------------------
> Losing optimism is blasphemy!
> http://vbsowmya.wordpress.com
> ----------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Boosting a document at query time, based on a field value/range

Posted by "Sowmya V.B." <vb...@gmail.com>.
Hi Elmer

Thanks for the reply.
I now tried giving a NumericRangeQuery.

Something like:
Query qq = NumericRangeQuery.newDoubleRange(field, frompercent, topercent,
true, true);
(As suggested in
http://lucene.apache.org/java/3_0_3/api/core/org/apache/lucene/search/NumericRangeQuery.html
)

However, though I dont get any compilation errors, I get a runtime error.
Here is the stack trace:

java.lang.NoSuchMethodError:
org.apache.lucene.util.StringHelper.intern(Ljava/lang/String;)Ljava/lang/String;

org.apache.lucene.search.NumericRangeQuery.<init>(NumericRangeQuery.java:161)

org.apache.lucene.search.NumericRangeQuery.newDoubleRange(NumericRangeQuery.java:259)


-Firstly, I don't understand the error :) So, I don't know what to do about
it.

S.

*********************

Let's try again ;)

If I understand you correctly, you want the returned results to include
all documents matching some query, also documents that not satisfy the
specified range ("like 20 to 30"), but results that satisfy this range
should appear higher in the list.

If so, first you have to find out how you can build a range query.
Enough documentation on that. This results in a RangeQuery, let's call
it R.
I assume that the user can enter its search query (words) in another
field. For this you create another query (for example by using the
QueryParser), let's call this one Q.
Now you have 2 queries (Q and R) which needs to be combined in a Boolean
query, so you get a boolean query: Q OR R
This can be done by specifying Q as boolean 'should' clause and R as
boolean 'should' clause. The BooleanQuery is the one to be used, and
documents matching the entered range will appear higher, because it
matches both clauses, and docs matching Q, but are outside that range
only match the first clause.

Br,
Elmer



On Wed, Jun 15, 2011 at 5:43 PM, Sowmya V.B. <vb...@gmail.com> wrote:

> Hi
>
> Thanks for the tip.
>
> I tried what you suggested. But, I get the same results as filtering the
> results on the range of values of a given field, but with different scores
> now.
>
> 1) Here is an example query I gave to Query parser:
>
> newtextQuery = textQuery + "  OR " +  field +":[" + frompercent+ " TO " +
> topercent + "]^" + myBoost;
> (Where textQuery is what the user gave, field, frompercent, topercent,
> myboost : are the variables in the code)
>
> A Lucene query for this was something like:
> Query New: ((text:space title:space text.stem:space) field4:[1.0 TO
> 37.0]^10.0)
>
> 2) Here is what I did when I used a filter:
> -used a longtrierangefilter, to filter results based on the range obtained
> by "frompercent" to "topercent", for the same query
>
> Basically, the results for both the methods are the same ranked documents,
> albeit with different scores.
>
> Am I missing something here??
>
>
>
> -----------------------
> The boost is something you do with your query, before it is issued to
> the searcher.
>
> If you use the query parser, you can provide the *additional* query
> parameters by concatenating them to the standard user query:
> String fullQuery = userQuery
>   + " OR myrange:[" + from + " TO " + to + "30]^" + myBoost;
>
> If you build your Query by code, you can use ConstantScoreRangeQuery or
> RangeQuery for the range part, where you can call setBoost(float).
>
> - Toke Eskildsen
>
>
> On Wed, Jun 15, 2011 at 11:22 AM, Sowmya V.B. <vb...@gmail.com> wrote:
>
>> Hi
>>
>> I am not getting the replies to my inbox ...hence the delay in responding.
>>
>> >>I think you misunderstand Eric's answer, as his suggestion does exactly
>>
>> what you ask for. Have you tried the "OR **field**:[20 TO 30]^10" method?
>>
>>
>> Well, my question is partly answered with this clarification. But, I am
>> still wondering how to do that programmatically.
>> the (20-30) range is not a fixed range. Its chosen by the user. It can as
>> well be (12-34) too. I am not able to figure out if there is any function in
>> the searcher classs, which will enable me give these specifications
>> ...something like... a setboost(), which exists during index time.
>>
>> S.
>>
>> On Fri, Jun 10, 2011 at 10:38 AM, Sowmya V.B. <vb...@gmail.com> wrote:
>>
>>> Hi Erick
>>>
>>> Thanks for the response.
>>>
>>> I would want the documents with values within #20-30# be ranked above the
>>> documents with some other values.
>>> Well, since there might be a case where there are no documents in that
>>> range, I would also prefer to have other documents listed too, somewhere
>>> lower down the rankings.
>>>
>>> Also, I don't want to do a simple sort on the results what lucene gives,
>>> with its own ranking function.
>>> I am looking for a possibility of boosting a given document at
>>> query-time, based on the values of a particular field : instead of plainly
>>> sorting the normal lucene results based on this field.
>>> Is that possible, without going in to the scoring function?
>>>
>>> Sowmya.
>>>
>>> *************
>>> I take it from this that you want documents with values #outside# 20-30
>>> to still be found? In that case you can do something like add a clause
>>> like:
>>>
>>> OR *field*:[20 TO 30]^10
>>>
>>> or similar.
>>>
>>> Best
>>> Erick
>>>
>>> On Thu, Jun 9, 2011 at 5:10 PM, Sowmya V.B. <vb...@gmail.com> wrote:
>>>
>>>> Hi All
>>>>
>>>> I have joined the group only today..and began working with lucene only
>>>> recently.
>>>>
>>>> My problem: I want to boost the ranking of certain documents, based on
>>>> the values of certain fields.
>>>>
>>>> For example, if the field has  a range of values from 0 to 100 and the
>>>> user chooses something like 20 to 30, as an option, along with the query; I
>>>> want the documents which satisfy that condition (The field value being
>>>> between 20 and 30) to get a boost during ranking.
>>>>
>>>> Is there a way to do that in Lucene? I could not find an understandable
>>>> explanation in the past mails about this. Hence, starting a fresh thread.
>>>>
>>>> Sowmya.
>>>>
>>>> --
>>>> Sowmya V.B.
>>>> ----------------------------------------------------
>>>> Losing optimism is blasphemy!
>>>> http://vbsowmya.wordpress.com
>>>> ----------------------------------------------------
>>>>
>>>
>>>
>>>
>>> --
>>> Sowmya V.B.
>>> ----------------------------------------------------
>>> Losing optimism is blasphemy!
>>> http://vbsowmya.wordpress.com
>>> ----------------------------------------------------
>>>
>>
>>
>>
>> --
>> Sowmya V.B.
>> ----------------------------------------------------
>> Losing optimism is blasphemy!
>> http://vbsowmya.wordpress.com
>> ----------------------------------------------------
>>
>
>
>
> --
> Sowmya V.B.
> ----------------------------------------------------
> Losing optimism is blasphemy!
> http://vbsowmya.wordpress.com
> ----------------------------------------------------
>



-- 
Sowmya V.B.
----------------------------------------------------
Losing optimism is blasphemy!
http://vbsowmya.wordpress.com
----------------------------------------------------

Re: Boosting a document at query time, based on a field value/range

Posted by Ian Lea <ia...@gmail.com>.
In your examples the queries are essentially the same, so getting the
same results is expected, and getting different scores is also
expected since you are boosting in the first and not the second, and
the second is using a filter which doesn't contribute to scoring.

You'll need to be careful of your range values: 1.0 TO 37.0 may not do
what you want since it will be using a string comparison. Unless you
are using NumericFields in which case you'll need NumericRangeQuery.

It appears that your original question has been answered.  I suggest
you take a step back and work through the problem again, reading the
earlier answers, and experiment with queries like

text:whatever
text:whatever OR percent:[01 TO 30]
text:whatever OR percent:[01 TO 30]^10

or using NumericRangeQuery if that is the way you go - generally
recommended as is quicker and avoids string comparison issues.
Experimenting with different boost values can also be worthwhile.


--
Ian.

On Wed, Jun 15, 2011 at 4:43 PM, Sowmya V.B. <vb...@gmail.com> wrote:
> Hi
>
> Thanks for the tip.
>
> I tried what you suggested. But, I get the same results as filtering the
> results on the range of values of a given field, but with different scores
> now.
>
> 1) Here is an example query I gave to Query parser:
>
> newtextQuery = textQuery + "  OR " +  field +":[" + frompercent+ " TO " +
> topercent + "]^" + myBoost;
> (Where textQuery is what the user gave, field, frompercent, topercent,
> myboost : are the variables in the code)
>
> A Lucene query for this was something like:
> Query New: ((text:space title:space text.stem:space) field4:[1.0 TO
> 37.0]^10.0)
>
> 2) Here is what I did when I used a filter:
> -used a longtrierangefilter, to filter results based on the range obtained
> by "frompercent" to "topercent", for the same query
>
> Basically, the results for both the methods are the same ranked documents,
> albeit with different scores.
>
> Am I missing something here??
>
>
>
> -----------------------
> The boost is something you do with your query, before it is issued to
> the searcher.
>
> If you use the query parser, you can provide the *additional* query
> parameters by concatenating them to the standard user query:
> String fullQuery = userQuery
>  + " OR myrange:[" + from + " TO " + to + "30]^" + myBoost;
>
> If you build your Query by code, you can use ConstantScoreRangeQuery or
> RangeQuery for the range part, where you can call setBoost(float).
>
> - Toke Eskildsen
>
>
> On Wed, Jun 15, 2011 at 11:22 AM, Sowmya V.B. <vb...@gmail.com> wrote:
>
>> Hi
>>
>> I am not getting the replies to my inbox ...hence the delay in responding.
>>
>> >>I think you misunderstand Eric's answer, as his suggestion does exactly
>> what you ask for. Have you tried the "OR **field**:[20 TO 30]^10" method?
>>
>> Well, my question is partly answered with this clarification. But, I am
>> still wondering how to do that programmatically.
>> the (20-30) range is not a fixed range. Its chosen by the user. It can as
>> well be (12-34) too. I am not able to figure out if there is any function in
>> the searcher classs, which will enable me give these specifications
>> ...something like... a setboost(), which exists during index time.
>>
>> S.
>>
>> On Fri, Jun 10, 2011 at 10:38 AM, Sowmya V.B. <vb...@gmail.com> wrote:
>>
>>> Hi Erick
>>>
>>> Thanks for the response.
>>>
>>> I would want the documents with values within #20-30# be ranked above the
>>> documents with some other values.
>>> Well, since there might be a case where there are no documents in that
>>> range, I would also prefer to have other documents listed too, somewhere
>>> lower down the rankings.
>>>
>>> Also, I don't want to do a simple sort on the results what lucene gives,
>>> with its own ranking function.
>>> I am looking for a possibility of boosting a given document at query-time,
>>> based on the values of a particular field : instead of plainly sorting the
>>> normal lucene results based on this field.
>>> Is that possible, without going in to the scoring function?
>>>
>>> Sowmya.
>>>
>>> *************
>>> I take it from this that you want documents with values #outside# 20-30
>>> to still be found? In that case you can do something like add a clause
>>> like:
>>>
>>> OR *field*:[20 TO 30]^10
>>>
>>> or similar.
>>>
>>> Best
>>> Erick
>>>
>>> On Thu, Jun 9, 2011 at 5:10 PM, Sowmya V.B. <vb...@gmail.com> wrote:
>>>
>>>> Hi All
>>>>
>>>> I have joined the group only today..and began working with lucene only
>>>> recently.
>>>>
>>>> My problem: I want to boost the ranking of certain documents, based on
>>>> the values of certain fields.
>>>>
>>>> For example, if the field has  a range of values from 0 to 100 and the
>>>> user chooses something like 20 to 30, as an option, along with the query; I
>>>> want the documents which satisfy that condition (The field value being
>>>> between 20 and 30) to get a boost during ranking.
>>>>
>>>> Is there a way to do that in Lucene? I could not find an understandable
>>>> explanation in the past mails about this. Hence, starting a fresh thread.
>>>>
>>>> Sowmya.
>>>>
>>>> --
>>>> Sowmya V.B.
>>>> ----------------------------------------------------
>>>> Losing optimism is blasphemy!
>>>> http://vbsowmya.wordpress.com
>>>> ----------------------------------------------------
>>>>
>>>
>>>
>>>
>>> --
>>> Sowmya V.B.
>>> ----------------------------------------------------
>>> Losing optimism is blasphemy!
>>> http://vbsowmya.wordpress.com
>>> ----------------------------------------------------
>>>
>>
>>
>>
>> --
>> Sowmya V.B.
>> ----------------------------------------------------
>> Losing optimism is blasphemy!
>> http://vbsowmya.wordpress.com
>> ----------------------------------------------------
>>
>
>
>
> --
> Sowmya V.B.
> ----------------------------------------------------
> Losing optimism is blasphemy!
> http://vbsowmya.wordpress.com
> ----------------------------------------------------
>

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Boosting a document at query time, based on a field value/range

Posted by "Sowmya V.B." <vb...@gmail.com>.
Hi

Thanks for the tip.

I tried what you suggested. But, I get the same results as filtering the
results on the range of values of a given field, but with different scores
now.

1) Here is an example query I gave to Query parser:

newtextQuery = textQuery + "  OR " +  field +":[" + frompercent+ " TO " +
topercent + "]^" + myBoost;
(Where textQuery is what the user gave, field, frompercent, topercent,
myboost : are the variables in the code)

A Lucene query for this was something like:
Query New: ((text:space title:space text.stem:space) field4:[1.0 TO
37.0]^10.0)

2) Here is what I did when I used a filter:
-used a longtrierangefilter, to filter results based on the range obtained
by "frompercent" to "topercent", for the same query

Basically, the results for both the methods are the same ranked documents,
albeit with different scores.

Am I missing something here??



-----------------------
The boost is something you do with your query, before it is issued to
the searcher.

If you use the query parser, you can provide the *additional* query
parameters by concatenating them to the standard user query:
String fullQuery = userQuery
  + " OR myrange:[" + from + " TO " + to + "30]^" + myBoost;

If you build your Query by code, you can use ConstantScoreRangeQuery or
RangeQuery for the range part, where you can call setBoost(float).

- Toke Eskildsen


On Wed, Jun 15, 2011 at 11:22 AM, Sowmya V.B. <vb...@gmail.com> wrote:

> Hi
>
> I am not getting the replies to my inbox ...hence the delay in responding.
>
> >>I think you misunderstand Eric's answer, as his suggestion does exactly
> what you ask for. Have you tried the "OR **field**:[20 TO 30]^10" method?
>
> Well, my question is partly answered with this clarification. But, I am
> still wondering how to do that programmatically.
> the (20-30) range is not a fixed range. Its chosen by the user. It can as
> well be (12-34) too. I am not able to figure out if there is any function in
> the searcher classs, which will enable me give these specifications
> ...something like... a setboost(), which exists during index time.
>
> S.
>
> On Fri, Jun 10, 2011 at 10:38 AM, Sowmya V.B. <vb...@gmail.com> wrote:
>
>> Hi Erick
>>
>> Thanks for the response.
>>
>> I would want the documents with values within #20-30# be ranked above the
>> documents with some other values.
>> Well, since there might be a case where there are no documents in that
>> range, I would also prefer to have other documents listed too, somewhere
>> lower down the rankings.
>>
>> Also, I don't want to do a simple sort on the results what lucene gives,
>> with its own ranking function.
>> I am looking for a possibility of boosting a given document at query-time,
>> based on the values of a particular field : instead of plainly sorting the
>> normal lucene results based on this field.
>> Is that possible, without going in to the scoring function?
>>
>> Sowmya.
>>
>> *************
>> I take it from this that you want documents with values #outside# 20-30
>> to still be found? In that case you can do something like add a clause
>> like:
>>
>> OR *field*:[20 TO 30]^10
>>
>> or similar.
>>
>> Best
>> Erick
>>
>> On Thu, Jun 9, 2011 at 5:10 PM, Sowmya V.B. <vb...@gmail.com> wrote:
>>
>>> Hi All
>>>
>>> I have joined the group only today..and began working with lucene only
>>> recently.
>>>
>>> My problem: I want to boost the ranking of certain documents, based on
>>> the values of certain fields.
>>>
>>> For example, if the field has  a range of values from 0 to 100 and the
>>> user chooses something like 20 to 30, as an option, along with the query; I
>>> want the documents which satisfy that condition (The field value being
>>> between 20 and 30) to get a boost during ranking.
>>>
>>> Is there a way to do that in Lucene? I could not find an understandable
>>> explanation in the past mails about this. Hence, starting a fresh thread.
>>>
>>> Sowmya.
>>>
>>> --
>>> Sowmya V.B.
>>> ----------------------------------------------------
>>> Losing optimism is blasphemy!
>>> http://vbsowmya.wordpress.com
>>> ----------------------------------------------------
>>>
>>
>>
>>
>> --
>> Sowmya V.B.
>> ----------------------------------------------------
>> Losing optimism is blasphemy!
>> http://vbsowmya.wordpress.com
>> ----------------------------------------------------
>>
>
>
>
> --
> Sowmya V.B.
> ----------------------------------------------------
> Losing optimism is blasphemy!
> http://vbsowmya.wordpress.com
> ----------------------------------------------------
>



-- 
Sowmya V.B.
----------------------------------------------------
Losing optimism is blasphemy!
http://vbsowmya.wordpress.com
----------------------------------------------------

Re: Boosting a document at query time, based on a field value/range

Posted by Toke Eskildsen <te...@statsbiblioteket.dk>.
On Wed, 2011-06-15 at 11:22 +0200, Sowmya V.B. wrote:
> [...] "OR **field**:[20 TO 30]^10"
> 
> Well, my question is partly answered with this clarification. But, I am
> still wondering how to do that programmatically.
> the (20-30) range is not a fixed range. Its chosen by the user. It can as
> well be (12-34) too. I am not able to figure out if there is any function in
> the searcher classs, which will enable me give these specifications
> ...something like... a setboost(), which exists during index time.

The boost is something you do with your query, before it is issued to
the searcher.

If you use the query parser, you can provide the additional query
parameters by concatenating them to the standard user query:
String fullQuery = userQuery 
  + " OR myrange:[" + from + " TO " + to + "30]^" + myBoost;

If you build your Query by code, you can use ConstantScoreRangeQuery or
RangeQuery for the range part, where you can call setBoost(float).

- Toke Eskildsen


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Boosting a document at query time, based on a field value/range

Posted by "Sowmya V.B." <vb...@gmail.com>.
Hi

I am not getting the replies to my inbox ...hence the delay in responding.

>>I think you misunderstand Eric's answer, as his suggestion does exactly
what you ask for. Have you tried the "OR **field**:[20 TO 30]^10" method?

Well, my question is partly answered with this clarification. But, I am
still wondering how to do that programmatically.
the (20-30) range is not a fixed range. Its chosen by the user. It can as
well be (12-34) too. I am not able to figure out if there is any function in
the searcher classs, which will enable me give these specifications
...something like... a setboost(), which exists during index time.

S.

On Fri, Jun 10, 2011 at 10:38 AM, Sowmya V.B. <vb...@gmail.com> wrote:

> Hi Erick
>
> Thanks for the response.
>
> I would want the documents with values within #20-30# be ranked above the
> documents with some other values.
> Well, since there might be a case where there are no documents in that
> range, I would also prefer to have other documents listed too, somewhere
> lower down the rankings.
>
> Also, I don't want to do a simple sort on the results what lucene gives,
> with its own ranking function.
> I am looking for a possibility of boosting a given document at query-time,
> based on the values of a particular field : instead of plainly sorting the
> normal lucene results based on this field.
> Is that possible, without going in to the scoring function?
>
> Sowmya.
>
> *************
> I take it from this that you want documents with values #outside# 20-30
> to still be found? In that case you can do something like add a clause
> like:
>
> OR *field*:[20 TO 30]^10
>
> or similar.
>
> Best
> Erick
>
> On Thu, Jun 9, 2011 at 5:10 PM, Sowmya V.B. <vb...@gmail.com> wrote:
>
>> Hi All
>>
>> I have joined the group only today..and began working with lucene only
>> recently.
>>
>> My problem: I want to boost the ranking of certain documents, based on the
>> values of certain fields.
>>
>> For example, if the field has  a range of values from 0 to 100 and the
>> user chooses something like 20 to 30, as an option, along with the query; I
>> want the documents which satisfy that condition (The field value being
>> between 20 and 30) to get a boost during ranking.
>>
>> Is there a way to do that in Lucene? I could not find an understandable
>> explanation in the past mails about this. Hence, starting a fresh thread.
>>
>> Sowmya.
>>
>> --
>> Sowmya V.B.
>> ----------------------------------------------------
>> Losing optimism is blasphemy!
>> http://vbsowmya.wordpress.com
>> ----------------------------------------------------
>>
>
>
>
> --
> Sowmya V.B.
> ----------------------------------------------------
> Losing optimism is blasphemy!
> http://vbsowmya.wordpress.com
> ----------------------------------------------------
>



-- 
Sowmya V.B.
----------------------------------------------------
Losing optimism is blasphemy!
http://vbsowmya.wordpress.com
----------------------------------------------------

Re: Boosting a document at query time, based on a field value/range

Posted by "Sowmya V.B." <vb...@gmail.com>.
Hi Erick

Thanks for the response.

I would want the documents with values within #20-30# be ranked above the
documents with some other values.
Well, since there might be a case where there are no documents in that
range, I would also prefer to have other documents listed too, somewhere
lower down the rankings.

Also, I don't want to do a simple sort on the results what lucene gives,
with its own ranking function.
I am looking for a possibility of boosting a given document at query-time,
based on the values of a particular field : instead of plainly sorting the
normal lucene results based on this field.
Is that possible, without going in to the scoring function?

Sowmya.

*************
I take it from this that you want documents with values #outside# 20-30
to still be found? In that case you can do something like add a clause like:


OR *field*:[20 TO 30]^10

or similar.

Best
Erick

On Thu, Jun 9, 2011 at 5:10 PM, Sowmya V.B. <vb...@gmail.com> wrote:

> Hi All
>
> I have joined the group only today..and began working with lucene only
> recently.
>
> My problem: I want to boost the ranking of certain documents, based on the
> values of certain fields.
>
> For example, if the field has  a range of values from 0 to 100 and the user
> chooses something like 20 to 30, as an option, along with the query; I want
> the documents which satisfy that condition (The field value being between 20
> and 30) to get a boost during ranking.
>
> Is there a way to do that in Lucene? I could not find an understandable
> explanation in the past mails about this. Hence, starting a fresh thread.
>
> Sowmya.
>
> --
> Sowmya V.B.
> ----------------------------------------------------
> Losing optimism is blasphemy!
> http://vbsowmya.wordpress.com
> ----------------------------------------------------
>



-- 
Sowmya V.B.
----------------------------------------------------
Losing optimism is blasphemy!
http://vbsowmya.wordpress.com
----------------------------------------------------