I have a table which contains a location of all geographical locations in the world and their relationships.
Here is a example that shows the hierarchy. You will see that the data is actually stored as all three
- Enumerated Path
- Adjacency list
- Nested Set
The data obviously never changes either. Below is an example of direct ancestors of the location Brighton in England which has a woeid of 13911.
Table: geoplanet_places
(Has 5.6million rows)
Large Image: http://chrisacky.com/ancestors.jpg
I then have another table called entities
. This table stores my items which I would like to map to a geographical location. I store some basic information but most important I store the woeid
which is a foreign key from geoplanet_places
.
Eventually the entities
table will contain several thousand entities. And I would like a way to be able to return a full tree of all of the nodes which contain entities.
I plan on creating something to facilitate the filtering and searching of entities based on their geographical location and be able to discover how many entities can be found on that particular node.
So if I only have one entity in my entities
table, I might have something like this
`Earth (1)
United Kingdom (1)
England (1)
East Sussex (1)
Brighton and Hove City (1)
Brighton (1)`
Lets then say that I have another entity which is located in Devon, then it would show something like:
Earth (2)
United Kingom (2)
England (2)
Devon (1)
East Sussex (1) ... etc
The (Counts) which will say how many entities are "inside" of each geographical location do not need to be live. I can live with generating my object every hour and caching it.
The aim, is to be able to create an interface which might start out showing only the Countries which have entities..
So like
Argentina (1021)
, Chile (291)
, ...
, United States (32,103)
, United Kingdom (12,338)
Then the user will click on a location, such as United Kindom, and will then be given all of the immediate child nodes which are descendants of United Kingdom AND have an entity in them.
If there are 32 Counties in United Kindgdom, but only 23 of them eventually when you drill down have entities stored in them, then I don't want to display the other 9. It is only locations.
This site aptly demonstrates the functionality that I wish to achieve: http://www.homeaway.com/vacation-rentals/europe/r5
How do you recommend that I manage such a data structure?
Things I am using.
- PHP
- MySQL
- Solr
I plan on having the Drill downs be as rapid as possible. I want to create an AJAX interface that will be seemless for searching.
I would also be interested to know which columns you would recommend indexing on.