lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Muir <rcm...@gmail.com>
Subject Re: PayloadAttribute behavior change between Lucene 2.9/3.0 and the trunk
Date Sat, 04 Dec 2010 03:30:29 GMT
On Fri, Dec 3, 2010 at 10:15 PM, Teruhiko Kurosaka <Kuro@basistech.com> wrote:
> Hello,
> I have a Tokenizer that generates a Payload, and a TokenFilter that uses it.
> These work well with Solr 1.4.0 (therefore Lucene 2.9.1?), but when
> I switched to the trunk version (I rebuilt the Tokenizer and TokenFilter
> using the Lucene jar from the trunk and ran it), I encountered with
> this error:
>
> java.lang.IllegalArgumentException: This AttributeSource does not have the attribute
'org.apache.lucene.analysis.tokenattributes.PayloadAttribute'.
>
> This exception comes from this line in the TokenFilter code:
>
>        payloadAtt = (PayloadAttribute) getAttribute(PayloadAttribute.class);
>

I recommend you use addAttribute instead. Its buggy to use
getAttribute in this way because you cannot rely upon the fact that a
previous tokenstream has added the attribute[1]. I think your code was
only working before because of TokenWrapperAttributeFactory (the
backwards compatibility layer in 2.9 for the old Token API) being
present.

[1] http://lucene.apache.org/java/2_9_0/api/core/org/apache/lucene/util/AttributeSource.html#getAttribute(java.lang.Class)

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


Mime
View raw message