< Back

Geo-Search on steroid!

Geo-search is playing an important role in user experience, especially on mobile applications. Therefore we’ve never stopped challenging it and we are excited today to announce a big improvement!

This new geo-search release simplifies most of the use cases, adds several features, and maintains backward-compatibility! And because we are hardcore when it comes to performance, we’ve made sure this update won’t impact anything. Better yet, all queries will actually be faster!

 

auto-radius

The end of the radius pain!

The most used geo-search feature was the retrieval of records around a specific geolocation. It is widely used by mobile applications via the device’s GPS position. On browsers, you can use our IP based geolocation feature. This feature requires a maximum distance called “radius” to perform the search, which was set by default to 10km. Because radius has an impact on performance, it is important to keep it low. In reality, it may become extremely cumbersome for our users to set it as the radius would depend on the area’s information density!

Fortunately, we have removed this pain in our new geo-search! While you can still manually define the radius, you can now let the system adjust it according to the density of the area for you … without doing anything! Just leave the aroundRadius query parameter unset! The radius will adapt itself to collect a few thousand records. Its value will also be returned in the result set (in the automaticRadius attribute). This information can help you display your map at the best scale. If you want to have a minimum radius size, we also introduced a query parameter called minimumAroundRadius that configures the minimum value that can be accepted as a radius.

We hope this new feature will help you and will make it super easy to have a good geo-search!

 

multi-geo

Several geolocations per record

Our previous geo-search was limited to only one geolocation per record. No more! Our new version now supports an arbitrary number of geolocations per record. You have just to use an array syntax.

Example of a record with one geolocation:


{
    "title": "Example",
    "_geoloc": { "lat": 47.279430, "lng": 5.106450 }
}

Example of a record with several geolocations:


{
    "title": "Example",
    "_geoloc": [
        { "lat": 47.279430, "lng": 5.106450 },
        { "lat": 47.293228, "lng": 5.004570 },
        { "lat": 47.316669, "lng": 5.016670 }
    ]
}

If your records contain several geolocations, you will be able to retrieve the matched geolocation and the distance in meters by requesting the ranking information (getRankingInfo=true query parameter).

Here is an example of a hit with several geolocations:


{
    "title": "Example",
    "objectID": "20",
    [...]
    "_rankingInfo": {
        [...]
        "matchedGeoLocation": {
            "lat": 47.316669,
            "lng": 5.016670,
            "distance": 1257
        }
    }
}

 

polygon-or

New ways to filter

In the past months, we have received several requests to improve the number of operators supported to filter by geolocation. We were only supporting filtering by a bounding box but we are now excited to offer three new types of filtering!

  • Filter by a polygon (defined by a list of point), you can look at the documentation of the insidePolygon query parameter
  • Filter by a OR between several bounding boxes, you have just to pass several times the insideBoundingBox query parameter
  • Filter by a OR between several polygons, you have just to pass several times the insidePolygon query parameter

We need your feedback!

We see an increasing number of users having geo-search needs, especially on mobile. We hope you will like this big evolution of our geo-search feature and that it will simplify your life! We would love to have your feedback and ideas on how to improve it, feel free to contact us anytime!

