|
3 | 3 | ## |
4 | 4 | # These examples walk you through operations specifically related to aliases |
5 | 5 |
|
6 | | -require_relative './client_initialization' |
| 6 | +require_relative 'client_initialization' |
7 | 7 |
|
8 | 8 | # Create a collection |
9 | 9 | create_response = @typesense.collections.create( |
10 | | - "name": 'books_january', |
11 | | - "fields": [ |
12 | | - { "name": 'title', "type": 'string' }, |
13 | | - { "name": 'authors', "type": 'string[]' }, |
14 | | - { "name": 'authors_facet', "type": 'string[]', "facet": true }, |
15 | | - { "name": 'publication_year', "type": 'int32' }, |
16 | | - { "name": 'publication_year_facet', "type": 'string', "facet": true }, |
17 | | - { "name": 'ratings_count', "type": 'int32' }, |
18 | | - { "name": 'average_rating', "type": 'float' }, |
19 | | - { "name": 'image_url', "type": 'string' } |
| 10 | + name: 'books_january', |
| 11 | + fields: [ |
| 12 | + { name: 'title', type: 'string' }, |
| 13 | + { name: 'authors', type: 'string[]' }, |
| 14 | + { name: 'authors_facet', type: 'string[]', facet: true }, |
| 15 | + { name: 'publication_year', type: 'int32' }, |
| 16 | + { name: 'publication_year_facet', type: 'string', facet: true }, |
| 17 | + { name: 'ratings_count', type: 'int32' }, |
| 18 | + { name: 'average_rating', type: 'float' }, |
| 19 | + { name: 'image_url', type: 'string' } |
20 | 20 | ], |
21 | | - "default_sorting_field": 'ratings_count' |
| 21 | + default_sorting_field: 'ratings_count' |
22 | 22 | ) |
23 | 23 |
|
24 | 24 | ap create_response |
25 | 25 |
|
26 | 26 | # Create or update an existing alias |
27 | 27 | create_alias_response = @typesense.aliases.upsert('books', |
28 | | - "collection_name": 'books_january') |
| 28 | + collection_name: 'books_january') |
29 | 29 | ap create_alias_response |
30 | 30 |
|
31 | 31 | # Add a book using the alias name `books` |
32 | 32 | hunger_games_book = { |
33 | | - 'id': '1', 'original_publication_year': 2008, 'authors': ['Suzanne Collins'], 'average_rating': 4.34, |
34 | | - 'publication_year': 2008, 'publication_year_facet': '2008', 'authors_facet': ['Suzanne Collins'], |
35 | | - 'title': 'The Hunger Games', |
36 | | - 'image_url': 'https://images.gr-assets.com/books/1447303603m/2767052.jpg', |
37 | | - 'ratings_count': 4_780_653 |
| 33 | + id: '1', original_publication_year: 2008, authors: ['Suzanne Collins'], average_rating: 4.34, |
| 34 | + publication_year: 2008, publication_year_facet: '2008', authors_facet: ['Suzanne Collins'], |
| 35 | + title: 'The Hunger Games', |
| 36 | + image_url: 'https://images.gr-assets.com/books/1447303603m/2767052.jpg', |
| 37 | + ratings_count: 4_780_653 |
38 | 38 | } |
39 | 39 |
|
40 | 40 | @typesense.collections['books'].documents.create(hunger_games_book) |
41 | 41 |
|
42 | 42 | # Search using the alias |
43 | 43 | ap @typesense.collections['books'].documents.search( |
44 | | - 'q': 'hunger', |
45 | | - 'query_by': 'title', |
46 | | - 'sort_by': 'ratings_count:desc' |
| 44 | + q: 'hunger', |
| 45 | + query_by: 'title', |
| 46 | + sort_by: 'ratings_count:desc' |
47 | 47 | ) |
48 | 48 |
|
49 | 49 | # List all aliases |
|
0 commit comments