lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Teruhiko Kurosaka <K...@basistech.com>
Subject Re: PayloadAttribute behavior change between Lucene 2.9/3.0 and the trunk
Date Sat, 04 Dec 2010 23:05:23 GMT
Thank you, Robert, substituting getAttribute with addAttribute worked!

But I don't understand why.  Could you help me to understand the mechanics?

In my setting,
hasAttribute(PayloadAttribute.class) returns false.

So I thought addAttribute(PayloadAttribute.class) would just
create a new PayloadAttribute object.  It would remedy the
Exception, but it wouldn't do any good accessing the payload 
generated upstream.

But the newly generated PayloadAttribute t is actually 
getting the payload that was generated upstream (by my Tokenizer). 
How is this possible?


On Dec 3, 2010, at 7:30 PM, Robert Muir wrote:

> 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
> 

----
T. "Kuro" Kurosaka, 415-227-9600x122, 617-386-7122(direct)




---------------------------------------------------------------------
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