Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-5977

IW should safeguard against token streams returning invalid offsets for multi-valued fields


    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.9, 4.9.1, 4.10, 4.10.1
    • 4.10.2, 5.0, 6.0
    • None
    • None
    • New


      We have a custom token stream that emits information about offsets of each token. My (wrong) assumption was that for multi-valued fields a token stream's offset information is magically shifted, much like this is the case with positions. It's not the case – offsets should be increasing and monotonic across all instances of a field, even if it has custom token streams. So, something like this:

              doc.add(new Field("field-foo", new CannedTokenStream(token("bar", 1, 150, 160)), ftype));
              doc.add(new Field("field-foo", new CannedTokenStream(token("bar", 1,  50,  60)), ftype));

      where the token function is defined as:

      token(String image, int positionIncrement, int startOffset, int endOffset)

      will result in either a cryptic assertion thrown from IW:

      Exception in thread "main" java.lang.AssertionError
      	at org.apache.lucene.index.FreqProxTermsWriterPerField.writeOffsets(FreqProxTermsWriterPerField.java:99)

      or nothing (or a codec error) if run without assertions.

      Obviously returning non-shifted offsets from subsequent token streams makes little sense but I wonder if it could be made more explicit (or asserted) that offsets need to be increasing between multiple-values. The minimum is to add some documentation to OffsetAttribute. I don't know if offsets should be shifted automatically, as it's the case with positions – this would change the semantics of existing tokenizers and filters which implement such shifting internally already.


        1. LUCENE-5977.patch
          6 kB
          Robert Muir



            Unassigned Unassigned
            dweiss Dawid Weiss
            0 Vote for this issue
            3 Start watching this issue