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 장용석 <ne...@gmail.com> on 2008/11/05 11:06:54 UTC

How to use Sort cass in Lucene 2.4.0?

hi.
I have a question :)

In lucene 2.3.X I did use Sort class like this..

Sort sort = new Sort("FIELDNAME", true);
Hits hits = searcher.search(query, sort);

but, in lucene 2.4.0 search(Query, Sort) method is deprecated. I was
searched API, so I found this method
search(query, filter, n, sort)

Could one of you point me to an example of code for querying without using
the deprecated method search(query, sort)?

and an example of code for method search(query, filter, n, sort). :)

Thanks. :)


-- 
DEV용식
http://devyongsik.tistory.com

Re: How to use Sort cass in Lucene 2.4.0?

Posted by 장용석 <ne...@gmail.com>.
Thank you very much.
It's really usefull sample code for me. :)

Thanks.

Jang.


08. 11. 6, Todd Benge <to...@gmail.com>님이 작성:
>
> Yup - goofed that up.
>
> Thanks,
>
> Todd
>
> 2008/11/5 Grant Ingersoll <gs...@apache.org>:
> >
> > On Nov 5, 2008, at 12:04 PM, Todd Benge wrote:
> >
> >> I think it's like this:
> >>
> >> Sort sort = new Sort("FIELDNAME", true);
> >> TopFieldDocs docs  = searcher.searcher(query, null, n, sort); // n is
> >> the number of documents you want to retrieve
> >>
> >> ScoreDoc[] hits = docs.scoreDocs;
> >> for (int i = 0; i<docs.totalHits; i++ ) {
> >
> >
> > FYI: totalHits is the total number of matches and may be different from
> the
> > actual length of the docs.scoreDocs[] array, so this should be
> >
> > i < hits.length
> >
> > Otherwise, looks good.
> >
> >>
> >>    Document doc = searcher.doc(hits[i].doc);
> >> }
> >>
> >> Hope this helps.
> >>
> >> Todd
> >>
> >>
> >> 2008/11/5 장용석 <ne...@gmail.com>:
> >>>
> >>> hi.
> >>> I have a question :)
> >>>
> >>> In lucene 2.3.X I did use Sort class like this..
> >>>
> >>> Sort sort = new Sort("FIELDNAME", true);
> >>> Hits hits = searcher.search(query, sort);
> >>>
> >>> but, in lucene 2.4.0 search(Query, Sort) method is deprecated. I was
> >>> searched API, so I found this method
> >>> search(query, filter, n, sort)
> >>>
> >>> Could one of you point me to an example of code for querying without
> >>> using
> >>> the deprecated method search(query, sort)?
> >>>
> >>> and an example of code for method search(query, filter, n, sort). :)
> >>>
> >>> Thanks. :)
> >>>
> >>>
> >>> --
> >>> DEV용식
> >>> http://devyongsik.tistory.com
> >>>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
>



-- 
DEV용식
http://devyongsik.tistory.com

Re: How to use Sort cass in Lucene 2.4.0?

Posted by Todd Benge <to...@gmail.com>.
Yup - goofed that up.

Thanks,

Todd

2008/11/5 Grant Ingersoll <gs...@apache.org>:
>
> On Nov 5, 2008, at 12:04 PM, Todd Benge wrote:
>
>> I think it's like this:
>>
>> Sort sort = new Sort("FIELDNAME", true);
>> TopFieldDocs docs  = searcher.searcher(query, null, n, sort); // n is
>> the number of documents you want to retrieve
>>
>> ScoreDoc[] hits = docs.scoreDocs;
>> for (int i = 0; i<docs.totalHits; i++ ) {
>
>
> FYI: totalHits is the total number of matches and may be different from the
> actual length of the docs.scoreDocs[] array, so this should be
>
> i < hits.length
>
> Otherwise, looks good.
>
>>
>>    Document doc = searcher.doc(hits[i].doc);
>> }
>>
>> Hope this helps.
>>
>> Todd
>>
>>
>> 2008/11/5 장용석 <ne...@gmail.com>:
>>>
>>> hi.
>>> I have a question :)
>>>
>>> In lucene 2.3.X I did use Sort class like this..
>>>
>>> Sort sort = new Sort("FIELDNAME", true);
>>> Hits hits = searcher.search(query, sort);
>>>
>>> but, in lucene 2.4.0 search(Query, Sort) method is deprecated. I was
>>> searched API, so I found this method
>>> search(query, filter, n, sort)
>>>
>>> Could one of you point me to an example of code for querying without
>>> using
>>> the deprecated method search(query, sort)?
>>>
>>> and an example of code for method search(query, filter, n, sort). :)
>>>
>>> Thanks. :)
>>>
>>>
>>> --
>>> DEV용식
>>> http://devyongsik.tistory.com
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Re: How to use Sort cass in Lucene 2.4.0?

Posted by Grant Ingersoll <gs...@apache.org>.
On Nov 5, 2008, at 12:04 PM, Todd Benge wrote:

> I think it's like this:
>
> Sort sort = new Sort("FIELDNAME", true);
> TopFieldDocs docs  = searcher.searcher(query, null, n, sort); // n is
> the number of documents you want to retrieve
>
> ScoreDoc[] hits = docs.scoreDocs;
> for (int i = 0; i<docs.totalHits; i++ ) {


FYI: totalHits is the total number of matches and may be different  
from the actual length of the docs.scoreDocs[] array, so this should be

i < hits.length

Otherwise, looks good.

>
>     Document doc = searcher.doc(hits[i].doc);
> }
>
> Hope this helps.
>
> Todd
>
>
> 2008/11/5 장용석 <ne...@gmail.com>:
>> hi.
>> I have a question :)
>>
>> In lucene 2.3.X I did use Sort class like this..
>>
>> Sort sort = new Sort("FIELDNAME", true);
>> Hits hits = searcher.search(query, sort);
>>
>> but, in lucene 2.4.0 search(Query, Sort) method is deprecated. I was
>> searched API, so I found this method
>> search(query, filter, n, sort)
>>
>> Could one of you point me to an example of code for querying  
>> without using
>> the deprecated method search(query, sort)?
>>
>> and an example of code for method search(query, filter, n, sort). :)
>>
>> Thanks. :)
>>
>>
>> --
>> DEV용식
>> http://devyongsik.tistory.com
>>


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


Re: How to use Sort cass in Lucene 2.4.0?

Posted by Todd Benge <to...@gmail.com>.
I think it's like this:

Sort sort = new Sort("FIELDNAME", true);
TopFieldDocs docs  = searcher.searcher(query, null, n, sort); // n is
the number of documents you want to retrieve

ScoreDoc[] hits = docs.scoreDocs;
for (int i = 0; i<docs.totalHits; i++ ) {
     Document doc = searcher.doc(hits[i].doc);
}

Hope this helps.

Todd


2008/11/5 장용석 <ne...@gmail.com>:
> hi.
> I have a question :)
>
> In lucene 2.3.X I did use Sort class like this..
>
> Sort sort = new Sort("FIELDNAME", true);
> Hits hits = searcher.search(query, sort);
>
> but, in lucene 2.4.0 search(Query, Sort) method is deprecated. I was
> searched API, so I found this method
> search(query, filter, n, sort)
>
> Could one of you point me to an example of code for querying without using
> the deprecated method search(query, sort)?
>
> and an example of code for method search(query, filter, n, sort). :)
>
> Thanks. :)
>
>
> --
> DEV용식
> http://devyongsik.tistory.com
>