On Wed, Jan 22, 2014 at 12:09 PM, Michael McCandless
<luc...@mikemccandless.com> wrote:

Hi,

> DocsAndPositionsEnum.getPayload() is allowed to re-use the returned
> BytesRef under the hood.

Ah, I am starting to get it. The BytesRef would be directly stored in
the key set of the map, but since its properties can change, then I
can imagine how this can invalidate the hash table.

In fact, I do not use DocsAndPositionsEnum.getPayload(), but I believe
that the way I have set up presents the same behavior that the one you
have described. I need the payload of the matched token in my custom
collector, so I simply extended the DefaultSimilarity (making the new
similarity aware of my custom collector), and passed the payload to
the collector in the scorePayload() method.

> So, if you want to hold a copy of the payload across two or more calls
> to .getPayload you'll have to make a deep copy of
> (BytesRef.deepCopyOf) the returned BytesRef yourself.

This is actually what I was doing in my workaround, except that I'd
use copyBytes directly, prior to putting the entry in the map. It
somehow worked by coincidence.

Cheers all for your time and replies, it is really appreciated.

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

Reply via email to