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 Riccardo Daviddi <rd...@gmail.com> on 2005/08/04 13:34:39 UTC

setBoost(float) in org.apache.lucene.document.Field cannot be applied to (double)???

Why I got this error by writing for example:

Field senderNameField = Field.Text("senderName", senderName);
Field subjectField = Field.Text("subject", subject);
subjectField.setBoost(1.2);

as in the manual lucene in action??

1.2 is a double, but the method wants a float?
-- 
Riccardo Daviddi

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


Re: setBoost(float) in org.apache.lucene.document.Field cannot be applied to (double)???

Posted by Riccardo Daviddi <rd...@gmail.com>.
Thx stefan:)

On 8/7/05, Stefan Groschupf <sg...@media-style.com> wrote:
> Hi,
> I run in the same problem some weeks ago as well.
> You can find following in the java doc:
> 
> "Note: this value is not stored directly with the document in the
> index. Documents returned from IndexReader.document(int) and Hits.doc
> (int) may thus not have the same value present as when this field was
> indexed."
> 
> HTH
> Stefan
> 
> 
> Am 07.08.2005 um 19:05 schrieb Riccardo Daviddi:
> 
> > I don't know where I am wrong...
> >
> > I just do this:
> >
> > IndexWriter writer = new IndexWriter(indexDir, new StandardAnalyzer(),
> >                                            !IndexReader.indexExists
> > (indexDir));
> > writer.setUseCompoundFile(true);
> > Document document = new Document();
> > document.add(Field.Keyword("DocId", Integer.toString(docId)));
> > Field f = Field.Text("boostfield", "text");
> > f.setBoost(3.0f);
> > document.add(f);
> > writer.addDocument(document);
> >         writer.optimize();
> >         writer.close();
> >
> > if then i try to get the boost factor of the boostfield
> >
> > System.out.println(IndexReader.open(indexDir).document(0).getField
> > ("boostfield").getBoost());
> >
> > for the only one document indexed I get 1.0 instead of 3.0!
> >
> > where is the error?
> >
> > thx
> >
> > On 8/4/05, Otis Gospodnetic <ot...@yahoo.com> wrote:
> >
> >> Yes. use 1.2f there.  That method accepts floats, not doubles.  That
> >> could be an error in the Lucene book.
> >>
> >> Otis
> >>
> >>
> >> --- Riccardo Daviddi <rd...@gmail.com> wrote:
> >>
> >>
> >>> Why I got this error by writing for example:
> >>>
> >>> Field senderNameField = Field.Text("senderName", senderName);
> >>> Field subjectField = Field.Text("subject", subject);
> >>> subjectField.setBoost(1.2);
> >>>
> >>> as in the manual lucene in action??
> >>>
> >>> 1.2 is a double, but the method wants a float?
> >>> --
> >>> Riccardo Daviddi
> >>>
> >>> --------------------------------------------------------------------
> >>> -
> >>> 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
> >>
> >>
> >>
> >
> >
> > --
> > Riccardo Daviddi
> > University of Siena - Information Engeneering
> > rdaviddi@gmail.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
> >
> 
> ---------------------------------------------------------------
> company:        http://www.media-style.com
> forum:        http://www.text-mining.org
> blog:            http://www.find23.net
> 
> 
> 
> 


-- 
Riccardo Daviddi
University of Siena - Information Engeneering
rdaviddi@gmail.com

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


Re: setBoost(float) in org.apache.lucene.document.Field cannot be applied to (double)???

Posted by Stefan Groschupf <sg...@media-style.com>.
Hi,
I run in the same problem some weeks ago as well.
You can find following in the java doc:

"Note: this value is not stored directly with the document in the  
index. Documents returned from IndexReader.document(int) and Hits.doc 
(int) may thus not have the same value present as when this field was  
indexed."

HTH
Stefan


Am 07.08.2005 um 19:05 schrieb Riccardo Daviddi:

