|
10 | 10 | { objectId: 456, title: 'Le Petit Prince', comment: 'A french book' },
|
11 | 11 | { objectId: 1, title: 'Alice In Wonderland', comment: 'A weird book' },
|
12 | 12 | { objectId: 1344, title: 'The Hobbit', comment: 'An awesome book' },
|
| 13 | + { objectId: 13, title: 'Zen in the Art of Archery' }, |
13 | 14 | { objectId: 4, title: 'Harry Potter and the Half-Blood Prince', comment: 'The best book' },
|
14 | 15 | { objectId: 42, title: 'The Hitchhiker\'s Guide to the Galaxy' },
|
15 | 16 | { objectId: 2, title: 'Le Rouge et le Noir' }
|
|
383 | 384 | describe '#documents' do
|
384 | 385 | before do
|
385 | 386 | index.add_documents(documents).await
|
386 |
| - index.update_filterable_attributes(['title', 'objectId']).await |
| 387 | + index.update_filterable_attributes(['title', 'objectId', 'comment']).await |
387 | 388 | end
|
388 | 389 |
|
389 | 390 | it 'browses documents' do
|
|
422 | 423 | { 'title' => a_kind_of(String) }
|
423 | 424 | )
|
424 | 425 | end
|
| 426 | + |
| 427 | + describe 'sorts documents' do |
| 428 | + before do |
| 429 | + index.update_sortable_attributes(['title']).await |
| 430 | + end |
| 431 | + |
| 432 | + it 'get' do |
| 433 | + docs = index.documents(sort: ['title:asc']) |
| 434 | + expect(docs['results'].first).to include('objectId' => 1, 'title' => 'Alice In Wonderland') |
| 435 | + expect(docs['results'].last).to include('objectId' => 13, 'title' => 'Zen in the Art of Archery') |
| 436 | + |
| 437 | + docs = index.documents(sort: ['title:desc']) |
| 438 | + expect(docs['results'].first).to include('objectId' => 13, 'title' => 'Zen in the Art of Archery') |
| 439 | + expect(docs['results'].last).to include('objectId' => 1, 'title' => 'Alice In Wonderland') |
| 440 | + end |
| 441 | + |
| 442 | + it 'post' do |
| 443 | + docs = index.documents(filter: 'comment NOT EXISTS', sort: ['title:asc']) |
| 444 | + expect(docs['results'].first).to include('objectId' => 2, 'title' => 'Le Rouge et le Noir') |
| 445 | + expect(docs['results'].last).to include('objectId' => 13, 'title' => 'Zen in the Art of Archery') |
| 446 | + end |
| 447 | + end |
425 | 448 | end
|
426 | 449 |
|
427 | 450 | describe '#update_documents' do
|
|
0 commit comments