Skip to content

Commit

Permalink
fix: create Resource from index entry with external url
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed May 15, 2024
1 parent 7b713ed commit 5a81581
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
40 changes: 31 additions & 9 deletions src/Service/Search/ExternalResourceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ExternalResourceFactory implements ResourceFactory
public function accept(Document $document, ResourceLanguage $lang): bool
{
$location = $this->getField($document, 'url');
if ($location === null) {
if ($location === '') {
return false;
}
return (
Expand All @@ -34,24 +34,46 @@ public function accept(Document $document, ResourceLanguage $lang): bool
public function create(Document $document, ResourceLanguage $lang): Resource
{
$location = $this->getField($document, 'url');
if ($location === null) {
if ($location === '') {
throw new LogicException('document should contain an url');
}

return new Resource(
location: $location,
id: $this->getField($document, 'sp_id') ?? '',
name: $this->getField($document, 'title') ?? '',
objectType: 'external',
id: $this->getField($document, 'sp_id'),
name: $this->getField($document, 'title'),
objectType: $this->getField(
$document,
'sp_objecttype',
'external'
),
lang: ResourceLanguage::of(
$this->getField($document, 'meta_content_language')
),
data: new DataBag([]),
data: new DataBag([
'base' => [
'teaser' => [
'text' => $this->getField($document, 'description')
]
]
]),
);
}

private function getField(Document $document, string $name): ?string
{
return $document->getFields()[$name] ?? null;
private function getField(
Document $document,
string $name,
string $default = ''
): string {
$value = $document->getFields()[$name];
if ($value === null) {
return $default;
}

if (is_array($value)) {
return implode(' ', $value);
}

return (string)$value;
}
}
2 changes: 1 addition & 1 deletion src/Service/Search/SolrSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private function addSortToSolrQuery(
private function addRequiredFieldListToSolrQuery(
SolrSelectQuery $solrQuery
): void {
$solrQuery->setFields(['url', 'title', 'sp_id']);
$solrQuery->setFields(['url', 'title', 'description', 'sp_id', 'sp_objecttype']);
}

private function addTextFilterToSolrQuery(
Expand Down

0 comments on commit 5a81581

Please sign in to comment.