> I don't know where I am wrong...
>
> I just do this:
>
> IndexWriter writer = new IndexWriter(indexDir, new StandardAnalyzer(),
>                                            !IndexReader.indexExists 
> (indexDir));
> writer.setUseCompoundFile(true);
> Document document = new Document();
> document.add(Field.Keyword("DocId", Integer.toString(docId)));
> Field f = Field.Text("boostfield", "text");
> f.setBoost(3.0f);
> document.add(f);
> writer.addDocument(document);
>         writer.optimize();
>         writer.close();
>
> if then i try to get the boost factor of the boostfield
>
> System.out.println(IndexReader.open(indexDir).document(0).getField 
> ("boostfield").getBoost());
>
> for the only one document indexed I get 1.0 instead of 3.0!
>
> where is the error?
>
> thx
>
> On 8/4/05, Otis Gospodnetic <ot...@yahoo.com> wrote:
>
>> Yes. use 1.2f there.  That method accepts floats, not doubles.  That
>> could be an error in the Lucene book.
>>
>> Otis
>>
>>
>> --- Riccardo Daviddi <rd...@gmail.com> wrote:
>>
>>
>>> Why I got this error by writing for example:
>>>
>>> Field senderNameField = Field.Text("senderName", senderName);
>>> Field subjectField = Field.Text("subject", subject);
>>> subjectField.setBoost(1.2);
>>>
>>> as in the manual lucene in action??
>>>
>>> 1.2 is a double, but the method wants a float?
>>> --
>>> Riccardo Daviddi
>>>
>>> -------------------------------------------------------------------- 
>>> -
>>> 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
>>
>>
>>
>
>
> -- 
> Riccardo Daviddi
> University of Siena - Information Engeneering
> rdaviddi@gmail.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
>

---------------------------------------------------------------
company:        http://www.media-style.com
forum:        http://www.text-mining.org
blog:            http://www.find23.net



Re: setBoost(float) in org.apache.lucene.document.Field cannot be applied to (double)???

Posted by Riccardo Daviddi <rd...@gmail.com>.
Ah, ok.

So what I am doing is correct, just the way to see the boost factor
was uncorrect.

sorry if I do newbie questions...

On 8/7/05, Chris Hostetter <ho...@fucit.org> wrote:
> : Field f = Field.Text("boostfield", "text");
> : f.setBoost(3.0f);
> : document.add(f);
> 
> : if then i try to get the boost factor of the boostfield
> :
> : System.out.println(IndexReader.open(indexDir).document(0).getField("boostfield").getBoost());
> :
> : for the only one document indexed I get 1.0 instead of 3.0!
> :
> : where is the error?
> 
> Did you read the documentation for getBoost?
> 
> http://lucene.apache.org/java/docs/api/org/apache/lucene/document/Document.html#getBoost()
> 
> if you search past messages for getBoost and setBoost you should be able
> to find some explanations of how Document based boosts (as opposed to
> Query boosts) are used at indexing time.
> 
> 
> 
> -Hoss
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 


-- 
Riccardo Daviddi
University of Siena - Information Engeneering
rdaviddi@gmail.com

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


Re: setBoost(float) in org.apache.lucene.document.Field cannot be applied to (double)???

Posted by Chris Hostetter <ho...@fucit.org>.
: Field f = Field.Text("boostfield", "text");
: f.setBoost(3.0f);
: document.add(f);

: if then i try to get the boost factor of the boostfield
:
: System.out.println(IndexReader.open(indexDir).document(0).getField("boostfield").getBoost());
:
: for the only one document indexed I get 1.0 instead of 3.0!
:
: where is the error?

Did you read the documentation for getBoost?

http://lucene.apache.org/java/docs/api/org/apache/lucene/document/Document.html#getBoost()

if you search past messages for getBoost and setBoost you should be able
to find some explanations of how Document based boosts (as opposed to
Query boosts) are used at indexing time.



-Hoss


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


Re: setBoost(float) in org.apache.lucene.document.Field cannot be applied to (double)???

Posted by Otis Gospodnetic <ot...@yahoo.com>.
A Lucene Highlighter Jar is included in the Lucene in Action code.
The link to downloadable code is at http://lucenebook.com/

Otis

--- Riccardo Daviddi <rd...@gmail.com> wrote:

> I don't know where I am wrong...
> 
> I just do this:
> 
> IndexWriter writer = new IndexWriter(indexDir, new
> StandardAnalyzer(),
>                                           
> !IndexReader.indexExists(indexDir));
> writer.setUseCompoundFile(true);
> Document document = new Document();
> document.add(Field.Keyword("DocId", Integer.toString(docId)));
> Field f = Field.Text("boostfield", "text");
> f.setBoost(3.0f);
> document.add(f);
> writer.addDocument(document);
>         writer.optimize();
>         writer.close();
> 
> if then i try to get the boost factor of the boostfield 
> 
>
System.out.println(IndexReader.open(indexDir).document(0).getField("boostfield").getBoost());
> 
> for the only one document indexed I get 1.0 instead of 3.0!
> 
> where is the error?
> 
> thx
> 
> On 8/4/05, Otis Gospodnetic <ot...@yahoo.com> wrote:
> > Yes. use 1.2f there.  That method accepts floats, not doubles. 
> That
> > could be an error in the Lucene book.
> > 
> > Otis
> > 
> > 
> > --- Riccardo Daviddi <rd...@gmail.com> wrote:
> > 
> > > Why I got this error by writing for example:
> > >
> > > Field senderNameField = Field.Text("senderName", senderName);
> > > Field subjectField = Field.Text("subject", subject);
> > > subjectField.setBoost(1.2);
> > >
> > > as in the manual lucene in action??
> > >
> > > 1.2 is a double, but the method wants a float?
> > > --
> > > Riccardo Daviddi
> > >
> > >
> ---------------------------------------------------------------------
> > > 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
> > 
> > 
> 
> 
> -- 
> Riccardo Daviddi
> University of Siena - Information Engeneering
> rdaviddi@gmail.com
> 
> ---------------------------------------------------------------------
> 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: setBoost(float) in org.apache.lucene.document.Field cannot be applied to (double)???

