0

According to this blog post, Algolia now allows several geolocations on a single record. All we have to do is to pass it as an array. I've tried it with the algolia-rails gem but was unable to do it.

Here are the combinations I've tried that does not work:

"geoloc": [
   {"lat": :latitude, "lng": :longitude}
]

geoloc [{:latitude, :longitude}]

And a bunch of other combinations. Most of it results in an error indicating that geoloc is expecting 2 arguments instead of 1 which is an array.

My original code for a single geoloc which works is:

geoloc :latitude, :longitude
oky_sabeni
  • 7,672
  • 15
  • 65
  • 89
  • The rails code looks like it it has only one geoloc. What happens when you call the same method multiple times? https://github.com/algolia/algoliasearch-rails/blob/2d63c37ed6151e314e5479e6a102d1f48e23cd4f/lib/algoliasearch-rails.rb#L204-L209 – Sairam Jan 18 '17 at 06:04
  • Well that sucks :( Is there any way that I can do it via pure ruby? – oky_sabeni Jan 18 '17 at 06:07
  • can you see what happens when you call it multiple times? – Sairam Jan 18 '17 at 06:07
  • Oh! Smart! Let me try that. I looked at their ruby gem and it seems to provide that functionality. I just need to know how to integrate that with the rails gem as well. – oky_sabeni Jan 18 '17 at 06:08
  • I called it multiple times and it does not seem to work. I still only see one geoloc on my index. – oky_sabeni Jan 18 '17 at 06:10
  • try using `add_attribute` method . See how tags accepts multiple - https://github.com/algolia/algoliasearch-rails/blob/2d63c37ed6151e314e5479e6a102d1f48e23cd4f/lib/algoliasearch-rails.rb#L204-L217 – Sairam Jan 18 '17 at 06:14
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/133408/discussion-between-okysabeni-and-sairam). – oky_sabeni Jan 18 '17 at 06:16

1 Answers1

0

One workaround is:

def _geoloc
  [{ lat: x_1, lng: y_1 }, { lat: x_2, lng: y_2 }]
end

algoliasearch do
  attributes :_geoloc
end

This does the trick.

ldlgds
  • 123
  • 1
  • 7