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 Mukul Ranjan <mr...@egain.com> on 2016/07/28 16:00:47 UTC

get enumeration of all terms starting at a given term after lucene 4

Hi All,

How to get enumeration of all terms starting at a given term. I have upgrade lucene version from lucene 3.6 to lucene 5.5.2. After 3.6, indexReader terms api is removed which used to give list of terms.
I have used below code  to get the termEnum, but it has no option to pass the value of the field which is used to get the matching result.

Terms terms = MultiFields.getTerms(reader, TEXT_FIELD);
TermsEnum termsEnum = terms.iterator();

Can anyone help me on this.

Thanks,
Mukul Ranjan
___ Watch an eGain Customer Service Transformation<https://www.youtube.com/watch?v=dEwdFfWoyuE> Success Story

Re: get enumeration of all terms starting at a given term after lucene 4

Posted by Michael McCandless <lu...@mikemccandless.com>.
Use seekCeil instead of seekExact.

Mike McCandless

http://blog.mikemccandless.com

On Fri, Jul 29, 2016 at 9:44 AM, Mukul Ranjan <mr...@egain.com> wrote:

> Thanks Parit!!!  I will try the below solution.
>
> Thanks,
> Mukul Ranjan
>
> -----Original Message-----
> From: Parit Bansal [mailto:Parit.Bansal@sib.swiss]
> Sent: Friday, July 29, 2016 7:11 PM
> To: java-user@lucene.apache.org
> Subject: Re: get enumeration of all terms starting at a given term after
> lucene 4
>
> Hi Mukul,
>
> Provided terms are sorted how about doing
>
> if (termsEnum.seekExact(text)) {
>      BytesRef text;
>      while ((text = con.foreignTermsEnum.next()) != null) {
>          // keep looping till your value is a prefix
>      }
> }
>
> - Parit
>
> On 07/29/2016 03:30 PM, Mukul Ranjan wrote:
> > Hi Parit,
> >
> > PrefixTermsEnum is removed in lucene 5.1 so we can not use this now.
> >
> > Thanks,
> > Mukul
> >
> > -----Original Message-----
> > From: Parit Bansal [mailto:Parit.Bansal@sib.swiss]
> > Sent: Friday, July 29, 2016 3:20 PM
> > To: java-user@lucene.apache.org
> > Subject: Re: get enumeration of all terms starting at a given term
> > after lucene 4
> >
> > On 07/29/2016 08:27 AM, Mukul Ranjan wrote:
> >> lucene version from lucene 3.6 to lucene 5.5.2. After 3.6,
> >>> indexReader terms api is removed which used to give list of terms.
> >>> I have used below code  to get the termEnum, but it has no option to
> >>> pass the value of the field which is used to get the matching result.
> >>>
> >>> Terms terms = MultiFields.getTerms(reader, TEXT_FIELD); TermsEnum
> >>> termsEnum = terms.iterator();
> >>>
> >>> Can anyone help me on this.
> > Hi Mukul,
> >
> > How about using PrefixTermsEnum like:
> >
> > Terms terms = MultiFields.getTerms(reader, TEXT_FIELD); TermsEnum
> > termsEnum = new PrefixTermsEnum(tenum, terms.iterator());
> >
> > - Best
> > Parit
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> > ___ Watch an eGain Customer Service
> > Transformation<https://www.youtube.com/watch?v=dEwdFfWoyuE> Success
> > Story
> >
> > ---------------------------------------------------------------------
> > 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
>
> ___ Watch an eGain Customer Service Transformation<
> https://www.youtube.com/watch?v=dEwdFfWoyuE> Success Story
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

RE: get enumeration of all terms starting at a given term after lucene 4

Posted by Mukul Ranjan <mr...@egain.com>.
Thanks Parit!!!  I will try the below solution.

Thanks,
Mukul Ranjan

-----Original Message-----
From: Parit Bansal [mailto:Parit.Bansal@sib.swiss]
Sent: Friday, July 29, 2016 7:11 PM
To: java-user@lucene.apache.org
Subject: Re: get enumeration of all terms starting at a given term after lucene 4

Hi Mukul,

Provided terms are sorted how about doing

if (termsEnum.seekExact(text)) {
     BytesRef text;
     while ((text = con.foreignTermsEnum.next()) != null) {
         // keep looping till your value is a prefix
     }
}

