Exemplo n.º 1
0
def search(text):
    # Split the search text into tokens and escape them properly
    tokens = text_to_tokens(text)
    tokens = escape_tokens(tokens)

    # Create combined search query
    query = combined_search_query(MODELS, tokens)

    # Perform query and limit output to 20 items
    results = query.limit(20).all()

    process_result_details(MODELS, results)

    results_json = []
    for r in results:
        result = {
            'type': r.model.lower(),
            'id': r.id,
            'name': r.name,
        }

        if hasattr(r, 'website') and r.website:
            result['website'] = r.website

        if hasattr(r, 'icao') and r.icao:
            result['icao'] = r.icao

        if hasattr(r, 'frequency') and r.frequency:
            result['frequency'] = '%.3f' % (float(r.frequency))

        results_json.append(result)

    return results_json
Exemplo n.º 2
0
def search(text):
    # Split the search text into tokens and escape them properly
    tokens = text_to_tokens(text)
    tokens = escape_tokens(tokens)

    # Create combined search query
    query = combined_search_query(MODELS, tokens)

    # Perform query and limit output to 20 items
    results = query.limit(20).all()

    results = process_results_details(MODELS, results)

    results_json = []
    for r in results:
        result = {
            'type': r['model'].lower(),
            'id': r['id'],
            'name': r['name'],
        }

        if r.get('website'):
            result['website'] = r['website']

        if r.get('icao'):
            result['icao'] = r['icao']

        if r.get('frequency'):
            result['frequency'] = '%.3f' % (float(r['frequency']))

        results_json.append(result)

    return results_json
Exemplo n.º 3
0
def search(text):
    # Split the search text into tokens and escape them properly
    tokens = text_to_tokens(text)
    tokens = escape_tokens(tokens)

    # Create combined search query
    query = combined_search_query(MODELS, tokens)

    # Perform query and limit output to 20 items
    results = query.limit(20).all()

    results = process_results_details(MODELS, results)

    results_json = []
    for r in results:
        result = {
            'type': r['model'].lower(),
            'id': r['id'],
            'name': r['name'],
        }

        if r.get('website'):
            result['website'] = r['website']

        if r.get('icao'):
            result['icao'] = r['icao']

        if r.get('frequency'):
            result['frequency'] = '%.3f' % (float(r['frequency']))

        results_json.append(result)

    return results_json
Exemplo n.º 4
0
def search(text):
    # Split the search text into tokens and escape them properly
    tokens = text_to_tokens(text)
    tokens = escape_tokens(tokens)

    # Create combined search query
    query = combined_search_query(MODELS, tokens)

    # Perform query and limit output to 20 items
    results = query.limit(20).all()

    process_result_details(MODELS, results)

    results_json = []
    for r in results:
        result = {
            'type': r.model.lower(),
            'id': r.id,
            'name': r.name,
        }

        if hasattr(r, 'website') and r.website:
            result['website'] = r.website

        if hasattr(r, 'icao') and r.icao:
            result['icao'] = r.icao

        if hasattr(r, 'frequency') and r.frequency:
            result['frequency'] = '%.3f' % (float(r.frequency))

        results_json.append(result)

    return results_json
Exemplo n.º 5
0
def search(text):
    # Split the search text into tokens and escape them properly
    tokens = text_to_tokens(text)
    tokens = escape_tokens(tokens)

    # Create combined search query
    return combined_search_query(MODELS, tokens)
Exemplo n.º 6
0
def search(text):
    # Split the search text into tokens and escape them properly
    tokens = text_to_tokens(text)
    tokens = escape_tokens(tokens)

    # Create combined search query
    query = combined_search_query(MODELS, tokens)

    # Perform query and limit output to 20 items
    results = query.limit(20).all()

    results = process_results_details(MODELS, results)

    results_json = []
    for r in results:
        result = {"type": r["model"].lower(), "id": r["id"], "name": r["name"]}

        if r.get("website"):
            result["website"] = r["website"]

        if r.get("icao"):
            result["icao"] = r["icao"]

        if r.get("frequency"):
            result["frequency"] = "%.3f" % (float(r["frequency"]))

        results_json.append(result)

    return results_json
