Skip to content

Commit 0b0a73b

Browse files
- Fix empty files.
1 parent 77cd014 commit 0b0a73b

24 files changed

Lines changed: 1561 additions & 31 deletions

examples/alias_operations.php

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,117 @@
1-
<?php
1+
<?php /** @noinspection ForgottenDebugOutputInspection */
2+
3+
include '../vendor/autoload.php';
4+
5+
use Devloops\Typesence\Client;
6+
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+
[
17+
'host' => 'HOST',
18+
'port' => '8108',
19+
'protocol' => 'http',
20+
'api_key' => 'API_KEY',
21+
],
22+
],
23+
'timeout_seconds' => 2,
24+
]);
25+
echo '<pre>';
26+
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+
],
38+
[
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+
]));
67+
echo "--------Create Collection-------\n";
68+
echo "\n";
69+
echo "--------Create Collection Alias-------\n";
70+
print_r($client->getAliases()->upsert('books', [
71+
'collection_name' => 'books_january',
72+
]));
73+
echo "--------Create Collection Alias-------\n";
74+
echo "\n";
75+
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+
]));
92+
echo "--------Create Document on Alias-------\n";
93+
echo "\n";
94+
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+
]));
100+
echo "--------Search Document on Alias-------\n";
101+
echo "\n";
102+
echo "--------Retrieve All Aliases-------\n";
103+
print_r($client->getAliases()->retrieve());
104+
echo "--------Retrieve All Aliases-------\n";
105+
echo "\n";
106+
echo "--------Retrieve All Alias Documents-------\n";
107+
print_r($client->getAliases()->books->retrieve());
108+
echo "--------Retrieve All Alias Documents-------\n";
109+
echo "\n";
110+
echo "--------Delete Alias-------\n";
111+
print_r($client->getAliases()->books->delete());
112+
echo "--------Delete Alias-------\n";
113+
echo "\n";
114+
115+
} catch (Exception $e) {
116+
echo $e->getMessage();
117+
}

