Skip to content

Commit 6293396

Browse files
committed
Always use multiSearch
1 parent 8232b62 commit 6293396

2 files changed

Lines changed: 14 additions & 31 deletions

File tree

config/statamic-typesense.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,4 @@
66
// but be quicker to update large numbers of documents.
77
'insert_chunk_size' => 100,
88

9-
// Use multiSearch via POST for search requests.
10-
// Typesense limits GET request parameter size for security
11-
// reasons, so if you have many or long search parameters,
12-
// you should enable this.
13-
'use_multi_search' => env('STATAMIC_TYPESENSE_MULTISEARCH', false)
14-
159
];

src/Typesense/Index.php

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,20 @@ public function searchUsingApi($query, array $options = []): array
111111
->join(',') ?: '*';
112112
}
113113

114-
$searchResults = config('statamic-typesense.use_multi_search', false)
115-
? $this->multiSearch($options)
116-
: $this->regularSearch($options);
114+
$this->getOrCreateIndex();
115+
116+
// Using POST multiSearch to avoid potential request size limitations
117+
// (regular search uses GET and is limited in size by Typesense)
118+
$searchRequest = [
119+
'searches' => [
120+
array_merge($options, [
121+
'collection' => $this->name
122+
])
123+
],
124+
];
125+
126+
$searchResults = $this->client->multiSearch->perform($searchRequest, []);
127+
$searchResults = array_shift($searchResults['results']);
117128

118129
$total = count($searchResults['hits']);
119130

@@ -184,26 +195,4 @@ public function client()
184195
{
185196
return $this->client;
186197
}
187-
188-
private function regularSearch(array $options)
189-
{
190-
return $this->getOrCreateIndex()->documents->search($options);
191-
}
192-
193-
private function multiSearch(array $options)
194-
{
195-
$this->getOrCreateIndex();
196-
197-
$searchRequest = [
198-
'searches' => [
199-
array_merge($options, [
200-
'collection' => $this->name
201-
])
202-
],
203-
];
204-
205-
$multiSearchResults = $this->client->multiSearch->perform($searchRequest, []);
206-
207-
return array_shift($multiSearchResults['results']);
208-
}
209198
}

0 commit comments

Comments
 (0)