--- title: GeoIndexer keywords: fastai sidebar: home_sidebar nb_path: "nbs/indexers.GeoIndexer.ipynb" ---
{% raw %}
{% endraw %} {% raw %}
{% endraw %}

This module describes the GeoIndexer, a toy example of how we can build an indexer and use it to add new items to the pod.

{% raw %}

class GeoIndexer[source]

GeoIndexer(*args, **kwargs) :: IndexerBase

Adds Countries and Cities to items with a location.

{% endraw %} {% raw %}
{% endraw %}

Usage

This Indexer is super simple, we use it to describe the steps that we need to take to run an Indexer in general. First, lets create a test dataset. We initialize items and add them to an IndexerData object.

{% raw %}
client   = PodClient()

location = Location.from_data(latitude=-37.81, longitude=144.96)
address  = Address.from_data()
address.add_edge("location", location)
data     = IndexerData(items_with_location=[address])
{% endraw %}

And lets initialize an indexer.

{% raw %}
indexer = GeoIndexer.from_data()
indexer_run = IndexerRun.from_data(progress=0, targetDataType="Address")
indexer_run.add_edge("indexer", indexer)
{% endraw %}

Now, we can run the indexer

{% raw %}
items = indexer.index(data, indexer_run)
assert items[0].name == "Australia" and items[1].city == "Melbourne"
indexing 1 items
Loading formatted geocoded file...
{% endraw %}

Finally, lets test the registration of our indexer

{% raw %}
test_registration(GeoIndexer)
{% endraw %}

And we are done, it is as simple as that.