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 selvakumar netaji <vv...@gmail.com> on 2012/10/05 13:32:56 UTC
Apache Lucene Analysis
Hi All,
I'm reading the docs of Apache Lucene.
I just read through the docs of the analyser
docs/core/org/apache/lucene/analysis/package-summary.html.
Here they have given a code snippet,I've ambiguities in the add attribute
method. Should it be added to the token stream instance?
Version matchVersion = Version.LUCENE_XY; // Substitute desired
Lucene version for XY
Analyzer analyzer = new StandardAnalyzer(matchVersion); // or any
other analyzer
TokenStream ts = analyzer.tokenStream("myfield", new
StringReader("some text goes here"));
OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
try {
ts.reset(); // Resets this stream to the beginning. (Required)
while (ts.incrementToken()) {
// Use AttributeSource.reflectAsString(boolean)
// for token stream debugging.
System.out.println("token: " + ts.reflectAsString(true));
System.out.println("token start offset: " + offsetAtt.startOffset());
System.out.println(" token end offset: " + offsetAtt.endOffset());
}
ts.end(); // Perform end-of-stream operations, e.g. set the
final offset.
} finally {
ts.close(); // Release resources associated with this stream.
}
Re: Apache Lucene Analysis
Posted by selvakumar netaji <vv...@gmail.com>.
Can you please help me to sort this out.
On Fri, Oct 5, 2012 at 7:54 PM, selvakumar netaji <vv...@gmail.com>wrote:
> Hi All,
>
>
> In the TokenStreamAPI section of the analysis documentation for lucene
> 4.0 beta, MyAnalyzer class is defined.
>
> They've added the lengthFilter in the create components method. The length
> filter doesn't accept method with three arguments in 4.0. Should I create a
> length filter class for this tutorial, but the ambiguity is there's a
> length filter defined in the analysis package.
>
> Can you please correct me if I'm wrong.
>
>
>
>
>
>
> On Fri, Oct 5, 2012 at 5:10 PM, selvakumar netaji <vv...@gmail.com>wrote:
>
>> Actually I'm getting results if I add it to the tokenStream instance.
>>
>>
>> Can you please inform is it right?
>>
>>
>> Thanks in advance.
>>
>>
>>
>> On Fri, Oct 5, 2012 at 5:02 PM, selvakumar netaji <vvekselva.gm@gmail.com
>> > wrote:
>>
>>> Hi All,
>>>
>>>
>>> I'm reading the docs of Apache Lucene.
>>>
>>> I just read through the docs of the analyser
>>> docs/core/org/apache/lucene/analysis/package-summary.html.
>>>
>>>
>>> Here they have given a code snippet,I've ambiguities in the add
>>> attribute method. Should it be added to the token stream instance?
>>>
>>> Version matchVersion = Version.LUCENE_XY; // Substitute desired Lucene version for XY
>>> Analyzer analyzer = new StandardAnalyzer(matchVersion); // or any other analyzer
>>> TokenStream ts = analyzer.tokenStream("myfield", new StringReader("some text goes here"));
>>> OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
>>>
>>> try {
>>> ts.reset(); // Resets this stream to the beginning. (Required)
>>> while (ts.incrementToken()) {
>>> // Use AttributeSource.reflectAsString(boolean)
>>> // for token stream debugging.
>>> System.out.println("token: " + ts.reflectAsString(true));
>>>
>>> System.out.println("token start offset: " + offsetAtt.startOffset());
>>> System.out.println(" token end offset: " + offsetAtt.endOffset());
>>> }
>>> ts.end(); // Perform end-of-stream operations, e.g. set the final offset.
>>> } finally {
>>> ts.close(); // Release resources associated with this stream.
>>> }
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>
Re: Apache Lucene Analysis
Posted by selvakumar netaji <vv...@gmail.com>.
Thanks Mike.
On Mon, Oct 8, 2012 at 4:30 PM, Michael McCandless <
lucene@mikemccandless.com> wrote:
> On Fri, Oct 5, 2012 at 10:24 AM, selvakumar netaji
> <vv...@gmail.com> wrote:
> > Hi All,
> >
> >
> > In the TokenStreamAPI section of the analysis documentation for lucene
> 4.0
> > beta, MyAnalyzer class is defined.
> >
> > They've added the lengthFilter in the create components method. The
> length
> > filter doesn't accept method with three arguments in 4.0.
>
> Looks like it's missing the first required boolean argument
> enablePositionIncrements; I'll fix the javadocs. Thanks for raising
> this!
>
> > Should I create a
> > length filter class for this tutorial, but the ambiguity is there's a
> > length filter defined in the analysis package.
>
> You should be able to just use the existing one (passing true or false
> for the first arg) ...
>
> Mike McCandless
>
> http://blog.mikemccandless.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Re: Apache Lucene Analysis
Posted by Michael McCandless <lu...@mikemccandless.com>.
On Fri, Oct 5, 2012 at 10:24 AM, selvakumar netaji
<vv...@gmail.com> wrote:
> Hi All,
>
>
> In the TokenStreamAPI section of the analysis documentation for lucene 4.0
> beta, MyAnalyzer class is defined.
>
> They've added the lengthFilter in the create components method. The length
> filter doesn't accept method with three arguments in 4.0.
Looks like it's missing the first required boolean argument
enablePositionIncrements; I'll fix the javadocs. Thanks for raising
this!
> Should I create a
> length filter class for this tutorial, but the ambiguity is there's a
> length filter defined in the analysis package.
You should be able to just use the existing one (passing true or false
for the first arg) ...
Mike McCandless
http://blog.mikemccandless.com
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Apache Lucene Analysis
Posted by selvakumar netaji <vv...@gmail.com>.
Hi All,
In the TokenStreamAPI section of the analysis documentation for lucene 4.0
beta, MyAnalyzer class is defined.
They've added the lengthFilter in the create components method. The length
filter doesn't accept method with three arguments in 4.0. Should I create a
length filter class for this tutorial, but the ambiguity is there's a
length filter defined in the analysis package.
Can you please correct me if I'm wrong.
On Fri, Oct 5, 2012 at 5:10 PM, selvakumar netaji <vv...@gmail.com>wrote:
> Actually I'm getting results if I add it to the tokenStream instance.
>
>
> Can you please inform is it right?
>
>
> Thanks in advance.
>
>
>
> On Fri, Oct 5, 2012 at 5:02 PM, selvakumar netaji <vv...@gmail.com>wrote:
>
>> Hi All,
>>
>>
>> I'm reading the docs of Apache Lucene.
>>
>> I just read through the docs of the analyser
>> docs/core/org/apache/lucene/analysis/package-summary.html.
>>
>>
>> Here they have given a code snippet,I've ambiguities in the add attribute
>> method. Should it be added to the token stream instance?
>>
>> Version matchVersion = Version.LUCENE_XY; // Substitute desired Lucene version for XY
>> Analyzer analyzer = new StandardAnalyzer(matchVersion); // or any other analyzer
>> TokenStream ts = analyzer.tokenStream("myfield", new StringReader("some text goes here"));
>> OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
>>
>> try {
>> ts.reset(); // Resets this stream to the beginning. (Required)
>> while (ts.incrementToken()) {
>> // Use AttributeSource.reflectAsString(boolean)
>> // for token stream debugging.
>> System.out.println("token: " + ts.reflectAsString(true));
>>
>> System.out.println("token start offset: " + offsetAtt.startOffset());
>> System.out.println(" token end offset: " + offsetAtt.endOffset());
>> }
>> ts.end(); // Perform end-of-stream operations, e.g. set the final offset.
>> } finally {
>> ts.close(); // Release resources associated with this stream.
>> }
>>
>>
>>
>>
>>
>>
>>
>
Re: Apache Lucene Analysis
Posted by Michael McCandless <lu...@mikemccandless.com>.
That is correct ... it should be:
OffsetAttribute offsetAtt = ts.addAttribute(OffsetAttribute.class);
I'll fix the javadocs (for 4.1) ... thanks for raising!
Mike McCandless
http://blog.mikemccandless.com
On Fri, Oct 5, 2012 at 7:40 AM, selvakumar netaji
<vv...@gmail.com> wrote:
> Actually I'm getting results if I add it to the tokenStream instance.
>
>
> Can you please inform is it right?
>
>
> Thanks in advance.
>
>
> On Fri, Oct 5, 2012 at 5:02 PM, selvakumar netaji <vv...@gmail.com>wrote:
>
>> Hi All,
>>
>>
>> I'm reading the docs of Apache Lucene.
>>
>> I just read through the docs of the analyser
>> docs/core/org/apache/lucene/analysis/package-summary.html.
>>
>>
>> Here they have given a code snippet,I've ambiguities in the add attribute
>> method. Should it be added to the token stream instance?
>>
>> Version matchVersion = Version.LUCENE_XY; // Substitute desired Lucene version for XY
>> Analyzer analyzer = new StandardAnalyzer(matchVersion); // or any other analyzer
>> TokenStream ts = analyzer.tokenStream("myfield", new StringReader("some text goes here"));
>> OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
>>
>> try {
>> ts.reset(); // Resets this stream to the beginning. (Required)
>> while (ts.incrementToken()) {
>> // Use AttributeSource.reflectAsString(boolean)
>> // for token stream debugging.
>> System.out.println("token: " + ts.reflectAsString(true));
>>
>> System.out.println("token start offset: " + offsetAtt.startOffset());
>> System.out.println(" token end offset: " + offsetAtt.endOffset());
>> }
>> ts.end(); // Perform end-of-stream operations, e.g. set the final offset.
>> } finally {
>> ts.close(); // Release resources associated with this stream.
>> }
>>
>>
>>
>>
>>
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Apache Lucene Analysis
Posted by selvakumar netaji <vv...@gmail.com>.
Actually I'm getting results if I add it to the tokenStream instance.
Can you please inform is it right?
Thanks in advance.
On Fri, Oct 5, 2012 at 5:02 PM, selvakumar netaji <vv...@gmail.com>wrote:
> Hi All,
>
>
> I'm reading the docs of Apache Lucene.
>
> I just read through the docs of the analyser
> docs/core/org/apache/lucene/analysis/package-summary.html.
>
>
> Here they have given a code snippet,I've ambiguities in the add attribute
> method. Should it be added to the token stream instance?
>
> Version matchVersion = Version.LUCENE_XY; // Substitute desired Lucene version for XY
> Analyzer analyzer = new StandardAnalyzer(matchVersion); // or any other analyzer
> TokenStream ts = analyzer.tokenStream("myfield", new StringReader("some text goes here"));
> OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
>
> try {
> ts.reset(); // Resets this stream to the beginning. (Required)
> while (ts.incrementToken()) {
> // Use AttributeSource.reflectAsString(boolean)
> // for token stream debugging.
> System.out.println("token: " + ts.reflectAsString(true));
>
> System.out.println("token start offset: " + offsetAtt.startOffset());
> System.out.println(" token end offset: " + offsetAtt.endOffset());
> }
> ts.end(); // Perform end-of-stream operations, e.g. set the final offset.
> } finally {
> ts.close(); // Release resources associated with this stream.
> }
>
>
>
>
>
>
>