MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / search

Function search

21-async/mojifinder/tcp_mojifinder.py:42–53  ·  view source on GitHub ↗
(query: str,  # <1>
                 index: InvertedIndex,
                 writer: asyncio.StreamWriter)

Source from the content-addressed store, hash-verified

40
41# tag::TCP_MOJIFINDER_SEARCH[]
42async def search(query: str, # <1>
43 index: InvertedIndex,
44 writer: asyncio.StreamWriter) -> int:
45 chars = index.search(query) # <2>
46 lines = (line.encode() + CRLF for line # <3>
47 in format_results(chars))
48 writer.writelines(lines) # <4>
49 await writer.drain() # <5>
50 status_line = f'{"─" * 66} {len(chars)} found' # <6>
51 writer.write(status_line.encode() + CRLF)
52 await writer.drain()
53 return len(chars)
54# end::TCP_MOJIFINDER_SEARCH[]
55
56# tag::TCP_MOJIFINDER_MAIN[]

Callers 1

finderFunction · 0.70

Calls 2

format_resultsFunction · 0.90
searchMethod · 0.45

Tested by

no test coverage detected