Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix facet search error #320

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/meilisearch-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,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
Expand Down
15 changes: 15 additions & 0 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,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) }
Expand Down
2 changes: 1 addition & 1 deletion spec/support/active_record_classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,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
Expand Down