user2216267
user2216267

Reputation: 491

how to filter according location in freebase?

i have been trying to filter the suggestions according to location but unsuccessful. i want to show all locations, city , town, villages of country : India

what changes should i do to the below code for it ?

<script type="text/javascript">
$("#myinput")
  .suggest({
    "key": "my key",
  filter: '(any type:/location/location )'

  })
 .bind("fb-select", function(e, data) {
   alert(data.name + ", " + data.id + " (" + data['n:type'].name + ")");
});
      </script>

Upvotes: 1

Views: 313

Answers (2)

Tom Morris
Tom Morris

Reputation: 10540

Shawn's approach will work for topics which have the containment properties set up correctly, but I'm not sure how good the coverage is there. I suspect simple geo data (lat/lon) coverage is better. If you want to just filter on distance from the centroid of India, you could do something like:

filter=(all type:/location/location (within radius:500km+lon:82.7948 lat:21.7866))

https://www.googleapis.com/freebase/v1/search?indent=true&filter=%28all+type%3A/location/location+%28within+radius%3A500km+lon%3A82.7948+lat%3A21.7866%29%29&output=%28geocode%29

Note that this is very sketchily documented and I'm not sure whether that means it's brand new and the documentation isn't finished or deprecated and about to go away.

Upvotes: 1

Shawn Simister
Shawn Simister

Reputation: 4603

The way to do this with a search filter is to use the part_of Metaschema predicate like this:

<script type="text/javascript">
$("#myinput")
  .suggest({
    "key": "my key",
  filter: '(all type:/location/location part_of:/m/03rk0)'

  })
 .bind("fb-select", function(e, data) {
   alert(data.name + ", " + data.id + " (" + data['n:type'].name + ")");
});
</script>

The part_of Metaschema predicate is transitive which means that it matches Freebase topics that are part_of India (/m/03rk0) or part_of a location which is part_of India, etc.

Upvotes: 1

Related Questions