- Parit

On 07/29/2016 03:30 PM, Mukul Ranjan wrote:
> Hi Parit,
>
> PrefixTermsEnum is removed in lucene 5.1 so we can not use this now.
>
> Thanks,
> Mukul
>
> -----Original Message-----
> From: Parit Bansal [mailto:Parit.Bansal@sib.swiss]
> Sent: Friday, July 29, 2016 3:20 PM
> To: java-user@lucene.apache.org
> Subject: Re: get enumeration of all terms starting at a given term
> after lucene 4
>
> On 07/29/2016 08:27 AM, Mukul Ranjan wrote:
>> lucene version from lucene 3.6 to lucene 5.5.2. After 3.6,
>>> indexReader terms api is removed which used to give list of terms.
>>> I have used below code  to get the termEnum, but it has no option to
>>> pass the value of the field which is used to get the matching result.
>>>
>>> Terms terms = MultiFields.getTerms(reader, TEXT_FIELD); TermsEnum
>>> termsEnum = terms.iterator();
>>>
>>> Can anyone help me on this.
> Hi Mukul,
>
> How about using PrefixTermsEnum like:
>
> Terms terms = MultiFields.getTerms(reader, TEXT_FIELD); TermsEnum
> termsEnum = new PrefixTermsEnum(tenum, terms.iterator());
>
> - Best
> Parit
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
> ___ Watch an eGain Customer Service
> Transformation<https://www.youtube.com/watch?v=dEwdFfWoyuE> Success
> Story
>
> ---------------------------------------------------------------------
> 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

___ Watch an eGain Customer Service Transformation<https://www.youtube.com/watch?v=dEwdFfWoyuE> Success Story

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


Re: get enumeration of all terms starting at a given term after lucene 4

Posted by Parit Bansal <Pa...@sib.swiss>.
Hi Mukul,

Provided terms are sorted how about doing

if (termsEnum.seekExact(text)) {
     BytesRef text;
     while ((text = con.foreignTermsEnum.next()) != null) {
         // keep looping till your value is a prefix
     }
}

- Parit

On 07/29/2016 03:30 PM, Mukul Ranjan wrote:
> Hi Parit,
>
> PrefixTermsEnum is removed in lucene 5.1 so we can not use this now.
>
> Thanks,
> Mukul
>
> -----Original Message-----
> From: Parit Bansal [mailto:Parit.Bansal@sib.swiss]
> Sent: Friday, July 29, 2016 3:20 PM
> To: java-user@lucene.apache.org
> Subject: Re: get enumeration of all terms starting at a given term after lucene 4
>
> On 07/29/2016 08:27 AM, Mukul Ranjan wrote:
>> lucene version from lucene 3.6 to lucene 5.5.2. After 3.6,
>>> indexReader terms api is removed which used to give list of terms.
>>> I have used below code  to get the termEnum, but it has no option to
>>> pass the value of the field which is used to get the matching result.
>>>
>>> Terms terms = MultiFields.getTerms(reader, TEXT_FIELD); TermsEnum
>>> termsEnum = terms.iterator();
>>>
>>> Can anyone help me on this.
> Hi Mukul,
>
> How about using PrefixTermsEnum like:
>
> Terms terms = MultiFields.getTerms(reader, TEXT_FIELD); TermsEnum termsEnum = new PrefixTermsEnum(tenum, terms.iterator());
>
> - Best
> Parit
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
> ___ Watch an eGain Customer Service Transformation<https://www.youtube.com/watch?v=dEwdFfWoyuE> Success Story
>
> ---------------------------------------------------------------------
> 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: get enumeration of all terms starting at a given term after lucene 4

Posted by Mukul Ranjan <mr...@egain.com>.
Hi Parit,

PrefixTermsEnum is removed in lucene 5.1 so we can not use this now.

Thanks,
Mukul

-----Original Message-----
From: Parit Bansal [mailto:Parit.Bansal@sib.swiss]
Sent: Friday, July 29, 2016 3:20 PM
To: java-user@lucene.apache.org
Subject: Re: get enumeration of all terms starting at a given term after lucene 4

