code: def test_termdocs2():
      schema = fields.Schema(key=fields.TEXT, city=fields.ID)
      ix = RamStorage().create_index(schema)
      with ix.writer() as w:
          w.add_document(key="ant", city="london")
          w.add_document(key="anteater", city="roma")
          w.add_document(key="bear", city="london")
          w.add_document(key="bees", city="roma")
          w.add_document(key="anorak", city="london")
          w.add_document(key="antimatter", city="roma")
          w.add_document(key="angora", city="london")
          w.add_document(key="angels", city="roma")
  
      with ix.searcher() as s:
          # A query that matches the applicable documents
          cond_q = query.Term("city", "london")
          # Get a list of the documents that match the condition(s)
          cond_docnums = set(cond_q.docs(s))
          # Grab the suggestion field for later
          field = s.schema["key"]
  
          terms = []
          # Expand the prefix
          for term in s.reader().expand_prefix("key", "an"):
              # Get the documents the term is in
              for docnum in s.document_numbers(key=term):
                  # Check if it's in the set matching the condition(s)
                  if docnum in cond_docnums:
                      # If so, decode the term from bytes and add it to the list,
                      # then move on to the next term
                      terms.append(field.from_bytes(term))
                      break
          assert terms == ["angora", "anorak", "ant"]
  
file_path: whoosh/tests/test_collector.py
imports: from __future__ import with_statement
  import pytest
  from whoosh import collectors, fields, query, searching
  from whoosh.compat import u, xrange
  from whoosh.filedb.filestore import RamStorage
  from whoosh.util.testing import TempIndex
label_desc: Use image node_id 7 for calling a global function with example usage: test_termdocs2() without return types