Welcome Guest, Not a member yet? Register   Sign In
Advanced Search
#1

[eluser]doubleplusgood[/eluser]
Hi there,

I'm building a site where authors can list vehicles on the site. The publish form will have all sorts of options such as Make, Model, Engine Size, Number of doors etc.

My next task is to build an advanced search where people can find cars near them (postcode search) and also select matching options such as the make, model, engine size and so on,

I was wondering if anyone has built something similar? I have searched around on the internet for some examples of an advanced search with results based on distance, but could not find anything suitable.

If anyone knows of any links or code samples for something like this, please let me know.

Cheers.
#2

[eluser]dmorin[/eluser]
There are kind of two questions mixed in here and I'm not sure if you need help with one or both. The first seems to be advanced search involving multiple (likely optional) fields. In this case, I would highly recommend taking the easiest approach at first and just having your script build a query based on the options that the user selects. If most of your fields are dropdowns, which it seems like they should be, this shouldn't be very hard at all and will scale for a while.

The second question seems to be about location based search. I've only done this once, and in my approach, I converted everything to Lat/Lon which you can then use in queries and calculations to determine approximate distances. You may want to checkout something like http://ipinfodb.com/ip_database.php which has zipcodes and Lat/Lon. From there, I would use a bounding box to remove any results more than a certain lat/lon away from the search, and then use something like Haversine Formula to reduce the set further if needed and to generate the distance. See http://www.movable-type.co.uk/scripts/latlong.html for a bit more info on the calculation.

If you have more specific questions, let us know.
#3

[eluser]doubleplusgood[/eluser]
@dmorin

Thanks very much for the reply. The search would involve several optional fields. So a user could potentially choose Make and Model from two dropdowns and then perhaps checkboxes or radio buttons for other options.

The location based search, I was thinking of doing something like find results within X miles of my postcode. Not sure how easy this might be to implement. Obviously the Lat/Lon search would be more accurate.
#4

[eluser]dmorin[/eluser]
Ok, so for the search with optional fields, that's fairly straightforward. Do you still have questions about that?

For the location search, X miles from my postcode seems creasonable. The problem is that you can't do anything useful with zip codes to find distances without first converting them to lat/lng which you can do by looking up the zip code in the db from the link I included in the previous post. You can do the same for each vehicle that is submitted to the site and store the lat/lng for them in which case you're have lat/lng for the search and lat/lng for each vehicle which you can then use to calculate distance using the Haversine Formula that I mentioned.

Let us know if you have specific follow up questions and I'll see what I can elaborate on.




Theme © iAndrew 2016 - Forum software by © MyBB