Merge pull request #24474 from nextcloud/enhancement/unified-search-result-attributes
Allow unified search results to have attributes
This commit is contained in:
commit
32ded877dc
|
@ -110,13 +110,16 @@ class FilesSearchProvider implements IProvider {
|
||||||
? $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id])
|
? $this->urlGenerator->linkToRouteAbsolute('core.Preview.getPreviewByFileId', ['x' => 32, 'y' => 32, 'fileId' => $result->id])
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
return new SearchResultEntry(
|
$searchResultEntry = new SearchResultEntry(
|
||||||
$thumbnailUrl,
|
$thumbnailUrl,
|
||||||
$result->name,
|
$result->name,
|
||||||
$this->formatSubline($result),
|
$this->formatSubline($result),
|
||||||
$this->urlGenerator->getAbsoluteURL($result->link),
|
$this->urlGenerator->getAbsoluteURL($result->link),
|
||||||
$result->type === 'folder' ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->mime_type)
|
$result->type === 'folder' ? 'icon-folder' : $this->mimeTypeDetector->mimeTypeIcon($result->mime_type)
|
||||||
);
|
);
|
||||||
|
$searchResultEntry->addAttribute('fileId', (string)$result->id);
|
||||||
|
$searchResultEntry->addAttribute('path', $result->path);
|
||||||
|
return $searchResultEntry;
|
||||||
}, $this->fileSearch->search($query->getTerm()))
|
}, $this->fileSearch->search($query->getTerm()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,13 @@ class SearchResultEntry implements JsonSerializable {
|
||||||
*/
|
*/
|
||||||
protected $rounded;
|
protected $rounded;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string[]
|
||||||
|
* @psalm-var array<string, string>
|
||||||
|
* @since 20.0.0
|
||||||
|
*/
|
||||||
|
protected $attributes = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $thumbnailUrl a relative or absolute URL to the thumbnail or icon of the entry
|
* @param string $thumbnailUrl a relative or absolute URL to the thumbnail or icon of the entry
|
||||||
* @param string $title a main title of the entry
|
* @param string $title a main title of the entry
|
||||||
|
@ -106,6 +113,19 @@ class SearchResultEntry implements JsonSerializable {
|
||||||
$this->rounded = $rounded;
|
$this->rounded = $rounded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add optional attributes to the result entry, e.g. an ID or some other
|
||||||
|
* context information that can be read by the client application
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $value
|
||||||
|
*
|
||||||
|
* @since 20.0.0
|
||||||
|
*/
|
||||||
|
public function addAttribute(string $key, string $value): void {
|
||||||
|
$this->attributes[$key] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
|
@ -119,6 +139,7 @@ class SearchResultEntry implements JsonSerializable {
|
||||||
'resourceUrl' => $this->resourceUrl,
|
'resourceUrl' => $this->resourceUrl,
|
||||||
'icon' => $this->icon,
|
'icon' => $this->icon,
|
||||||
'rounded' => $this->rounded,
|
'rounded' => $this->rounded,
|
||||||
|
'attributes' => $this->attributes,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue