meilisearch / meilisearch-rails

Meilisearch integration for Ruby on Rails
https://www.meilisearch.com
MIT License
295 stars 48 forks source link

_geoBoundingBox filter causing an error #325

Closed Frexuz closed 7 months ago

Frexuz commented 7 months ago

Description Trying to filter with _geoBoundingBox, getting an error.

Expected behavior No error :) Based on https://www.meilisearch.com/docs/learn/fine_tuning_results/geosearch#examples-1

Current behavior Error when using the _geoBoundingBox filter. _geoRadius works.

Screenshots or Logs

irb(main):018:0> Profile.search('', { filter: ['_geoBoundingBox([45.494181, 9.214024], [45.449484, 9.179175])'] })
/Users/frexuz/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/meilisearch-0.26.0/lib/meilisearch/http_request.rb:131:in `validate': 400 Bad Request - Was expecting an operation `=`, `!=`, `>=`, `>`, `<=`, `<`, `IN`, `NOT IN`, `TO`, `EXISTS`, `NOT EXISTS`, or `_geoRadius` at `_geoBoundingBox([45.494181, 9.214024], [45.449484, 9.179175])`. (MeiliSearch::ApiError)
1:62 _geoBoundingBox([45.494181, 9.214024], [45.449484, 9.179175]). See https://docs.meilisearch.com/errors#invalid_filter.

irb(main):019:0> Profile.search('', { filter: '_geoRadius(45.472735, 9.184019, 2000)' })
=> []
irb(main):020:0>

i have also tried without an array { filter: '_geoBoundingBox([45.494181, 9.214024], [45.449484, 9.179175]) }' vs filter: ['

profile.rb:

class Profile < ApplicationRecord
  include MeiliSearch::Rails
  extend Pagy::Meilisearch

  belongs_to :user

  has_many :interests_profiles, dependent: :destroy
  has_many :interests, through: :interests_profiles

  meilisearch do
    attribute :interest_ids

    attribute :_geo do
      {
        lat: location_lat,
        lng: location_lng,
      }
    end

    filterable_attributes [
      :_geo,
      :interest_ids
    ]
  end

  def interest_ids
    interests_profiles.pluck(:interest_id)
  end
end

am i doing anything wrong?

Environment (please complete the following information):

ellnix commented 7 months ago

Your meilisearch server does not support _geoBoundingBox since it is too outdated. Filtering by geoBoundingBox was added in v1.1.0.

Follow the official installation instructions to update meilisearch to the latest version.

If you have any other problems, feel free to open new issues. :smile:

Frexuz commented 7 months ago

That was it :) Works with newer versions, thanks!