Beispiel #1
0
async def search(query: str, index: InvertedIndex, writer: asyncio.StreamWriter) -> int:
    chars = index.search(query)
    lines = (line.encode() + CRLF for line in format_results(chars))
    writer.writelines(lines)
    await writer.drain()
    writer.write(f"{'-'*66}".encode() + CRLF + f"{len(chars)} founded".encode() + CRLF)
    await writer.drain()
    return len(chars)
async def search(
        query: str,  # <1>
        index: InvertedIndex,
        writer: asyncio.StreamWriter) -> int:
    chars = index.search(query)  # <2>
    lines = (
        line.encode() + CRLF for line  # <3>
        in format_results(chars))
    writer.writelines(lines)  # <4>
    await writer.drain()  # <5>
    status_line = f'{"─" * 66} {len(chars)} found'  # <6>
    writer.write(status_line.encode() + CRLF)
    await writer.drain()
    return len(chars)