0

I have one question regarding the search part of mashup. It is almost working as intended, but when I try to search by postal code it works for the first digits (for example: 554), but when I type the next number 5542, the suggestion only shows ” , ,” even if it should match the postal codes starting with 5542 in the database.

I have checked that the url "https://ide50-username.cs50.io/search?q=554 returns the correct JSON data.

Postal code is of type TEXT in my database for simplicity in the search part.

It may seem like it is having problems displaying less than 10 suggestions? Anyone know what is wrong?

Here is my search function:

@app.route("/search")
def search():
"""Search for places that match query."""

q = request.args.get("q") + "%"
result = db.execute("SELECT * FROM places WHERE postal_code LIKE :q OR place_name LIKE :q OR admin_name1 LIKE :q", q=q)

if len(result)>10:
    return jsonify([result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8], result[9]])
else:
    return jsonify([result])
1

Try using the following:

SELECT * FROM places WHERE postal_code LIKE :q OR place_name LIKE :q OR 
admin_name1 LIKE :q LIMIT 0,10
0

I think if fixed the issue now. I removed the brackets from my return jsonify([result]) line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .