Algolia giving undesired results

_geoloc
geosearch
geolocation

#1

Hello everyone, I hope this can be answered as soon as possible.

We’ve been using Algolia, especially its geolocation api in our Laravel application however we are getting undesirable results.

I have a data with _geoloc of around the same lat and lng but only one is being returned, some data it returns 2 or more.


#2

Hi Eugene,

Thanks for reaching out to Algolia Support.

Can you please share a small example that demonstrates the “undesirable results” you are receiving? Please provide the following that will be helpful:

  • code snippets
  • specific queries
  • the data being queried

Thanks in advance. I look forward to your reply!
Best regards,


#3

Hi Jason, thanks for responding!

$data = User::search('driver')->with([
        'aroundLatLng' => "7.1072767,125.6177089",
        'aroundRadius' => 30000,
        'aroundPrecision' => 200
])
->get();

This is Laravel by the way…

Assuming User::search have the following data:

"_geoloc": [
  { "lat": 7.1070381, "lng": 125.6180108 },
  { "lat": 7.1070381, "lng": 125.6180108 },
  { "lat": 7.1050835, "lng": 125.6179664 }
]

I am expecting to get the first two data returned to me because they are both in the same location. Also including the last data if it satisfies the query.

However, only one is being returned in my case.

Regards,
Gene


#4

Hi Jason, any chance you figured out my troubles? Thanks!


#5

Hi Jason - any input on this one please and thanks.

Dave


#6

Hi @mckillen and @eug5ne,

Thanks for contacting Algolia. I’m going to try and understand what you are seeking to do by walking through an example in case it illustrates how Algolia actually cannot return the data in the way you expect.

So, let’s get to it!

Step 1 - the records: Let’s say you have two records, one from your example and another I just created:

{
  "objectID": "1",
  "name": "driver",
  "_geoloc": [ // this is your data
    {"lat": 7.1070381, "lng": 125.6180108},
    {"lat": 7.1070381,"lng": 125.6180108},
    {"lat": 7.1050835,"lng": 125.6179664}
  ]
}
{
  "objectID": "2",
  "name": "driver",
  "_geoloc": [ // this is the new data
    {"lat": 47.27943, "lng": 5.10645},
    {"lat": 47.293228,"lng": 5.00457},
    {"lat": 47.316669,"lng": 5.01667}
  ]
}

Notice: Both of these records have an attribute with the value "driver" which means if you query driver they will match.

Step 2 - the geo search: Now, it looks like you then inserted query parameters as follows for the geo search:

{
  "aroundLatLng": "7.1072767,125.6177089",
  "aroundRadius": 30000,
  "aroundPrecision": 200
}

Step 3 the results: Our geo search will return the entire record ObjectID: 1 because one of the _geoloc coordinates matches the geo search. The record will not be “cleaned” so that only the coordinates that match are returned.

IF your goal is to return only matching data, I suggest you breakout your coordinates into separate records. In this case, ObjectID: 1 would become:

{
  "objectID": "1A",
  "name": "driver",
  "_geoloc": [{"lat": 7.1070381, "lng": 125.6180108}]
} 
{
  "objectID": "1B",
  "name": "driver",
  "_geoloc": [{"lat": 7.1070381,"lng": 125.6180108}]
}
{
  "objectID": "1C",
  "name": "driver",
  "_geoloc": [{"lat": 7.1050835,"lng": 125.6179664}]
} 

Using the above records, you would retrieve just the objects with _geoloc that match your query parameters.

Does this answer your question?


#7

Hi Ajay,

Thanks for your response! It does clear some of the misunderstandings I had with Algolia, but it still didn’t solve our problem. In your example, we expect that would be the case. But we are only getting one result.

If we have these records,

  {
  "objectID": "1",
  "name": "driver",
  "_geoloc": [ // this is your data
    {"lat": 7.1070381, "lng": 125.6180108}
  ]
},
{
  "objectID": "2",
  "name": "driver",
  "_geoloc": [
    {"lat": 7.1070381,"lng": 125.6180108}
  ]
},
{
  "objectID": "3",
  "name": "driver",
  "_geoloc": [ 
    {"lat": 7.1050835,"lng": 125.6179664}
  ]
}

All objects should be returned correct?

Recent tests also shows random results with different records.


#8

Hi @eug5ne,

Thanks for your sample data set. The first place to check whether “Algolia is working” is directly against your records in the Dashboard.

I created a test index with those three records. I then added your geo search query params. In the below GIF, you can see that all three (3) records are returned as you would expect, with objectID 3 as the last result:

How are the results in your Dashboard?

If you think that the issue might be an API client issue, please feel free to raise an issue directly in the repo:


#9

Hi Ajay,

Thanks again. This is very interesting development. For some reason, it’s only giving me one object. I will dig further. Thanks for wonderful guidance!

Gene