Skip to content

Commit a1848c6

Browse files
committed
Add options to indexing endpoints
1 parent 6cd1c2d commit a1848c6

4 files changed

Lines changed: 35 additions & 13 deletions

File tree

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3.5'
22

33
services:
44
typesense:
5-
image: typesense/typesense:0.19.0.rc18
5+
image: typesense/typesense:0.20.0.rc39
66
environment:
77
TYPESENSE_DATA_DIR: /data
88
TYPESENSE_API_KEY: xyz

examples/collection_operations.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,17 @@
118118
'Suzanne Collins',
119119
],
120120
'average_rating' => 4.6,
121-
'publication_year' => 2008,
121+
'publication_year' => "2008",
122122
'publication_year_facet' => '2008',
123123
'authors_facet' => [
124124
'Suzanne Collins',
125125
],
126126
'title' => 'The Hunger Games',
127127
'image_url' => 'https://images.gr-assets.com/books/1447303603m/2767052.jpg',
128128
'ratings_count' => 4780653,
129+
],
130+
[
131+
'dirty_values' => 'coerce_or_reject',
129132
]
130133
)
131134
);

src/Document.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ public function retrieve(): array
6969

7070
/**
7171
* @param array $partialDocument
72+
* @param array $options
7273
*
7374
* @return array
7475
* @throws TypesenseClientError|HttpClientException
7576
*/
76-
public function update(array $partialDocument): array
77+
public function update(array $partialDocument, array $options = []): array
7778
{
78-
return $this->apiCall->patch($this->endpointPath(), $partialDocument);
79+
return $this->apiCall->patch($this->endpointPath(), $partialDocument, true, $options);
7980
}
8081

8182
/**

src/Documents.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,40 +51,59 @@ public function __construct(string $collectionName, ApiCall $apiCall)
5151
*/
5252
private function endPointPath(string $action = ''): string
5353
{
54-
return sprintf('%s/%s/%s/%s', Collections::RESOURCE_PATH, $this->collectionName, static::RESOURCE_PATH, $action);
54+
return sprintf(
55+
'%s/%s/%s/%s',
56+
Collections::RESOURCE_PATH,
57+
$this->collectionName,
58+
static::RESOURCE_PATH,
59+
$action
60+
);
5561
}
5662

5763
/**
5864
* @param array $document
65+
* @param array $options
5966
*
6067
* @return array
6168
* @throws TypesenseClientError|HttpClientException
6269
*/
63-
public function create(array $document): array
70+
public function create(array $document, array $options = []): array
6471
{
65-
return $this->apiCall->post($this->endPointPath(''), $document, true);
72+
return $this->apiCall->post($this->endPointPath(''), $document, true, $options);
6673
}
6774

6875
/**
6976
* @param array $document
77+
* @param array $options
7078
*
7179
* @return array
7280
* @throws TypesenseClientError|HttpClientException
7381
*/
74-
public function upsert(array $document): array
82+
public function upsert(array $document, array $options = []): array
7583
{
76-
return $this->apiCall->post($this->endPointPath(''), $document, true, ['action' => 'upsert']);
84+
return $this->apiCall->post(
85+
$this->endPointPath(''),
86+
$document,
87+
true,
88+
array_merge($options, ['action' => 'upsert'])
89+
);
7790
}
7891

7992
/**
8093
* @param array $document
94+
* @param array $options
8195
*
8296
* @return array
8397
* @throws TypesenseClientError|HttpClientException
8498
*/
85-
public function update(array $document): array
99+
public function update(array $document, array $options = []): array
86100
{
87-
return $this->apiCall->post($this->endPointPath(''), $document, true, ['action' => 'update']);
101+
return $this->apiCall->post(
102+
$this->endPointPath(''),
103+
$document,
104+
true,
105+
array_merge($options, ['action' => 'update'])
106+
);
88107
}
89108

90109
/**
@@ -109,8 +128,7 @@ public function createMany(array $documents, array $options = []): array
109128
*
110129
* @return string|array
111130
* @throws TypesenseClientError
112-
* @throws GuzzleException
113-
* @throws \JsonException
131+
* @throws \JsonException|HttpClientException
114132
*/
115133
public function import($documents, array $options = [])
116134
{

0 commit comments

Comments
 (0)