예제 #1
0
파일: ajax.py 프로젝트: nanfang/lvtuso
def _find_places_by_ids(ids):
    redis = storage.get_redis()
    places = redis.hmget(STORE_KEYS.PLACE_INFO, [int(id) for id in ids])
    places = [json.loads(p) for p in places]
    for idx, p in enumerate(places):
        p.insert(1, ids[idx])
    return places
예제 #2
0
    def handle(self, *args, **options):
        conn = storage.get_conn()
        redis = storage.get_redis()
        cursor = conn.cursor()
        cursor.execute('SELECT id, name, hot, rating FROM place_mfw')
        for id, name, hot, rating in cursor:
            info = [name, hot, rating]
            redis.hset(STORE_KEYS.PLACE_INFO, str(id), json.dumps(info))

            prefixes = _extract_prefixes(name)
            score = _score(hot, rating)
            for prefix in prefixes:
                redis.zadd(STORE_KEYS.PLACE_TYPE_AHEAD % prefix, score, id)
                print('%s %s %s' % (prefix, score, id))
예제 #3
0
파일: ajax.py 프로젝트: nanfang/lvtuso
def _prefix_search_places(prefix):
    prefix = prefix.strip() if prefix else None
    if not prefix:
        return []
    redis = storage.get_redis()
    return _find_places_by_ids(redis.zrevrange(STORE_KEYS.PLACE_TYPE_AHEAD % prefix, 0, 20))