0

I found the search query a little bit complicated, in the sense it can be difficult to adjust it to the user's input.

For example, how do I permit the user to enter the parameters in different order without "hardcoding" the position of the parameters. Something like this:

q = request.args.get("q") + "%"
q = q.split(",")

if len(q) == 1:

    # Make a query on db with "q" and save it to "results" 
    results = db.execute("SELECT * FROM places WHERE postal_code LIKE :q0 OR place_name LIKE :q0 OR admin_name1 LIKE :q0", q0=q[0])

elif len(q) == 2:

    results = db.execute("SELECT * FROM places WHERE place_name LIKE :q0 AND admin_name1 LIKE :q1", q0=q[0], q1=q[1])

elif len(q) == 3:

    results = db.execute("SELECT * FROM places WHERE place_name LIKE :q0 OR admin_name1 LIKE :q1 OR place_name LIKE :q2", q0=q[0], q1=q[1], q2=q[2])      

I was reading the FTS way that you reccomend, but I don't know if I'm complicating too much the solution with a normal query.

PD: I understand that the user will not send a query like

http://mashup.cs50.net/search?q=massa

but I'm testing the app and I don't think my solution will adapt the user's input in an efficient way.

Thanks!

2
  • What do you mean by this? Wouldn't just using the query once be enough? It would automatically look in the whole table finding the search term anyway even though whatever format it may be? I mean yes it's a bit slow but it works? Jun 28, 2018 at 0:05
  • I was trying to comply with this. How I specify in the PD, it's obvious the user will not enter a place like "New Haven, Connecticut, US", but I wasn't secure of that until I advanced to the Javascript file and tried my app with the suggestions. Jun 29, 2018 at 10:45

1 Answer 1

0

I think that I overcomplicated the task (as usual), trying to comply with this.

I suggest you guide through the usability of cs50's mashup, and then try to improve your code.

You must log in to answer this question.

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