|
1 | | -<?php /** @noinspection ForgottenDebugOutputInspection */ |
| 1 | +<?php |
| 2 | + |
| 3 | +/** @noinspection ForgottenDebugOutputInspection */ |
2 | 4 |
|
3 | 5 | include '../vendor/autoload.php'; |
4 | 6 |
|
5 | | -use \Typesense\Client; |
| 7 | +use Typesense\Client; |
6 | 8 |
|
7 | 9 | try { |
8 | 10 | $client = new Client( |
9 | | - [ |
10 | | - 'api_key' => 'xyz', |
11 | | - 'nodes' => [ |
12 | | - [ |
13 | | - 'host' => 'localhost', |
14 | | - 'port' => '8108', |
15 | | - 'protocol' => 'http', |
16 | | - ], |
17 | | - ], |
18 | | - 'connection_timeout_seconds' => 2, |
19 | | - ] |
| 11 | + [ |
| 12 | + 'api_key' => 'xyz', |
| 13 | + 'nodes' => [ |
| 14 | + [ |
| 15 | + 'host' => 'localhost', |
| 16 | + 'port' => '8108', |
| 17 | + 'protocol' => 'http', |
| 18 | + ], |
| 19 | + ], |
| 20 | + 'connection_timeout_seconds' => 2, |
| 21 | + ] |
20 | 22 | ); |
21 | 23 | echo '<pre>'; |
22 | 24 | try { |
|
31 | 33 | } |
32 | 34 | echo "--------Create Collection-------\n"; |
33 | 35 | print_r( |
34 | | - $client->collections->create( |
35 | | - [ |
36 | | - 'name' => 'books_january', |
37 | | - 'fields' => [ |
38 | | - [ |
39 | | - 'name' => 'title', |
40 | | - 'type' => 'string', |
41 | | - ], |
42 | | - [ |
43 | | - 'name' => 'authors', |
44 | | - 'type' => 'string[]', |
45 | | - ], |
46 | | - [ |
47 | | - 'name' => 'authors_facet', |
48 | | - 'type' => 'string[]', |
49 | | - 'facet' => true, |
50 | | - ], |
51 | | - [ |
52 | | - 'name' => 'publication_year', |
53 | | - 'type' => 'int32', |
54 | | - ], |
55 | | - [ |
56 | | - 'name' => 'publication_year_facet', |
57 | | - 'type' => 'string', |
58 | | - 'facet' => true, |
59 | | - ], |
| 36 | + $client->collections->create( |
60 | 37 | [ |
61 | | - 'name' => 'ratings_count', |
62 | | - 'type' => 'int32', |
63 | | - ], |
64 | | - [ |
65 | | - 'name' => 'average_rating', |
66 | | - 'type' => 'float', |
67 | | - ], |
68 | | - [ |
69 | | - 'name' => 'image_url', |
70 | | - 'type' => 'string', |
71 | | - ], |
72 | | - ], |
73 | | - 'default_sorting_field' => 'ratings_count', |
74 | | - ] |
75 | | - ) |
| 38 | + 'name' => 'books_january', |
| 39 | + 'fields' => [ |
| 40 | + [ |
| 41 | + 'name' => 'title', |
| 42 | + 'type' => 'string', |
| 43 | + ], |
| 44 | + [ |
| 45 | + 'name' => 'authors', |
| 46 | + 'type' => 'string[]', |
| 47 | + ], |
| 48 | + [ |
| 49 | + 'name' => 'authors_facet', |
| 50 | + 'type' => 'string[]', |
| 51 | + 'facet' => true, |
| 52 | + ], |
| 53 | + [ |
| 54 | + 'name' => 'publication_year', |
| 55 | + 'type' => 'int32', |
| 56 | + ], |
| 57 | + [ |
| 58 | + 'name' => 'publication_year_facet', |
| 59 | + 'type' => 'string', |
| 60 | + 'facet' => true, |
| 61 | + ], |
| 62 | + [ |
| 63 | + 'name' => 'ratings_count', |
| 64 | + 'type' => 'int32', |
| 65 | + ], |
| 66 | + [ |
| 67 | + 'name' => 'average_rating', |
| 68 | + 'type' => 'float', |
| 69 | + ], |
| 70 | + [ |
| 71 | + 'name' => 'image_url', |
| 72 | + 'type' => 'string', |
| 73 | + ], |
| 74 | + ], |
| 75 | + 'default_sorting_field' => 'ratings_count', |
| 76 | + ] |
| 77 | + ) |
76 | 78 | ); |
77 | 79 | echo "--------Create Collection-------\n"; |
78 | 80 | echo "\n"; |
79 | 81 | echo "--------Create Collection Alias-------\n"; |
80 | 82 | print_r( |
81 | | - $client->aliases->upsert( |
82 | | - 'books', |
83 | | - [ |
84 | | - 'collection_name' => 'books_january', |
85 | | - ] |
86 | | - ) |
| 83 | + $client->aliases->upsert( |
| 84 | + 'books', |
| 85 | + [ |
| 86 | + 'collection_name' => 'books_january', |
| 87 | + ] |
| 88 | + ) |
87 | 89 | ); |
88 | 90 | echo "--------Create Collection Alias-------\n"; |
89 | 91 | echo "\n"; |
90 | 92 | echo "--------Create Document on Alias-------\n"; |
91 | 93 | print_r( |
92 | | - $client->collections['books']->documents->create( |
93 | | - [ |
94 | | - 'id' => '1', |
95 | | - 'original_publication_year' => 2008, |
96 | | - 'authors' => [ |
97 | | - 'Suzanne Collins', |
98 | | - ], |
99 | | - 'average_rating' => 4.34, |
100 | | - 'publication_year' => 2008, |
101 | | - 'publication_year_facet' => '2008', |
102 | | - 'authors_facet' => [ |
103 | | - 'Suzanne Collins', |
104 | | - ], |
105 | | - 'title' => 'The Hunger Games', |
106 | | - 'image_url' => 'https://images.gr-assets.com/books/1447303603m/2767052.jpg', |
107 | | - 'ratings_count' => 4780653, |
108 | | - ] |
109 | | - ) |
| 94 | + $client->collections['books']->documents->create( |
| 95 | + [ |
| 96 | + 'id' => '1', |
| 97 | + 'original_publication_year' => 2008, |
| 98 | + 'authors' => [ |
| 99 | + 'Suzanne Collins', |
| 100 | + ], |
| 101 | + 'average_rating' => 4.34, |
| 102 | + 'publication_year' => 2008, |
| 103 | + 'publication_year_facet' => '2008', |
| 104 | + 'authors_facet' => [ |
| 105 | + 'Suzanne Collins', |
| 106 | + ], |
| 107 | + 'title' => 'The Hunger Games', |
| 108 | + 'image_url' => 'https://images.gr-assets.com/books/1447303603m/2767052.jpg', |
| 109 | + 'ratings_count' => 4780653, |
| 110 | + ] |
| 111 | + ) |
110 | 112 | ); |
111 | 113 | echo "--------Create Document on Alias-------\n"; |
112 | 114 | echo "\n"; |
113 | 115 | echo "--------Search Document on Alias-------\n"; |
114 | 116 | print_r( |
115 | | - $client->collections['books']->documents->search( |
116 | | - [ |
117 | | - 'q' => 'hunger', |
118 | | - 'query_by' => 'title', |
119 | | - 'sort_by' => 'ratings_count:desc', |
120 | | - ] |
121 | | - ) |
| 117 | + $client->collections['books']->documents->search( |
| 118 | + [ |
| 119 | + 'q' => 'hunger', |
| 120 | + 'query_by' => 'title', |
| 121 | + 'sort_by' => 'ratings_count:desc', |
| 122 | + ] |
| 123 | + ) |
122 | 124 | ); |
123 | 125 | echo "--------Search Document on Alias-------\n"; |
124 | 126 | echo "\n"; |
|
0 commit comments