glendango Posted May 13, 2019 Share Posted May 13, 2019 (edited) Hi, i'am looking for best practices in 2019 for Search on a website. Very similar to rightmove / zoopla etc. 1) They allow the user to search by county / postcode / town. How is this list populated in the drop down? is it a list of towns in a plugin which are then used as variables to populate the mysql select query,, or is it ajax populating the search input with a call to the db... Reason iam confused it i know of a site with no property in a certain area but the list still predicts the area ...i.e. if no matching address is in the db how is it populating? 2) they also have a search function that once the user has arrived on the page by postcode..users are able to search 1/4 mile 1/2 mile radius etc from the postcode for other properties... how is this working? thx for your time in advance . in the jpeg i show the search box...when user types 'lon' it brings up everything with lon in title i.e london, londonderry, long meadow etc Edited May 13, 2019 by glendango Quote Link to comment https://forums.phpfreaks.com/topic/308702-best-practice-for-searching-on-a-website/ Share on other sites More sharing options...
requinix Posted May 13, 2019 Share Posted May 13, 2019 1 hour ago, glendango said: 1) They allow the user to search by county / postcode / town. How is this list populated in the drop down? is it a list of towns in a plugin which are then used as variables to populate the mysql select query,, or is it ajax populating the search input with a call to the db... Reason iam confused it i know of a site with no property in a certain area but the list still predicts the area ...i.e. if no matching address is in the db how is it populating? They have a big database of locations. Probably purchased from and/or subscribed to a service that tracks stuff like that so they don't have to try to stay up to date themselves. Quote 2) they also have a search function that once the user has arrived on the page by postcode..users are able to search 1/4 mile 1/2 mile radius etc from the postcode for other properties... how is this working? They know the latitude and longitude of an address, also probably from a third-party service (eg, Google Maps). A postcode has a location too, though it's obviously not quite as precise. Then they can do some pretty simple math to estimate the distance between the two points. 1 Quote Link to comment https://forums.phpfreaks.com/topic/308702-best-practice-for-searching-on-a-website/#findComment-1566648 Share on other sites More sharing options...
glendango Posted May 13, 2019 Author Share Posted May 13, 2019 They have a big database of locations. Probably purchased from and/or subscribed to a service that tracks stuff like that so they don't have to try to stay up to date themselves. interesting. so do you think they use Ajax to get the locations from a database or would it be an API.... once a user selects e.g. Islington, London . does this then add that as a $variable to a select statement to the database to create a list of properties on the next page ? $location = islington select * from table where $location Quote Link to comment https://forums.phpfreaks.com/topic/308702-best-practice-for-searching-on-a-website/#findComment-1566650 Share on other sites More sharing options...
Barand Posted May 13, 2019 Share Posted May 13, 2019 If ($lat, $lng) is the centre of the postcode area, then this will find the locations of properties within $d Km select lat, lng from properties where pow(lat-$lat, 2) + pow((lng-$lng)*cos(radians($lat)), 2) < pow($d/110.25, 2) 1 Quote Link to comment https://forums.phpfreaks.com/topic/308702-best-practice-for-searching-on-a-website/#findComment-1566651 Share on other sites More sharing options...
glendango Posted May 13, 2019 Author Share Posted May 13, 2019 (edited) nice,,so i can set the radius from the selected lat/long of the properties. Rightmove only lets you search minimum 1/4 mile radius which is to large... 1/8 mile be ideal. Edited May 13, 2019 by glendango Quote Link to comment https://forums.phpfreaks.com/topic/308702-best-practice-for-searching-on-a-website/#findComment-1566653 Share on other sites More sharing options...
Barand Posted May 13, 2019 Share Posted May 13, 2019 I agree, I like furlongs. Quote Link to comment https://forums.phpfreaks.com/topic/308702-best-practice-for-searching-on-a-website/#findComment-1566654 Share on other sites More sharing options...
requinix Posted May 13, 2019 Share Posted May 13, 2019 36 minutes ago, glendango said: interesting. so do you think they use Ajax to get the locations from a database or would it be an API.... AJAX is a way for the browser to get something from the server without having to refresh the page. An API is merely what tells two things how to talk to each other. Since they won't want to put every location onto the page (probably), yes: they will use AJAX to ask the server for a list of locations matching what the user types. Quote once a user selects e.g. Islington, London . does this then add that as a $variable to a select statement to the database to create a list of properties on the next page ? $location = islington select * from table where $location Something like that. Quote Link to comment https://forums.phpfreaks.com/topic/308702-best-practice-for-searching-on-a-website/#findComment-1566655 Share on other sites More sharing options...
glendango Posted May 13, 2019 Author Share Posted May 13, 2019 (edited) furlongs lol... 'something like that' anyone care to look at rightmove and tell me what the hell is going on under the hood? could be ' typeahead' j.s . with a json file of postcodes and counties,.Could be ajax calling the locations from the database... just because i type ajax into google doessnt mean that is the correct way to do it... sweet jesus mother of god.... its like getting blood from bent coppers round here, so it is Edited May 13, 2019 by glendango Quote Link to comment https://forums.phpfreaks.com/topic/308702-best-practice-for-searching-on-a-website/#findComment-1566678 Share on other sites More sharing options...
Barand Posted May 13, 2019 Share Posted May 13, 2019 Furlongs are nice, round unit of measure (1 furlong = 10 cricket pitches) I can't see Rightmove's code any better than you can. Quote Link to comment https://forums.phpfreaks.com/topic/308702-best-practice-for-searching-on-a-website/#findComment-1566682 Share on other sites More sharing options...
glendango Posted May 13, 2019 Author Share Posted May 13, 2019 Any more cheek and i'll throw the book at you , so i will. Quote Link to comment https://forums.phpfreaks.com/topic/308702-best-practice-for-searching-on-a-website/#findComment-1566683 Share on other sites More sharing options...
Barand Posted May 13, 2019 Share Posted May 13, 2019 View the rightmove page with your browser's developer tool/network tab open and watch the ajax calls Quote Link to comment https://forums.phpfreaks.com/topic/308702-best-practice-for-searching-on-a-website/#findComment-1566684 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.