code: def test_lengths():
      s = fields.Schema(
          f1=fields.KEYWORD(stored=True, scorable=True),
          f2=fields.KEYWORD(stored=True, scorable=True),
      )
      with TempIndex(s, "testlengths") as ix:
          w = ix.writer()
          items = u("ABCDEFG")
          from itertools import cycle, islice
  
          lengths = [10, 20, 2, 102, 45, 3, 420, 2]
          for length in lengths:
              w.add_document(
                  f2=u(" ").join(islice(cycle(items), length))
              )
          w.commit()
  
          with ix.reader() as dr:
              ls1 = [
                  dr.doc_field_length(i, "f1")
                  for i in xrange(0, len(lengths))
              ]
              assert ls1 == [0] * len(lengths)
              ls2 = [
                  dr.doc_field_length(i, "f2")
                  for i in xrange(0, len(lengths))
              ]
              assert ls2 == [
                  byte_to_length(length_to_byte(l)) for l in lengths
              ]
  
imports: from __future__ import with_statement
  import random
  from collections import defaultdict
  from datetime import datetime
  import pytest
  from whoosh import analysis, fields, index, qparser, query, __version__
  from whoosh.compat import b, u, xrange, text_type, permutations
  from whoosh.filedb.filestore import RamStorage
  from whoosh.writing import IndexingError
  from whoosh.util.numeric import length_to_byte, byte_to_length
  from whoosh.util.testing import TempIndex, TempStorage
label_desc: Use image node_id 6 for calling a global function with example usage: test_lengths() without return types