Пример #1
0
def prefix_search(args):
    start = int(args.get('start', 0))
    limit = int(args.get('limit', 20))
    
    fq = []
    if 'type' in args:
        type_ = args.get('type').strip().lstrip('/')
        fq.append('+__type__:"%s"' % type_)
    
    qs = args.get('prefix', '').strip()
    qs = qs + "^%d" % (len(qs)/2)
    results = Type.find(qs, fq, start=start, rows=limit)
    matches = []
    for result in results.get('response', {}).get('docs', []):
        id = url_for('entity', type=result.get('__type__'),
                key=result.get('__key__'))
        matches.append({
            'name': result.get('title'),
            'n:type': {
                'id': '/' + result.get('__type__'),
                'name': result.get('__type__')
                },
            'r:score': result.get('score'),
            'id': id,
            'type': ['foo']
            })
    return {
        "code" : "/api/status/ok",
        "status" : "200 OK",
        "prefix" : args.get('prefix'),
        "result" : matches
        }
Пример #2
0
def prefix_search(args):
    start = int(args.get('start', 0))
    limit = int(args.get('limit', 20))

    fq = []
    if 'type' in args:
        type_ = args.get('type').strip().lstrip('/')
        fq.append('+__type__:"%s"' % type_)

    qs = args.get('prefix', '').strip()
    qs = qs + "^%d" % (len(qs) / 2)
    results = Type.find(qs, fq, start=start, rows=limit)
    matches = []
    for result in results.get('response', {}).get('docs', []):
        id = url_for('entity',
                     type=result.get('__type__'),
                     key=result.get('__key__'))
        matches.append({
            'name': result.get('title'),
            'n:type': {
                'id': '/' + result.get('__type__'),
                'name': result.get('__type__')
            },
            'r:score': result.get('score'),
            'id': id,
            'type': ['foo']
        })
    return {
        "code": "/api/status/ok",
        "status": "200 OK",
        "prefix": args.get('prefix'),
        "result": matches
    }