|
75 | 75 | expect(hits.size).to be 3 |
76 | 76 | expect(hits.first).to have_key('_federation') |
77 | 77 | end |
| 78 | + |
| 79 | + describe 'searching multiple remotes' do |
| 80 | + it 'federated search searches multiple remotes' do |
| 81 | + client.update_experimental_features(network: true) |
| 82 | + proxy_client.update_experimental_features(network: true) |
| 83 | + |
| 84 | + client.update_network( |
| 85 | + self: 'ms0', |
| 86 | + remotes: { |
| 87 | + ms2: { |
| 88 | + url: PROXY_URL, |
| 89 | + search_api_key: MASTER_KEY |
| 90 | + } |
| 91 | + } |
| 92 | + ) |
| 93 | + |
| 94 | + three_body_problem = { id: 1, title: 'The Three Body Problem' } |
| 95 | + the_dark_forest = { id: 2, title: 'The Dark Forest' } |
| 96 | + proxy_client.index('books').add_documents([three_body_problem, the_dark_forest]).await |
| 97 | + |
| 98 | + sherwood_forest = { id: 50, name: 'Sherwood Forest' } |
| 99 | + forbidden_forest = { id: 200, name: 'Forbidden Forest' } |
| 100 | + client.index('parks').add_documents([sherwood_forest, forbidden_forest]).await |
| 101 | + |
| 102 | + response = client.multi_search( |
| 103 | + federation: {}, |
| 104 | + queries: [ |
| 105 | + { |
| 106 | + q: 'Forest', |
| 107 | + index_uid: 'parks', |
| 108 | + federation_options: { |
| 109 | + remote: 'ms0' |
| 110 | + } |
| 111 | + }, |
| 112 | + { |
| 113 | + q: 'Body', |
| 114 | + index_uid: 'books', |
| 115 | + federation_options: { |
| 116 | + remote: 'ms2' |
| 117 | + } |
| 118 | + } |
| 119 | + ] |
| 120 | + ) |
| 121 | + |
| 122 | + resp = response['hits'].map { |hit| hit.slice('id', 'name', 'title').transform_keys(&:to_sym) } |
| 123 | + |
| 124 | + expect(resp).to include(three_body_problem, sherwood_forest, forbidden_forest) |
| 125 | + expect(resp).not_to include(the_dark_forest) |
| 126 | + rescue Meilisearch::CommunicationError |
| 127 | + pending('Please launch a second instance of Meilisearch to test network search, see spec_helper for addr config.') |
| 128 | + raise |
| 129 | + ensure |
| 130 | + client.update_network(self: nil, remotes: nil) |
| 131 | + client.delete_index('parks') |
| 132 | + proxy_client.delete_index('books') |
| 133 | + end |
| 134 | + end |
78 | 135 | end |
0 commit comments