A tiny text index records which documents contain an exact word.

exact-word search Splitting text into words makes an exact membership test visible in the trace.

Text Index

term
text_index.py
Replay: real traced execution (multi-file project)
documents = [
    "trace source code",
    "source replay view",
    "static trace page",
]

term = "trace"

matches = []
for number, text in enumerate(documents, start=1):
    words = text.split()
    if term in words:
        matches.append(str(number))

print("matches=" + ",".join(matches))
documents = [
    "trace source code",
    "source replay view",
    "static trace page",
]

term = "source"

matches = []
for number, text in enumerate(documents, start=1):
    words = text.split()
    if term in words:
        matches.append(str(number))

print("matches=" + ",".join(matches))
  1. documents ← ['trace source code', 'source replay view', 'static trace page']

    1documents→ ['trace source code', 'source replay view', 'static trace page'] = [2    "trace source code",3    "source replay view",4    "static trace page",5]67term→ trace = "trace"  #@term="source"89matches→ [] = []10for number, text in enumerate(documents, start=1):
  2. words ← ['trace', 'source', 'code']

    pass 1 of 3
    9matches = []10for number1, texttrace source code in enumerate(documents['trace source code', 'source replay view', 'static trace page'], start=1):11    words→ ['trace', 'source', 'code'] = texttrace source code.split()12    if term in words:
    All 3 passes — pass 1 is the card above
    passnumbertexttermwordsmatches
    11trace source codetrace['trace', 'source', 'code'][] ['1']
    22source replay view['source', 'replay', 'view']
    33static trace pagetrace['static', 'trace', 'page']['1'] ['1', '3']
  3. matches ← ['1']

    pass 1 of 2
    11words = text.split()12if termtrace in words['trace', 'source', 'code']:13    matches→ ['1'].append(str(number1))
  4. matches ← ['1', '3']

    pass 2 of 2
    11words = text.split()12if termtrace in words['static', 'trace', 'page']:13    matches→ ['1', '3'].append(str(number3))
  5. print("matches=" + ",".join(matches))

    15print("matches=" + ",".join(matches['1', '3']))
    outputmatches=1,3
  1. documents ← ['trace source code', 'source replay view', 'static trace page']

    1documents→ ['trace source code', 'source replay view', 'static trace page'] = [2    "trace source code",3    "source replay view",4    "static trace page",5]67term→ source = "source"89matches→ [] = []10for number, text in enumerate(documents, start=1):
  2. words ← ['trace', 'source', 'code']

    pass 1 of 3
    9matches = []10for number1, texttrace source code in enumerate(documents['trace source code', 'source replay view', 'static trace page'], start=1):11    words→ ['trace', 'source', 'code'] = texttrace source code.split()12    if term in words:
    All 3 passes — pass 1 is the card above
    passnumbertexttermwordsmatches
    11trace source codesource['trace', 'source', 'code'][] ['1']
    22source replay viewsource['source', 'replay', 'view']['1'] ['1', '2']
    33static trace page['static', 'trace', 'page']
  3. matches ← ['1']

    pass 1 of 2
    11words = text.split()12if termsource in words['trace', 'source', 'code']:13    matches→ ['1'].append(str(number1))
  4. matches ← ['1', '2']

    pass 2 of 2
    11words = text.split()12if termsource in words['source', 'replay', 'view']:13    matches→ ['1', '2'].append(str(number2))
  5. print("matches=" + ",".join(matches))

    15print("matches=" + ",".join(matches['1', '2']))
    outputmatches=1,2