コード例 #1
0
 def cleanup():
     conn = get_redis_connection()
     _delete_test_keys(app_config.key_prefix, conn)
コード例 #2
0
import click
import logging
import redis

from sitesearch.config import AppConfiguration
from sitesearch.transformer import transform_documents
from sitesearch.connections import get_search_connection, get_redis_connection
from sitesearch.query_parser import parse

config = AppConfiguration()
client = get_search_connection(config.default_search_site)
redis_client = get_redis_connection()
log = logging.getLogger(__name__)


@click.argument("query")
@click.command()
def search(query):
    q = parse(query, config.default_search_site.synonym_groups)

    try:
        res = client.search(q)
    except redis.exceptions.ResponseError as e:
        log.error("Search query failed: %s", e)
        total = 0
        docs = []
    else:
        total = res.total
        docs = transform_documents(res.docs)

    print(f"Hits: {total}")
コード例 #3
0
def redis():
    yield get_redis_connection()