(query: str, # <1>
index: InvertedIndex,
writer: asyncio.StreamWriter)
| 40 | |
| 41 | # tag::TCP_MOJIFINDER_SEARCH[] |
| 42 | async 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[] |
no test coverage detected