Get started with our tutorial

  • Huy Nguyễn

    Great improvements. Good job guys.

  • SeanCheng

    Hi, “automaticRadius” is a really useful feature for geo search. However, the radius range is determined by this: “The radius will adapt itself to collect a few thousand records. ” In my case, i might only want to collect twenty to hundreds results. Thousand records is way too much. Is there a setting parameter so that I can determine how many records is “enough” for automaticRadius?

    Thanks!

    • The backend will identify thousands of hits, but you can control how many you want to retrieve via the hitsPerPage query parameter.

      • SeanCheng

        Thanks for reply. Hope the case below will clarify my concern.

        The case is: “Users want to search nearby recommended restaurants with keyword ‘steak’. This will be sorted by ‘recommend_count’ and 20~40 restaurants (within 1~5km) should be enough for normal case.”

        However, if automaticRadius will expand to the radius with total 1000 results. The users might get some restaurants which are “far away (50~100km) but highly recommended (100 recommend_count)”, but they might only want to get some nearby (1~5km) restaurants with acceptable recommend count (10 recommend_count maybe).

        My imagination case:
        1. Search in Palo Alto: auto expand radius to 10km and get 20 results.
        (not auto expand to 100km and get 1000 results but in San Francisco)
        2. Search in San Francisco: auto expand radius to 500m~1km and get 20~40 results.
        (not auto expand to 100km and get 1000 results but in Oakland)

        Therefore I think if we can set a parameter to determine the number of “enough records” then it will be great.

        • By default our geo-search is returning results sorted by distance, so using the hitsPerPage parameter will be really similar.

          For example for the query ‘steak’, if the auto-radius identify 1000 results and you request hitsPerPage=10, you will have the 10 results closest to your locations (‘geo’ is one of the first parameter of ranking, just after typos).

          Maybe in your use case you want to have a maximum radius size rather than “enough records”which would introduce complexity as it is a bit redundant with hitsPerPage

          • Sharad Agarwal

            Julien – we are facing this issue and does not seem the auto-radius to 1000 hits is working. Please see comments above –

            We are using automaticRadius and it seems its failing to be for us.

            We have a “Phone” listed in New York and a “Phone” listed in Seattle in our records. During query mode we call searching for “Phone” around the Lat/Long of San Francisco. (Note – we do not have any phone listed in San Francisco, infact the only two phones we have listed in our data is in Seattle and New York).

            We expected the New York and Seattle products in the result set as well – though lower in the rank list. What we are seeing is that New York and Seattle records are not being returned at all.

            Should we be setting minimumAroundRadius or aroundRadius to force this behavior? Ideally we do not want to do it and just pass the lat / long and let Algolia handle it at their end.

            Also – in our search log – we see automatic radius got set to 4609 (30 miles or so).

            Based on how you describe this, we expected the Algolia engine to continue expanding the search beyond SF till the NY & Seattle records we found.

            Can you confirm – is this a bug?

  • Sharad Agarwal

    Two questions –

    My use case is there is a record with

    – array of locations (loc 1, loc 2, loc 3)
    – array of radius (r1 corresponding to loc1, r2 corresponding to loc2, r3 corresponding to loc3)

    During search I pass – search_loc and s_radius

    Results I am expecting –

    1) Match all records where

    A) distance between search_loc and loc_1 < s_radius + r1 OR

    B) distance between search_loc and loc_2 < s_radius + r2 OR

    C) distance between search_loc and loc_3 < s_radius + r3

    2) results attribs I am expecting back is for the nearest matched record – matched location (loc 1 OR loc 2 OR loc 3), distance between search_loc and matched location (loc 1 OR loc 2 OR loc 3)

    Is this feasible?

    • As most search engine, we index points and not geo-shapes. In your case you want to index a geo-shape and not a point. Your use case seems more GIS oriented, you should probably have a look to something like PostGIS

  • Sharad Agarwal

    Second Q – Can we have two different kinds of locations in the same record.

    Eg – user is posting something to sell.

    Loc 1 – where is the user posting from.
    Loc 2 – Where does the user want to sell the product.

    thanks,
    Sharad

  • Sharad Agarwal

    We are using automaticRadius and it seems its failing to be for us.

    We have a “Phone” listed in New York and a “Phone” listed in Seattle in our records. During query mode we call searching for “Phone” around the Lat/Long of San Francisco. (Note – we do not have any phone listed in San Francisco, infact the only two phones we have listed in our data is in Seattle and New York).

    We expected the New York and Seattle products in the result set as well – though lower in the rank list. What we are seeing is that New York and Seattle records are not being returned at all.

    Should we be setting minimumAroundRadius or aroundRadius to force this behavior? Ideally we do not want to do it and just pass the lat / long and let Algolia handle it at their end.

    Also – in our search log – we see automatic radius got set to 4609 (30 miles or so).

    Based on how you describe this, we expected the Algolia engine to continue expanding the search beyond SF till the NY & Seattle records we found.

    Can you confirm – is this a bug?

    • The automatic radius is adapted to the number of records around the latitude/longitude you specified. The goal is to be sure there is enough content around you.
      This computation is done on the full index to identify the radius that is then applied as a filter with the textual query.

      In your case this behavior is expected because you have records in the requested region. You can indeed use minimumAroundRadius to workaround this case or maybe you want to apply a sort by geo-distance on the result without filtering by geo (this is a new parameter we plan to introduce in the API).

      • Sharad Agarwal

        Thanks for the quick reply. Immensely helpful to understand what’s going on under the search engine.

        Couple of quick q’s – though currently in our test data we have 100 or records around San Francisco – in the long term is does not seem we can rely on the way we have implemented algolia.

        As a workaround – we will set the minimumAroundRadius to say (breadth of US – 3000 miles) since our app is US based currently and we cover coast to coast that ways. Quick q – do you expect performance degradation because of setting this?
        If yes – what would you recommend as the max value of minimumAroundRadius before performance degradation happens?

        Re: sort by geo on the result without applying geo filters –
        1) so basically in this case – we would send the query param – “phone” and Lat/long .. And then algolia would first match against phone and then give us a sorted result based on the Lat / long we send?
        2) will the distance between the hits and the search loc be provided if we have ranking info on?
        3) we are also using around precision for some requirements. For sorting – can aroundPrecision be also passed in this new param.

        • Sharad Agarwal

          Also –
          4) when’s the expected release – we are going live next month.

          Finally – we have 100 or so test records in SF .. So for 1000 hits it should have expanded to NY right? Or 1000 count changes as per density.

          Happy to share out test account if you think some scrutiny is needed.

          Again, thanks for the help and quick response.

          • Yes the sort by latitude/longitude will match against the query and sort results by geo-distance, you will be able to use geoPrecision and see the distance in the _rankingInfo inside each hit.

            The automatic radius should take far more than 100 records, you can see how many it has took if you remove the textual query on your hit.

            We unfortunately don’t have any precise ETA for the moment for this feature. In the meantime, as a workaround, I recommend to use the minimumAroundRadius with a high value.

          • Sharad Agarwal

            Super helpful. Looking forward to the new Api. For now – we will tinker with the minimum radius setting.

            Will look into how many records were taken – will send you a note if I see a small #.

            Thanks again,
            Sharad

      • BambangLuPS

        “or maybe you want to apply a sort by geo-distance on the result without filtering by geo (this is a new parameter we plan to introduce in the API).”

        is this new parameter ready to use?where I can find the documentation?

        • Yes, this parameter is “aroundRadius=all”. The documentation is available here: https://www.algolia.com/doc/api-client/php/parameters/#aroundradius

          • BambangLuPS

            thanks @speedblue:disqus , it’s works..
            I want to ask one more question. Is there any setting in algolia to disable geosearch for temporary fix? Our code have deploy in production and some of our vendor name not displayed in search result.

          • The best to activate/desactivate the geo-search is to do it at the query level. If you have already deployed your code in production that perform a geo-filter (aroundLatLng for example), the only way is to remove or change the filter is to change the query.

            If you have in production a sort by distance and want to temporary disable it because of missing geo data in your records, you can just remove the “geo” criterion in your ranking formula.

            Does it answer your question?

          • BambangLuPS

            I already tried to remove “geo” from our ranking formula before. But nothing changes. The enginee not display correct search result.

          • I think the best would be to contact our support at support@algolia.com to describe your problem in details. I am afraid the blog is really not the best to have a good support experience.

          • BambangLuPS

            I have tried. But there isn’t answer yet. I search on google and found this blog. Will wait for their response @speedblue:disqus . Thank you very much ya..
            😀