examples/collection_operations.php

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,122 @@
1-
<?php
1+
<?php /** @noinspection ForgottenDebugOutputInspection */
2+
3+
include '../vendor/autoload.php';
4+
5+
use Devloops\Typesence\Client;
6+
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+
[
17+
'host' => 'HOST',
18+
'port' => '8108',
19+
'protocol' => 'http',
20+
'api_key' => 'API_KEY',
21+
],
22+
],
23+
'timeout_seconds' => 2,
24+
]);
25+
echo '<pre>';
26+
echo "--------Create Collection-------\n";
27+
print_r($client->getCollections()->create([
28+
'name' => 'books',
29+
'fields' => [
30+
[
31+
'name' => 'title',
32+
'type' => 'string',
33+
],
34+
[
35+
'name' => 'authors',
36+
'type' => 'string[]',
37+
],
38+
[
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+
]));
67+
echo "--------Create Collection-------\n";
68+
echo "\n";
69+
echo "--------Retrieve Collection-------\n";
70+
print_r($client->getCollections()->books->retrieve());
71+
echo "--------Retrieve Collection-------\n";
72+
echo "\n";
73+
echo "--------Retrieve All Collections-------\n";
74+
print_r($client->getCollections()->retrieve());
75+
echo "--------Retrieve All Collections-------\n";
76+
echo "\n";
77+
echo "--------Create Document-------\n";
78+
print_r($client->getCollections()->books->getDocuments()->create([
79+
'id' => '1',
80+
'original_publication_year' => 2008,
81+
'authors' => [
82+
'Suzanne Collins',
83+
],
84+
'average_rating' => 4.34,
85+
'publication_year' => 2008,
86+
'publication_year_facet' => '2008',
87+
'authors_facet' => [
88+
'Suzanne Collins',
89+
],
90+
'title' => 'The Hunger Games',
91+
'image_url' => 'https://images.gr-assets.com/books/1447303603m/2767052.jpg',
92+
'ratings_count' => 4780653,
93+
]));
94+
echo "--------Create Document-------\n";
95+
echo "\n";
96+
echo "--------Export Documents-------\n";
97+
print_r($client->getCollections()->books->getDocuments()->export());
98+
echo "--------Export Documents-------\n";
99+
echo "\n";
100+
echo "--------Fetch Single Document-------\n";
101+
print_r($client->getCollections()->books->getDocuments()[1]->retrieve());
102+
echo "--------Fetch Single Document-------\n";
103+
echo "\n";
104+
echo "--------Search Document-------\n";
105+
print_r($client->getCollections()->books->getDocuments()->search([
106+
'q' => 'hunger',
107+
'query_by' => 'title',
108+
'sort_by' => 'ratings_count:desc',
109+
]));
110+
echo "--------Search Document-------\n";
111+
echo "\n";
112+
echo "--------Delete Document-------\n";
113+
print_r($client->getCollections()->books->getDocuments()[1]->delete());
114+
echo "--------Delete Document-------\n";
115+
echo "\n";
116+
echo "--------Delete Collection-------\n";
117+
print_r($client->getCollections()->books->delete());
118+
echo "--------Delete Collection-------\n";
119+
120+
} catch (Exception $e) {
121+
echo $e->getMessage();
122+
}

examples/curation_operations.php

Lines changed: 127 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,127 @@
1-
<?php
1+
<?php /** @noinspection ForgottenDebugOutputInspection */
2+
3+
include '../vendor/autoload.php';
4+
5+
use Devloops\Typesence\Client;
6+
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+
[
17+
'host' => 'HOST',
18+
'port' => '8108',
19+
'protocol' => 'http',
20+
'api_key' => 'API_KEY',
21+
],
22+
],
23+
'timeout_seconds' => 2,
24+
]);
25+
echo '<pre>';
26+
echo "--------Create Collection-------\n";
27+
print_r($client->getCollections()->create([
28+
'name' => 'books',
29+
'fields' => [
30+
[
31+
'name' => 'title',
32+
'type' => 'string',
33+
],
34+
[
35+
'name' => 'authors',
36+
'type' => 'string[]',
37+
],
38+
[
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+
]));
67+
echo "--------Create Collection-------\n";
68+
echo "\n";
69+
echo "--------Create or Update Override-------\n";
70+
print_r($client->getCollections()->books->getOverrides()
71+
->upsert('hermione-exact', [
72+
'rule' => [
73+
'query' => 'hermione',
74+
'match' => 'exact',
75+
],
76+
'includes' => [
77+
[
78+
'id' => '1',
79+
'position' => 1,
80+
],
81+
],
82+
]));
83+
echo "--------Create or Update Override-------\n";
84+
echo "\n";
85+
echo "--------Get All Overrides-------\n";
86+
print_r($client->getCollections()->books->getOverrides()->retrieve());
87+
echo "--------Get All Overrides-------\n";
88+
echo "\n";
89+
echo "--------Get Single Override-------\n";
90+
print_r($client->getCollections()->books->getOverrides()['hermione-exact']->retrieve());
91+
echo "--------Get Single Override-------\n";
92+
echo "\n";
93+
echo "--------Create Document-------\n";
94+
print_r($client->getCollections()->books->getDocuments()->create([
95+
'id' => '1',
96+
'original_publication_year' => 2008,
97+
'authors' => [
98+
'Suzanne Collins',
99+
],
100+
'average_rating' => 4.34,
101+
'publication_year' => 2008,
102+
'publication_year_facet' => '2008',
103+
'authors_facet' => [
104+
'Suzanne Collins',
105+
],
106+
'title' => 'The Hunger Games',
107+
'image_url' => 'https://images.gr-assets.com/books/1447303603m/2767052.jpg',
108+
'ratings_count' => 4780653,
109+
]));
110+
echo "--------Create Document-------\n";
111+
echo "\n";
112+
echo "--------Search Document-------\n";
113+
print_r($client->getCollections()->books->getDocuments()->search([
114+
'q' => 'hermione',
115+
'query_by' => 'title',
116+
'sort_by' => 'ratings_count:desc',
117+
]));
118+
echo "--------Search Document-------\n";
119+
echo "\n";
120+
echo "--------Delete Override-------\n";
121+
print_r($client->getCollections()->books->getOverrides()['hermione-exact']->delete());
122+
echo "--------Delete Override-------\n";
123+
echo "\n";
124+
125+
} catch (Exception $e) {
126+
echo $e->getMessage();
127+
}

0 commit comments

Comments
 (0)