Exemplo n.º 7
0
def index(args):
    search_text = args['q']

    # Split the search text into tokens and escape them properly
    tokens = text_to_tokens(search_text)
    tokens = escape_tokens(tokens)

    # Create combined search query
    query = combined_search_query(MODELS, tokens)

    # Perform query and limit output to 20 items
    results = query.limit(20).all()

    results = map(convert, results)

    return jsonify(results)
Exemplo n.º 8
0
def index(args):
    search_text = args['q']

    # Split the search text into tokens and escape them properly
    tokens = text_to_tokens(search_text)
    tokens = escape_tokens(tokens)

    # Create combined search query
    query = combined_search_query(MODELS, tokens)

    # Perform query and limit output to 20 items
    results = query.limit(20).all()

    results = map(convert, results)

    return jsonify(results)
Exemplo n.º 9
0
def index():
    search_text = request.values.get('text', '').strip()
    if not search_text:
        return render_template('search/list.jinja')

    # Split the search text into tokens and escape them properly
    tokens = text_to_tokens(search_text)
    tokens = escape_tokens(tokens)

    # Create combined search query
    query = combined_search_query(MODELS, tokens)

    # Perform query and limit output to 20 items
    results = query.limit(20).all()

    process_result_details(MODELS, results)

    return render_template('search/list.jinja',
                           search_text=search_text,
                           results=results)
Exemplo n.º 10
0
def index():
    search_text = request.values.get('text', '').strip()
    if not search_text:
        return render_template('search/list.jinja')

    # Split the search text into tokens and escape them properly
    tokens = text_to_tokens(search_text)
    tokens = escape_tokens(tokens)

    # Create combined search query
    query = combined_search_query(MODELS, tokens)

    # Perform query and limit output to 20 items
    results = query.limit(20).all()

    process_result_details(MODELS, results)

    return render_template('search/list.jinja',
                           search_text=search_text,
                           results=results)
Exemplo n.º 11
0
 def search_query(self, tokens):
     tokens = escape_tokens(tokens)
     return combined_search_query(MODELS, tokens)
Exemplo n.º 12
0
 def search_query(self, tokens):
     tokens = escape_tokens(tokens)
     return combined_search_query(MODELS, tokens)
Exemplo n.º 13
0
def test_escaping():
    assert escape_tokens([u'hello!']) == [u'hello!']
    assert escape_tokens([u'hello *!']) == [u'hello %!']
    assert escape_tokens([u'hello %!']) == [u'hello \\%!']
    assert escape_tokens([u'hello _!']) == [u'hello \\_!']
Exemplo n.º 14
0
def test_escaping():
    assert escape_tokens([u"hello!"]) == [u"hello!"]
    assert escape_tokens([u"hello *!"]) == [u"hello %!"]
    assert escape_tokens([u"hello %!"]) == [u"hello \\%!"]
    assert escape_tokens([u"hello _!"]) == [u"hello \\_!"]
Exemplo n.º 15
0
def test_escaping():
    eq_(escape_tokens(['hello!']), ['hello!'])
    eq_(escape_tokens(['hello *!']), ['hello %!'])
    eq_(escape_tokens(['hello %!']), ['hello \\%!'])
    eq_(escape_tokens(['hello _!']), ['hello \\_!'])
Exemplo n.º 16
0
def test_escaping():
    eq_(escape_tokens(['hello!']), ['hello!'])
    eq_(escape_tokens(['hello *!']), ['hello %!'])
    eq_(escape_tokens(['hello %!']), ['hello \\%!'])
    eq_(escape_tokens(['hello _!']), ['hello \\_!'])