Geo-filtering gives your app the ability to filter search results by a geographic location (only Earth coordinates are supported currently 🌎). This allows you to surface both semantically relevant and location-aware search results to your users when geography is important, such as brick-and-mortar store searches, concert event searches, and job searches.

If you already have a Private Beta account, go check it out in your Console now! If you aren’t, jump on the waitlist — we’re still onboarding developers as fast as we can, and we’ll let you know when your account is ready!

To implement Geo-Filtering with Objective Search, follow these steps:

1

Add data

Add data to the Object Store
2

Create Index

Build an Index using the data
3

Search Index

Querying the Index to get results

Setup

For this Quickstart, we’ll use the Python SDK, but you can follow along in TypeScript by grabbing our Typescript library. Begin by obtaining an API key and installing the SDK:

To get an API key, join the waitlist.

pip install objective-sdk

Adding data

Implementing geo-filtering is straightforward. Begin by adding Objects to the Object Store that include geographic coordinates. Consider this example where we build a brick-and-mortar restaurant search platform:

from objective import Client as ObjectiveClient

c = ObjectiveClient(api_key="YOUR_API_KEY")

objects = [
    {
        "store_name": "Joan's Giant Burgers",
        "store_photo": "https://t4.ftcdn.net/jpg/01/98/94/15/240_F_198941587_KMXpll1r21FkaST48v5koKT1e7RoZsLj.jpg",
        "coordinates": {
            "lat": 51.524000,
            "lon": -0.158610
        }
    }
    # Additional objects...
]

c.object_store.upsert_objects(objects)

Building an Index

Build an index out of the Objects pushed to the API. Configure your Index to recognize the coordinates field as filterable and designate it as a ‘geo’ field:

index = c.indexes.create_index(
    index_type="multimodal",
    fields={
        "searchable": ["store_name"],
        "crawlable": ["store_photo"],
        "filterable": ["coordinates"],
        "type": {"coordinates": "geo"}
    }
)

index.status(watch=True)

Querying results

Geo-filtering syntax breaks down into the following format: {field_name}:@{latitude},{longitude},{distance_in_meters}. To query within a specific radius:

from objective import Client as ObjectiveClient
import json

c = ObjectiveClient(api_key="YOUR_API_KEY")
index = c.indexes.get_index("INSERT_INDEX_ID_HERE")

results = index.search(
	query="burger restaurant",
  object_fields="*",
	filter_query="coordinates:@51.523160,-0.158070,810"
)

print(json.dumps(results, indent=4))

In our scenario, we’re searching for dining options within 810 meters of 221B Baker St., London (with coordinates 51.523160, -0.158070,810). Imagine finding Joan’s Giant Burgers just a short walk away!

{
    "results": [
        {
            "id": "obj_07bcc8ecc1ed42e3b46c87404ab21122",
            "object": {
                "store_photo": "https://t4.ftcdn.net/jpg/01/98/94/15/240_F_198941587_KMXpll1r21FkaST48v5koKT1e7RoZsLj.jpg",
                "store_name": "Joan's Giant Burgers",
                "coordinates": {
                    "lat": 51.524,
                    "lon": -0.15861
                }
            }
        }
    ],
    "pagination": {
        "pages": 1,
        "page": 1
    }
}

Follow-Up Experiment

Try adjusting the distance in your search to 100 meters. Let us know your findings!

Explore More Resources:

  • managing data via the Object Store APIs
  • configuring indexes via the Index APIs
  • searching and filtering via the Search API

For assistance or inquiries, contact us at [email protected].