On 07/29/2016 08:27 AM, Mukul Ranjan wrote:
> lucene version from lucene 3.6 to lucene 5.5.2. After 3.6,
> >indexReader terms api is removed which used to give list of terms.
> >I have used below code  to get the termEnum, but it has no option to
> >pass the value of the field which is used to get the matching result.
> >
> >Terms terms = MultiFields.getTerms(reader, TEXT_FIELD); TermsEnum
> >termsEnum = terms.iterator();
> >
> >Can anyone help me on this.

Hi Mukul,

How about using PrefixTermsEnum like:

Terms terms = MultiFields.getTerms(reader, TEXT_FIELD); TermsEnum termsEnum = new PrefixTermsEnum(tenum, terms.iterator());

- Best
Parit


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

___ Watch an eGain Customer Service Transformation<https://www.youtube.com/watch?v=dEwdFfWoyuE> Success Story

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


Re: get enumeration of all terms starting at a given term after lucene 4

Posted by Parit Bansal <Pa...@sib.swiss>.
On 07/29/2016 08:27 AM, Mukul Ranjan wrote:
> lucene version from lucene 3.6 to lucene 5.5.2. After 3.6,
> >indexReader terms api is removed which used to give list of terms.
> >I have used below code  to get the termEnum, but it has no option to
> >pass the value of the field which is used to get the matching result.
> >
> >Terms terms = MultiFields.getTerms(reader, TEXT_FIELD); TermsEnum
> >termsEnum = terms.iterator();
> >
> >Can anyone help me on this.

Hi Mukul,

How about using PrefixTermsEnum like:

Terms terms = MultiFields.getTerms(reader, TEXT_FIELD); TermsEnum
termsEnum = new PrefixTermsEnum(tenum, terms.iterator());

- Best
Parit


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


RE: get enumeration of all terms starting at a given term after lucene 4

Posted by Mukul Ranjan <mr...@egain.com>.
Hi Greg,

Sorry it was mistake, actually 'TEXT_FIELD' is constant in my code. Please find below the correct code-

Terms terms = MultiFields.getTerms(reader, "field");
TermsEnum  termsEnum = terms.iterator();

Thanks,
Mukul

-----Original Message-----
From: Greg Bowyer [mailto:gbowyer@fastmail.co.uk]
Sent: Friday, July 29, 2016 12:27 AM
To: java-user@lucene.apache.org
Subject: Re: get enumeration of all terms starting at a given term after lucene 4

I am confused by your example, MultiFields.get allows you to ask for a specific field.

On Thu, Jul 28, 2016, at 09:00 AM, Mukul Ranjan wrote:
> Hi All,
>
> How to get enumeration of all terms starting at a given term. I have
> upgrade lucene version from lucene 3.6 to lucene 5.5.2. After 3.6,
> indexReader terms api is removed which used to give list of terms.
> I have used below code  to get the termEnum, but it has no option to
> pass the value of the field which is used to get the matching result.
>
> Terms terms = MultiFields.getTerms(reader, TEXT_FIELD); TermsEnum
> termsEnum = terms.iterator();
>
> Can anyone help me on this.
>
> Thanks,
> Mukul Ranjan
> ___ Watch an eGain Customer Service
> Transformation<https://www.youtube.com/watch?v=dEwdFfWoyuE> Success
> Story

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

___ Watch an eGain Customer Service Transformation<https://www.youtube.com/watch?v=dEwdFfWoyuE> Success Story

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


Re: get enumeration of all terms starting at a given term after lucene 4

Posted by Greg Bowyer <gb...@fastmail.co.uk>.
I am confused by your example, MultiFields.get allows you to ask for a
specific field.

On Thu, Jul 28, 2016, at 09:00 AM, Mukul Ranjan wrote:
> Hi All,
> 
> How to get enumeration of all terms starting at a given term. I have
> upgrade lucene version from lucene 3.6 to lucene 5.5.2. After 3.6,
> indexReader terms api is removed which used to give list of terms.
> I have used below code  to get the termEnum, but it has no option to pass
> the value of the field which is used to get the matching result.
> 
> Terms terms = MultiFields.getTerms(reader, TEXT_FIELD);
> TermsEnum termsEnum = terms.iterator();
> 
> Can anyone help me on this.
> 
> Thanks,
> Mukul Ranjan
> ___ Watch an eGain Customer Service
> Transformation<https://www.youtube.com/watch?v=dEwdFfWoyuE> Success Story

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