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