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 adviner <er...@gmail.com> on 2009/10/22 17:52:59 UTC
How to loop through all the entries for a field
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
Re: How to loop through all the entries for a field
Posted by Mark Miller <ma...@gmail.com>.
But with Lucene 2.9 you would want to use StringHelper.intern right?
adviner wrote:
> Thank you
>
>
> Uwe Schindler wrote:
>
>> 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 <er...@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
>>>
>>
>>
>>
>>
>>
>
>
--
- Mark
http://www.lucidimagination.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 loop through all the entries for a field
Posted by adviner <er...@gmail.com>.
Thank you
Uwe Schindler wrote:
>
> 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 <er...@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
>
>
>
>
>
--
View this message in context: http://www.nabble.com/How-to-loop-through-all-the-entries-for-a-field-tp26012512p26017581.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
RE: How to loop through all the entries for a field
Posted by Uwe Schindler <uw...@thetaphi.de>.
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 <er...@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
Re: How to loop through all the entries for a field
Posted by adviner <er...@gmail.com>.
nevermind I figured it out. I did this:
while ((term = termEnum.Term()) != null)
{
if (!term.Field().Equals("BookTitle"))
break;
map = new SearchResultMap();
map.Title = term.Text();
control.Items.Add(map);
termEnum.Next();
}
thanks for all the help
adviner wrote:
>
> 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 <er...@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-tp26012512p26017525.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
Re: How to loop through all the entries for a field
Posted by adviner <er...@gmail.com>.
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 <er...@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
Re: How to loop through all the entries for a field
Posted by Erick Erickson <er...@gmail.com>.
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 <er...@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
>
>