Skip to content
Kirsten Thomas edited this page Nov 30, 2016 · 14 revisions

Our website has a search capability. It performs both an OR search and an AND search on the user input.

#Back End

For the OR results, we query each of our tables column's for every term in the user's search using an or_ function. Then add the results to each table's OR set in order to avoid duplicate database objects.

For the AND results, we search the columns of the tables now using the and_ function by passing in a generator for each word in the search string and then unpacking it. We have a separate query for each attribute so that we are scanning through all the data in our database. We then iterate through the lists and add all the database objects to each tables' AND set.

For example

campname = and(*[Campground.name.like('%'+s+'%') for s in descriptivename])_

camp1 = Campground.query.filter(campname).all()

Then we loop through those results and add them to a set set like below

for stuff in camp1:

campsand.add(stuff)

#Front End

For the front end, we wanted to emulate the behavior of Google. When a user enters a search term, their results are displayed in a list format. The matching terms are highlighted in the result. The AND results are displayed above the OR results in hopes of providing more relevant results. When there are more than ten results, the user will click to another page of results.

Clone this wiki locally