-
Notifications
You must be signed in to change notification settings - Fork 48
Search Capabilities
Our approach to searching which attributes match a given set of search terms involved parsing the JSON file for each model and determining which attributes had properties matching any of the search terms. In order to display which attributes matched the most search terms, we kept track of how many search terms each attribute matched and then sorted the results based on this number. We also kept track of which properties of each attribute matched a search term so that we could highlight them when the search results were displayed on the web page. In order to allow for searching of numbers, we return any results within 10 for horsepower and torque or 1000 for price.
Thankfully we didn't have to change much for the search capabilities to work in the front-end. Using AngularJS and basic html we were able to display the result JSON object in our search.html. The way we did it was to make a index.html have the search bar in the navigation bar as a text box and for it to call a method called search() when the enter key was pressed. the method search() grabs the string that it has, parses it and performs the query and returns the information as a JSON. This function was declared in the index controller in app.js. The index controller collects the data from the query and stores it in the global variable rootScope. We then reload the route variable so that it refreshes the controller that it is in. This refresh helps the user perform several searches without having to leave the search page. Finally the index controller changes the path to the search website adding the queried terms at the end.
The Search controller is a mixture of the Manufacturer, Car and Engine controller since it displays information from all these tables. It implements the goto methods for each model so that the user can click on any item and go to its specific page.
We ran into several problems with the search function since it involves one controller inside of another, the search controller inside of the index controller, and we had race conditions. The search controller would run before the index controller had time to load the data. We fixed this issue by using the global variable rootScope in both of them, since it is the only info that will be displayed.