I have successfully implemented search in application.py. Though ss I was testing through the app, I noticed that every search was really slow.
It's turns out that every search request was from 63KB up to 1.1MB, where in staff's implementation the largest request is 817 B (according to Network Tab in Chrome Tab).
My code:
@app.route("/search")
def search():
"""Search for places that match query."""
# Raise exception if no args is passed
if not request.args.get('q'):
raise RuntimeError("missing query")
# Save query and concatenate SQL wildcard character "%""
q = request.args.get('q') + "%"
results = db.execute("SELECT * FROM places WHERE \
(postal_code LIKE :q \
OR place_name LIKE :q \
OR admin_name1 LIKE :q \
OR admin_code1 LIKE :q)", q=q)
return jsonify(results)
Then I reduced my search to only two out of four database columns, postal_code
and place_name
and the requests' size reduced: 572 KB when I start a query and smaller for every new letter in query up to 991 B. But still far from the staff's solution.
- How do the numbers of columns I search to affects the request size?
- Why does my query creates smaller request size as I write (big for first letter, smaller and smaller for the next ones)?
- How may I reach the performance of staff's solution. Is it possible that full-text searches may do the trick?