lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shai Erera <ser...@gmail.com>
Subject Adding Field twice w/ Payload - bug or works as designed?
Date Thu, 27 Aug 2009 03:51:19 GMT
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

Mime
View raw message