diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5285525d..6482a0c4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -35,7 +35,7 @@ jobs: - name: Run tests run: bundle exec rspec - name: Upload coverage reports to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/lib/meilisearch-rails.rb b/lib/meilisearch-rails.rb index acbb16b2..a976d088 100644 --- a/lib/meilisearch-rails.rb +++ b/lib/meilisearch-rails.rb @@ -283,6 +283,15 @@ def initialize(index_uid, raise_on_failure, options) end end + # Maually define facet_search due to complications with **opts in ruby 2.* + def facet_search(*args, **opts) + SafeIndex.log_or_throw(:facet_search, @raise_on_failure) do + return MeiliSearch::Rails.black_hole unless MeiliSearch::Rails.active? + + @index.facet_search(*args, **opts) + end + end + # special handling of wait_for_task to handle null task_id def wait_for_task(task_uid) return if task_uid.nil? && !@raise_on_failure # ok diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 3ef31313..f035a2c5 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -669,6 +669,21 @@ expect(results.facets_distribution['genre'].size).to eq(3) end + it 'does not error on facet_search' do + genres = %w[Legend Fiction Crime].cycle + authors = %w[A B C].cycle + + 5.times do + Book.create! name: Faker::Book.title, author: authors.next, genre: genres.next + end + + expect do + Book.index.facet_search('genre', 'Fic', filter: 'author = A') + Book.index.facet_search('genre', filter: 'author = A') + Book.index.facet_search('genre') + end.not_to raise_error + end + context 'with Marshal serialization' do let(:found_books) { Book.search('*') } let(:marshaled_books) { Marshal.dump(found_books) } diff --git a/spec/support/active_record_classes.rb b/spec/support/active_record_classes.rb index 11cd65a8..4a661cc4 100644 --- a/spec/support/active_record_classes.rb +++ b/spec/support/active_record_classes.rb @@ -414,7 +414,7 @@ class Book < ActiveRecord::Base meilisearch synchronous: true, index_uid: safe_index_uid('SecuredBook'), sanitize: true do searchable_attributes [:name] typo_tolerance min_word_size_for_typos: { one_typo: 5, twoTypos: 8 } - filterable_attributes [:genre] + filterable_attributes %i[genre author] faceting max_values_per_facet: 3 add_index safe_index_uid('BookAuthor') do