Skip to content

Commit

Permalink
Create MultiSearch module
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoocasali committed Mar 30, 2023
1 parent acef680 commit 7999210
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/meilisearch.rb
Expand Up @@ -3,6 +3,7 @@
require 'meilisearch/version'
require 'meilisearch/utils'
require 'meilisearch/http_request'
require 'meilisearch/multi_search'
require 'meilisearch/tenant_token'
require 'meilisearch/task'
require 'meilisearch/client'
Expand Down
1 change: 1 addition & 0 deletions lib/meilisearch/client.rb
Expand Up @@ -3,6 +3,7 @@
module MeiliSearch
class Client < HTTPRequest
include MeiliSearch::TenantToken
include MeiliSearch::MultiSearch

### INDEXES

Expand Down
11 changes: 11 additions & 0 deletions lib/meilisearch/multi_search.rb
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module MeiliSearch
module MultiSearch
def multi_search(data)
body = Utils.transform_attributes(data)

http_post '/multi-search', queries: body
end
end
end
19 changes: 19 additions & 0 deletions spec/meilisearch/client/multi_search_spec.rb
@@ -0,0 +1,19 @@
# frozen_string_literal: true
RSpec.describe 'MeiliSearch::Client - Multiple Index Search' do

before do
client.create_index('books')
client.create_index('movies')
end

it 'does a custom search with two different indexes' do
response = client.multi_search([
{ index_uid: 'books', q: 'prince' },
{ index_uid: 'movies', q: 'prince' }
])

expect(response['results'].count).to eq(2)
expect(response['results'][0]['estimatedTotalHits']).to eq(0)
expect(response['results'][1]['estimatedTotalHits']).to eq(0)
end
end

0 comments on commit 7999210

Please sign in to comment.