|
37 | 37 | end |
38 | 38 |
|
39 | 39 | it 'adds JSON documents (as a array of documents)' do |
40 | | - documents = <<JSON |
41 | | - [ |
42 | | - { "objectRef": 123, "title": "Pride and Prejudice", "comment": "A great book" }, |
43 | | - { "objectRef": 456, "title": "Le Petit Prince", "comment": "A french book" }, |
44 | | - { "objectRef": 1, "title": "Alice In Wonderland", "comment": "A weird book" }, |
45 | | - { "objectRef": 1344, "title": "The Hobbit", "comment": "An awesome book" }, |
46 | | - { "objectRef": 4, "title": "Harry Potter and the Half-Blood Prince", "comment": "The best book" } |
47 | | - ] |
48 | | -JSON |
| 40 | + documents = <<~JSON |
| 41 | + [ |
| 42 | + { "objectRef": 123, "title": "Pride and Prejudice", "comment": "A great book" }, |
| 43 | + { "objectRef": 456, "title": "Le Petit Prince", "comment": "A french book" }, |
| 44 | + { "objectRef": 1, "title": "Alice In Wonderland", "comment": "A weird book" }, |
| 45 | + { "objectRef": 1344, "title": "The Hobbit", "comment": "An awesome book" }, |
| 46 | + { "objectRef": 4, "title": "Harry Potter and the Half-Blood Prince", "comment": "The best book" } |
| 47 | + ] |
| 48 | + JSON |
49 | 49 | response = index.add_documents_json(documents, 'objectRef') |
50 | 50 |
|
51 | 51 | index.wait_for_task(response['taskUid']) |
52 | 52 | expect(index.documents['results'].count).to eq(5) |
53 | 53 | end |
54 | 54 |
|
55 | 55 | it 'adds NDJSON documents (as a array of documents)' do |
56 | | - documents = <<NDJSON |
57 | | - { "objectRef": 123, "title": "Pride and Prejudice", "comment": "A great book" } |
58 | | - { "objectRef": 456, "title": "Le Petit Prince", "comment": "A french book" } |
59 | | - { "objectRef": 1, "title": "Alice In Wonderland", "comment": "A weird book" } |
60 | | - { "objectRef": 4, "title": "Harry Potter and the Half-Blood Prince", "comment": "The best book" } |
61 | | -NDJSON |
| 56 | + documents = <<~NDJSON |
| 57 | + { "objectRef": 123, "title": "Pride and Prejudice", "comment": "A great book" } |
| 58 | + { "objectRef": 456, "title": "Le Petit Prince", "comment": "A french book" } |
| 59 | + { "objectRef": 1, "title": "Alice In Wonderland", "comment": "A weird book" } |
| 60 | + { "objectRef": 4, "title": "Harry Potter and the Half-Blood Prince", "comment": "The best book" } |
| 61 | + NDJSON |
62 | 62 | response = index.add_documents_ndjson(documents, 'objectRef') |
63 | 63 |
|
64 | 64 | index.wait_for_task(response['taskUid']) |
|
196 | 196 | end |
197 | 197 |
|
198 | 198 | describe 'accessing documents' do |
199 | | - before { index.add_documents!(documents) } |
| 199 | + before do |
| 200 | + index.add_documents(documents) |
| 201 | + |
| 202 | + task = index.update_filterable_attributes(['title', 'objectId']) |
| 203 | + client.wait_for_task(task['taskUid']) |
| 204 | + end |
200 | 205 |
|
201 | 206 | it 'gets one document from its primary-key' do |
202 | 207 | task = index.document(123) |
|
228 | 233 | expect(docs).to be_a(Array) |
229 | 234 | expect(docs.first.keys).to eq(['title']) |
230 | 235 | end |
| 236 | + |
| 237 | + it 'retrieves documents by filters' do |
| 238 | + docs = index.documents(filter: 'objectId > 400')['results'] |
| 239 | + |
| 240 | + expect(docs).to be_a(Array) |
| 241 | + expect(docs.first).to eq({ |
| 242 | + 'objectId' => 456, |
| 243 | + 'title' => 'Le Petit Prince', |
| 244 | + 'comment' => 'A french book' |
| 245 | + }) |
| 246 | + end |
| 247 | + |
| 248 | + it 'retrieves documents by filters & other parameters' do |
| 249 | + docs = index.documents(fields: ['title'], filter: 'objectId > 100')['results'] |
| 250 | + |
| 251 | + expect(docs).to be_a(Array) |
| 252 | + expect(docs.size).to eq(3) |
| 253 | + expect(docs.first.keys).to eq(['title']) |
| 254 | + end |
231 | 255 | end |
232 | 256 |
|
233 | 257 | describe 'updating documents' do |
|
390 | 414 | expect { index.document(id) }.to raise_document_not_found_meilisearch_api_error |
391 | 415 | end |
392 | 416 |
|
| 417 | + it 'deletes documents based on filter from index (with delete route)' do |
| 418 | + expect do |
| 419 | + index.update_filterable_attributes(['objectId']) |
| 420 | + task = index.delete_documents(filter: ['objectId > 0']) |
| 421 | + |
| 422 | + client.wait_for_task(task['taskUid']) |
| 423 | + end.to(change { index.documents['results'].size }.by(-documents.size)) |
| 424 | + end |
| 425 | + |
| 426 | + it 'ignores filter even when documents_ids is empty (with delete-batch route)' do |
| 427 | + expect do |
| 428 | + task = index.delete_documents(filter: ['objectId > 0']) |
| 429 | + |
| 430 | + client.wait_for_task(task['taskUid']) |
| 431 | + end.to(change { index.documents['results'].size }.by(0)) |
| 432 | + end |
| 433 | + |
393 | 434 | it 'deletes one document synchronously from index (with delete-batch route)' do |
394 | 435 | id = 2 |
395 | 436 | expect do |
|
0 commit comments