From 96f87a847a8188698d40ac4f7abb37aba0b96949 Mon Sep 17 00:00:00 2001 From: jygaulier Date: Tue, 6 May 2025 14:15:18 +0200 Subject: [PATCH 1/4] add `include[]=results.records.stories` to searchV3 api --- .../Controller/Api/V3/V3SearchController.php | 5 +++++ .../Phrasea/Search/RecordTransformer.php | 20 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php b/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php index 6cfd6bd682..5b6ae5b82e 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php @@ -79,6 +79,7 @@ public function searchAction(Request $request) 'suggestions' => new CallbackTransformer(), 'results.stories' => $storyTransformer, 'results.stories.children' => $recordTransformer, + 'results.records.stories' => new CallbackTransformer(), 'results.stories.children.thumbnail' => $subdefTransformer, 'results.stories.children.technical_informations' => $technicalDataTransformer, 'results.stories.children.subdefs' => $subdefTransformer, @@ -338,7 +339,11 @@ private function buildSearchView(SearchEngineResult $result, array $includes, $u */ private function doSearch(Request $request) { + // print(getcwd()); die; list($offset, $limit) = V3ResultHelpers::paginationFromRequest($request); + file_put_contents("/var/alchemy/Phraseanet/logs/trace.txt", + sprintf("%s(%d) : %d ; %d\n", __FILE__, __LINE__, $offset, $limit), + FILE_APPEND); $options = SearchEngineOptions::fromRequest($this->app, $request); diff --git a/lib/Alchemy/Phrasea/Search/RecordTransformer.php b/lib/Alchemy/Phrasea/Search/RecordTransformer.php index 51fecf87de..ecbeb73db8 100644 --- a/lib/Alchemy/Phrasea/Search/RecordTransformer.php +++ b/lib/Alchemy/Phrasea/Search/RecordTransformer.php @@ -22,7 +22,8 @@ class RecordTransformer extends TransformerAbstract 'metadata', // 'metadatas', 'status', - 'caption' + 'caption', + 'stories' ]; protected $defaultIncludes = [ @@ -171,6 +172,23 @@ public function includeCaption(RecordView $recordView) }); } + public function includeStories(RecordView $recordView) + { + $data = []; + + /** @var record_adapter $story */ + foreach($recordView->getRecord()->get_grouping_parents() as $story) { + $data[] = [ + // 'title' => $story->get_title(), + 'record_id' => $story->getRecordId(), + ]; + } + + return $this->collection($data, function (array $storyData) { + return $storyData; + }); + } + /** * @return callable */ From 347187f36bc2b0b5748cf7f4382ec474cdd56952 Mon Sep 17 00:00:00 2001 From: jygaulier Date: Thu, 15 May 2025 15:32:23 +0200 Subject: [PATCH 2/4] cleanup --- .../Controller/Api/V3/V3SearchController.php | 5 ++++- lib/Alchemy/Phrasea/Search/RecordTransformer.php | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php b/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php index 5b6ae5b82e..f668908663 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php @@ -69,6 +69,7 @@ public function searchAction(Request $request) $technicalDataTransformer = new TechnicalDataTransformer(); $recordTransformer = new RecordTransformer($subdefTransformer, $technicalDataTransformer, $this->getResourceIdResolver()); $storyTransformer = new V3StoryTransformer($recordTransformer); + $recordTransformer->setStoryTransformer($storyTransformer); $compositeTransformer = new V3SearchCompositeResultTransformer($recordTransformer, $storyTransformer); $searchTransformer = new V3SearchResultTransformer($compositeTransformer); @@ -79,7 +80,9 @@ public function searchAction(Request $request) 'suggestions' => new CallbackTransformer(), 'results.stories' => $storyTransformer, 'results.stories.children' => $recordTransformer, - 'results.records.stories' => new CallbackTransformer(), + 'results.records.stories' => $storyTransformer, + 'results.records.stories.thumbnail' => $subdefTransformer, + 'results.records.stories.metadata' => new CallbackTransformer(), 'results.stories.children.thumbnail' => $subdefTransformer, 'results.stories.children.technical_informations' => $technicalDataTransformer, 'results.stories.children.subdefs' => $subdefTransformer, diff --git a/lib/Alchemy/Phrasea/Search/RecordTransformer.php b/lib/Alchemy/Phrasea/Search/RecordTransformer.php index ecbeb73db8..143f90ae30 100644 --- a/lib/Alchemy/Phrasea/Search/RecordTransformer.php +++ b/lib/Alchemy/Phrasea/Search/RecordTransformer.php @@ -46,6 +46,10 @@ class RecordTransformer extends TransformerAbstract * @var callable */ private $resourceIdResolver; + /** + * @var V3StoryTransformer + */ + private $storyTransformer; public function __construct(SubdefTransformer $subdefTransformer, TechnicalDataTransformer $technicalDataTransformer, callable $resourceIdResolver) { @@ -179,8 +183,8 @@ public function includeStories(RecordView $recordView) /** @var record_adapter $story */ foreach($recordView->getRecord()->get_grouping_parents() as $story) { $data[] = [ - // 'title' => $story->get_title(), - 'record_id' => $story->getRecordId(), + // 'title' => $story->get_title(), + 'story_id' => $story->getRecordId(), ]; } @@ -196,4 +200,9 @@ public function getResourceIdResolver(): callable { return $this->resourceIdResolver; } + + public function setStoryTransformer(V3StoryTransformer $storyTransformer) + { + $this->storyTransformer = $storyTransformer; + } } From 303df6e199af9606395776a39f4aca3e3ff4d0a8 Mon Sep 17 00:00:00 2001 From: jygaulier Date: Thu, 15 May 2025 15:39:52 +0200 Subject: [PATCH 3/4] cleanup --- lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php b/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php index f668908663..11914add1b 100644 --- a/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php +++ b/lib/Alchemy/Phrasea/Controller/Api/V3/V3SearchController.php @@ -342,11 +342,7 @@ private function buildSearchView(SearchEngineResult $result, array $includes, $u */ private function doSearch(Request $request) { - // print(getcwd()); die; list($offset, $limit) = V3ResultHelpers::paginationFromRequest($request); - file_put_contents("/var/alchemy/Phraseanet/logs/trace.txt", - sprintf("%s(%d) : %d ; %d\n", __FILE__, __LINE__, $offset, $limit), - FILE_APPEND); $options = SearchEngineOptions::fromRequest($this->app, $request); From 522dd4237bd974a783b67d4cc84ac883b946526c Mon Sep 17 00:00:00 2001 From: jygaulier Date: Thu, 15 May 2025 19:26:51 +0200 Subject: [PATCH 4/4] doc --- doc/API_documentation/v3/_compiled.yaml | 32 ++++++++++++++++++++++--- doc/API_documentation/v3/api.yaml | 32 ++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/doc/API_documentation/v3/_compiled.yaml b/doc/API_documentation/v3/_compiled.yaml index 4836c6fa7e..a1c595ad89 100644 --- a/doc/API_documentation/v3/_compiled.yaml +++ b/doc/API_documentation/v3/_compiled.yaml @@ -400,10 +400,36 @@ paths: ### results.records.technical_informations always included - + _nb:_ since stories are not related to a document, there is no technical_informations for stories. - - ### results.records.children + + ### results.records.stories + Include a list of stories that contains the record + + stories is an array of small objects containing only the `story_id` (= `record_id`) of the story. + ``` + "response": { + "results": { + "records": [ + { + "stories": [ + { + "story_id": 100 + }, + { + "story_id": 102 + }, + ... + ], + ... + }, + ... + ] + } + } + ``` + + ### results.stories.children In story search mode, will publish a children[] array for each result. See _story_children_limit_ parameter. children is an array of records, with same structure as a result record. diff --git a/doc/API_documentation/v3/api.yaml b/doc/API_documentation/v3/api.yaml index 457c48655d..537f605b94 100644 --- a/doc/API_documentation/v3/api.yaml +++ b/doc/API_documentation/v3/api.yaml @@ -443,10 +443,36 @@ paths: ### results.records.technical_informations always included - + _nb:_ since stories are not related to a document, there is no technical_informations for stories. - - ### results.records.children + + ### results.records.stories + Include a list of stories that contains the record + + stories is an array of small objects containing only the `story_id` (= `record_id`) of the story. + ``` + "response": { + "results": { + "records": [ + { + "stories": [ + { + "story_id": 100 + }, + { + "story_id": 102 + }, + ... + ], + ... + }, + ... + ] + } + } + ``` + + ### results.stories.children In story search mode, will publish a children[] array for each result. See _story_children_limit_ parameter. children is an array of records, with same structure as a result record.