lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <...@thetaphi.de>
Subject RE: How to loop through all the entries for a field
Date Thu, 22 Oct 2009 21:28:47 GMT
Use this one:

 

String fieldname="BookTitle";

 

fieldname = fieldname.intern(); // because of this we need no
String.equals()

TermEnum te = IndexReader.terms(new Term(fieldname, ""));

do {

      Term term = te.term();

      if (term == null || term.field() != fieldname) break;

      System.out.println(term.text());

} while (te.next());

te.close();

 

-----

Uwe Schindler

H.-H.-Meier-Allee 63, D-28213 Bremen

http://www.thetaphi.de

eMail: uwe@thetaphi.de

 

> -----Original Message-----

> From: adviner [mailto:eric.advincula@gmail.com]

> Sent: Thursday, October 22, 2009 11:20 PM

> To: java-user@lucene.apache.org

> Subject: Re: How to loop through all the entries for a field

> 

> 

> How do you know if your on your last term?  I tried it and it does work

> but

> continues.  How do you know to check if its the last entry?

> 

> Thanks

> 

> 

> Erick Erickson wrote:

> >

> > Try something like

> > TermEnum te = IndexReader.terms(new Term("BookTitle", ""));

> > do {

> >     Term term = te.term();

> >     if (! term.field().equals("BookTitle")) break;

> >     System.out.println(term.text());

> > } while (te.next());

> >

> >

> > Note that next() will merrily continue beyond the last term for

> > the field "BookTitle", so you have to check that you're still

> > where you want to be.

> >

> >

> > Best

> > Erick

> >

> > On Thu, Oct 22, 2009 at 11:52 AM, adviner <eric.advincula@gmail.com>

> > wrote:

> >

> >>

> >> I have a field in called BookTitle.  I want to loop through all the

> >> entries

> >> without doing a search.  I just want to get the list of BookTitle's

> that

> >> is

> >> in this field:

> >>

> >> I tried IndexReader but MaxDocs() doesnt work because it returns

> >> everything

> >> and I have other fields in their which is allot bigger.

> >>

> >>

> >> Sorry i originally posted to the developer site which is wrong place so

> i

> >> moved it here

> >> --

> >> View this message in context:

> >> http://www.nabble.com/How-to-loop-through-all-the-entries-for-a-field-

> tp26012512p26012512.html

> >> Sent from the Lucene - Java Users mailing list archive at Nabble.com.

> >>

> >>

> >> ---------------------------------------------------------------------

> >> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org

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

> >>

> >>

> >

> >

> 

> --

> View this message in context: http://www.nabble.com/How-to-loop-through-

> all-the-entries-for-a-field-tp26012512p26017418.html

> Sent from the Lucene - Java Users mailing list archive at Nabble.com.

> 

> 

> ---------------------------------------------------------------------

> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org

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

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message