Posted by Riccardo Daviddi <rd...@gmail.com>.
I don't know where I am wrong...

I just do this:

IndexWriter writer = new IndexWriter(indexDir, new StandardAnalyzer(),
                                           !IndexReader.indexExists(indexDir));
writer.setUseCompoundFile(true);
Document document = new Document();
document.add(Field.Keyword("DocId", Integer.toString(docId)));
Field f = Field.Text("boostfield", "text");
f.setBoost(3.0f);
document.add(f);
writer.addDocument(document);
        writer.optimize();
        writer.close();

if then i try to get the boost factor of the boostfield 

System.out.println(IndexReader.open(indexDir).document(0).getField("boostfield").getBoost());

for the only one document indexed I get 1.0 instead of 3.0!

where is the error?

thx

On 8/4/05, Otis Gospodnetic <ot...@yahoo.com> wrote:
> Yes. use 1.2f there.  That method accepts floats, not doubles.  That
> could be an error in the Lucene book.
> 
> Otis
> 
> 
> --- Riccardo Daviddi <rd...@gmail.com> wrote:
> 
> > Why I got this error by writing for example:
> >
> > Field senderNameField = Field.Text("senderName", senderName);
> > Field subjectField = Field.Text("subject", subject);
> > subjectField.setBoost(1.2);
> >
> > as in the manual lucene in action??
> >
> > 1.2 is a double, but the method wants a float?
> > --
> > Riccardo Daviddi
> >
> > ---------------------------------------------------------------------
> > 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
> 
> 


-- 
Riccardo Daviddi
University of Siena - Information Engeneering
rdaviddi@gmail.com

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


Re: setBoost(float) in org.apache.lucene.document.Field cannot be applied to (double)???

Posted by Riccardo Daviddi <rd...@gmail.com>.
It seems it doesn't change the boost factors and that is strange, I
did as in the manual, I thought it was easy, I just use:

fieldname.setBoost(1.2f);

and then I add to the doc that field, and I index the doc.
All the indexing process goes ok, only these boost factors are
different from what I do in the code.

Any idea?


On 8/4/05, Otis Gospodnetic <ot...@yahoo.com> wrote:
> Yes. use 1.2f there.  That method accepts floats, not doubles.  That
> could be an error in the Lucene book.
> 
> Otis
> 
> 
> --- Riccardo Daviddi <rd...@gmail.com> wrote:
> 
> > Why I got this error by writing for example:
> >
> > Field senderNameField = Field.Text("senderName", senderName);
> > Field subjectField = Field.Text("subject", subject);
> > subjectField.setBoost(1.2);
> >
> > as in the manual lucene in action??
> >
> > 1.2 is a double, but the method wants a float?
> > --
> > Riccardo Daviddi
> >
> > ---------------------------------------------------------------------
> > 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
> 
> 


-- 
Riccardo Daviddi
University of Siena - Information Engeneering
rdaviddi@gmail.com

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


Re: setBoost(float) in org.apache.lucene.document.Field cannot be applied to (double)???

Posted by Otis Gospodnetic <ot...@yahoo.com>.
Yes. use 1.2f there.  That method accepts floats, not doubles.  That
could be an error in the Lucene book.

Otis


--- Riccardo Daviddi <rd...@gmail.com> wrote:

> Why I got this error by writing for example:
> 
> Field senderNameField = Field.Text("senderName", senderName);
> Field subjectField = Field.Text("subject", subject);
> subjectField.setBoost(1.2);
> 
> as in the manual lucene in action??
> 
> 1.2 is a double, but the method wants a float?
> -- 
> Riccardo Daviddi
> 
> ---------------------------------------------------------------------
> 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