Skip to content

Commit 6917ef0

Browse files
committed
Merge branch 'develop'
2 parents 94e744c + 9d01368 commit 6917ef0

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## 9.1.0 - 2025-04-10
4+
5+
Add support for raw JSON requests (like the ones used by the Assets UI) using SearchRequest::json.
6+
37
## 9.0.0 - 2025-02-19
48

59
PHP 8.4 is now required.

src/Service/SearchRequest.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace DerSpiegel\WoodWingAssetsClient\Service;
44

5-
65
use DerSpiegel\WoodWingAssetsClient\AssetsClient;
76
use DerSpiegel\WoodWingAssetsClient\RelationType;
87
use DerSpiegel\WoodWingAssetsClient\Request;
98

9+
1010
/**
1111
* Search for assets
1212
*
@@ -33,33 +33,42 @@ public function __construct(
3333
readonly array $facets = [],
3434
readonly bool $appendRequestSecret = self::APPEND_REQUEST_SECRET_DEFAULT,
3535
readonly bool $returnHighlightedText = self::RETURN_HIGHLIGHTED_TEXT_DEFAULT,
36-
readonly bool $returnThumbnailHits = self::RETURN_THUMBNAIL_HITS_DEFAULT
36+
readonly bool $returnThumbnailHits = self::RETURN_THUMBNAIL_HITS_DEFAULT,
37+
readonly string $json = ''
3738
) {
3839
parent::__construct($assetsClient);
3940
}
4041

4142

4243
public function __invoke(): SearchResponse
4344
{
44-
$httpResponse = $this->assetsClient->serviceRequest('POST', 'search', $this->toArray());
45+
$isRawJsonRequest = !empty($this->json);
46+
47+
$httpResponse = $this->assetsClient->serviceRequest(
48+
'POST',
49+
'search',
50+
$this->toArray(),
51+
!$isRawJsonRequest
52+
);
4553

4654
$this->logger->debug(
4755
'Search performed',
4856
[
4957
'method' => __METHOD__,
50-
'query' => $this->q
58+
'query' => $isRawJsonRequest ? $this->json : $this->q
5159
]
5260
);
5361

5462
return SearchResponse::createFromHttpResponse($httpResponse);
5563
}
5664

5765

58-
/**
59-
* @return array
60-
*/
6166
protected function toArray(): array
6267
{
68+
if (!empty($this->json)) {
69+
return json_decode($this->json, true, 512, JSON_THROW_ON_ERROR);
70+
}
71+
6372
$params = [
6473
'q' => $this->q
6574
];
@@ -104,11 +113,6 @@ protected function toArray(): array
104113
* Get query for relation search
105114
*
106115
* @see https://helpcenter.woodwing.com/hc/en-us/articles/360041854172#additional-queries
107-
*
108-
* @param string $relatedTo
109-
* @param string $relationTarget
110-
* @param RelationType|null $relationType
111-
* @return string
112116
*/
113117
public static function getRelationSearchQ(
114118
string $relatedTo,

tests/Integration/SearchRequestTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final class SearchRequestTest extends IntegrationFixture
1111
{
1212
public function testEmptySearch(): void
1313
{
14-
$response = (new SearchRequest($this->assetsClient, q: '', num: 0))();
14+
$response = new SearchRequest($this->assetsClient, q: '', num: 0)();
1515

1616
$this->assertGreaterThan(0, $response->totalHits);
1717
}
@@ -22,6 +22,19 @@ public function testMalformedQuery(): void
2222
$this->expectException(ClientException::class);
2323
$this->expectExceptionCode(400);
2424

25-
(new SearchRequest($this->assetsClient, q: 'noSuchField:', num: 0))();
25+
new SearchRequest($this->assetsClient, q: 'noSuchField:', num: 0)();
26+
}
27+
28+
29+
public function testJsonQuery(): void
30+
{
31+
$json = '{"start":0,"num":300,"returnHighlightedText":true,"facets":{"extension":{"field":"extension"},"assetType":{"field":"assetType"},"assetDomain":{"field":"assetDomain"},"tags":{"field":"tags"},"status":{"field":"status"}},"sorting":[{"field":"assetCreated","descending":true}],"showAssetsOfSubfolders":"true","showSubCollections":"false","query":{"BoolQuery":{"elements":[{"operator":"MUST","query":{"QueryStringQuery":{"queryString":""}}},{"operator":"MUST_NOT","query":{"BoolQuery":{"elements":[{"operator":"MUST","query":{"TermQuery":{"name":"assetType","value":"collection"}}},{"operator":"MUST","query":{"WildcardQuery":{"name":"parentContainerIds","wildcardValue":"*"}}}]}}}]}},"maxResultHits":400,"firstResult":0,"returnThumbnailHits":true}';
32+
33+
$response = new SearchRequest(
34+
$this->assetsClient,
35+
json: $json
36+
)();
37+
38+
$this->assertGreaterThan(0, $response->totalHits);
2639
}
2740
}

0 commit comments

Comments
 (0)