Ohh, right. I missed that. Indeed after I call nextPosition again, it prints
1. Thanks !

Shai

On Thu, Aug 27, 2009 at 7:09 AM, Michael Busch <busch...@gmail.com> wrote:

> The first occurrence of your term does not have a payload, the second one
> does. So getPayloadLength() correctly returns 0, because the TermPositions
> is at the first occurrence. If you call nextPosition() again and then dump
> the payload length it should be 1.
>
>  Michael
>
>
> On 8/26/09 8:51 PM, Shai Erera wrote:
>
>> Hi
>>
>> I don't know if it's supported or not, but I wrote the following simple
>> example code to describe what I want.
>>
>>    Directory dir = new RAMDirectory();
>>    Analyzer a = new SimpleAnalyzer();
>>    IndexWriter writer = new IndexWriter(dir, a, MaxFieldLength.UNLIMITED);
>>    Document doc = new Document();
>>    doc.add(new Field("a", "abc", Store.NO, Index.NOT_ANALYZED));
>>    final Term t = new Term("a", "abc");
>>    doc.add(new Field(t.field(), new TokenStream() {
>>      boolean done = false;
>>      @Override
>>      public Token next(Token reusableToken) throws IOException {
>>        if (done) return null;
>>        done = true;
>>        reusableToken.setTermBuffer(t.text());
>>        reusableToken.setPayload(new Payload(new byte[] { 1 }));
>>        return reusableToken;
>>      }
>>    }));
>>    writer.addDocument(doc);
>>    writer.commit();
>>    writer.close();
>>
>>    IndexReader reader = IndexReader.open(dir, true);
>>    TermPositions tp = reader.termPositions(t);
>>    tp.next();
>>    tp.nextPosition();
>>    System.out.println(tp.getPayloadLength());
>>    reader.close();
>>
>> Basically, I add the same Field twice (a:abc), the second time I just set
>> a Payload. The program prints 0 as the payload length (1 line above the
>> last). If I change either the field name or field text, it prints 1.
>>
>> Bug or works as designed?
>>
>> Shai
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscr...@lucene.apache.org
> For additional commands, e-mail: java-dev-h...@lucene.apache.org
>
>

Reply via email to