Skip to content

Commit 99b68d1

Browse files
- Code style fixing.
- Allow ``$client->collections['books']->retrieve()`` and ``$client->collections['books']->documents['1']->retrieve()`` to maintain clients parity with python and NodeJS. - Update examples.
1 parent 263fcc6 commit 99b68d1

13 files changed

Lines changed: 480 additions & 283 deletions

examples/alias_operations.php

Lines changed: 97 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,113 +5,131 @@
55
use Devloops\Typesence\Client;
66

77
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' => [
1711
'host' => 'HOST',
1812
'port' => '8108',
1913
'protocol' => 'http',
2014
'api_key' => 'API_KEY',
2115
],
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+
);
2527
echo '<pre>';
2628
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(
3831
[
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+
);
6773
echo "--------Create Collection-------\n";
6874
echo "\n";
6975
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+
);
7384
echo "--------Create Collection Alias-------\n";
7485
echo "\n";
7586
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+
);
92107
echo "--------Create Document on Alias-------\n";
93108
echo "\n";
94109
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+
);
100119
echo "--------Search Document on Alias-------\n";
101120
echo "\n";
102121
echo "--------Retrieve All Aliases-------\n";
103-
print_r($client->getAliases()->retrieve());
122+
print_r($client->aliases->retrieve());
104123
echo "--------Retrieve All Aliases-------\n";
105124
echo "\n";
106125
echo "--------Retrieve All Alias Documents-------\n";
107-
print_r($client->getAliases()->books->retrieve());
126+
print_r($client->aliases['books']->retrieve());
108127
echo "--------Retrieve All Alias Documents-------\n";
109128
echo "\n";
110129
echo "--------Delete Alias-------\n";
111-
print_r($client->getAliases()->books->delete());
130+
print_r($client->aliases['books']->delete());
112131
echo "--------Delete Alias-------\n";
113132
echo "\n";
114-
115133
} catch (Exception $e) {
116134
echo $e->getMessage();
117135
}

0 commit comments

Comments
 (0)