For a real estate website I need to implement a search mechanism that allows to search both for text and distance.
Doing distance calculations on a MySQL table when the lat & lon are recorded in separate columns is easy but a house tends to have a LOT of true/false properties.
I will need to store all those fields in a database because they need to be editable so I intend to use a simple table like | houseID | property | in which I store all properties that are true (set).
That will save me from making a ridiculously wide table with hundreds of columns, but searching this database will not be very feasible.
I have thought about adding a column of type text to each house’s main record that contains the fieldnames of all true properties. I would then search both the human text description and that text column but I feel that’s still not the best approach.
How could I solve this in a clean way?
Thanks in advance!
I would reccomend the
Entity Attribute ValueorEAVmodel of storing data. http://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model (this is how WordPress Posts and Post Meta work).so assuming tables like:
Use a query like this:
that will select entities and their related attributes (has_ac, has_garage, has_fridge, latitude, and longitude) and require that all entities selected will have has_ac equal to 1 (true)
Now for the geo stuff: