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 dokondr <do...@gmail.com> on 2012/12/18 20:32:07 UTC

Some fixes to typos in documentation

Hi,
Found some typos. In package description:
http://lucene.apache.org/core/4_0_0/core/org/apache/lucene/analysis/package-summary.html?is-external=true#package_description

In the example code bellow the following corrections are needed:

OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
*** Should be:
OffsetAttribute offsetAtt = ts.addAttribute(OffsetAttribute.class);

*** And:
   } finally {
      ts.close(); // Release resources associated with this stream.
    }
*** Should be:
   } finally {
analyzer.close();
      ts.close(); // Release resources associated with this stream.
    }


Example code:

    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)
<http://lucene.apache.org/core/4_0_0/core/org/apache/lucene/util/AttributeSource.html#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: Some fixes to typos in documentation

Posted by Steve Rowe <sa...@gmail.com>.
Hi Dima,

On Dec 18, 2012, at 2:32 PM, dokondr <do...@gmail.com> wrote:
> Hi,
> Found some typos.  In package description:
> http://lucene.apache.org/core/4_0_0/core/org/apache/lucene/analysis/package-summary.html?is-external=true#package_description

Thanks for reporting these.

> OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
> *** Should be:
> OffsetAttribute offsetAtt = ts.addAttribute(OffsetAttribute.class);

This one is already fixed in branch_4x (future v4.X):

<http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/analysis/package.html?diff_format=f&view=markup#l186>

and trunk (future v5.X):

<http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/analysis/package.html?diff_format=f&view=markup#l186>

>   } finally {
>      ts.close(); // Release resources associated with this stream.
>    }
> *** Should be:
>   } finally {
> analyzer.close();
>      ts.close(); // Release resources associated with this stream.
>    }

Although this is technically correct, I see very few actual uses of Analyzer.close() in Lucene's tests.

Ordinarily, Analyzers are reused, so you wouldn't want to close them unless your program is going to exit, in which case resources will be released anyway?  (I guess apps running in resource constrained environments might choose to reclaim resources and then re-initialize on each use.) 

Steve


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