cleaning the excerpts managment

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
This commit is contained in:
Maxence Lange 2019-03-01 10:29:17 -01:00
parent 83d70d9008
commit 4ac0375f89
1 changed files with 6 additions and 11 deletions

View File

@ -671,12 +671,11 @@ class IndexDocument implements IIndexDocument, JsonSerializable {
* @return IIndexDocument * @return IIndexDocument
*/ */
final public function addExcerpt(string $source, string $excerpt): IIndexDocument { final public function addExcerpt(string $source, string $excerpt): IIndexDocument {
$excerpt = $this->cleanExcerpt($excerpt); $this->excerpts[] =
if (!array_key_exists($source, $this->excerpts)) { [
$this->excerpts[$source] = []; 'source' => $source,
} 'excerpt' => $this->cleanExcerpt($excerpt)
];
$this->excerpts[$source][] = $excerpt;
return $this; return $this;
} }
@ -694,13 +693,9 @@ class IndexDocument implements IIndexDocument, JsonSerializable {
final public function setExcerpts(array $excerpts): IIndexDocument { final public function setExcerpts(array $excerpts): IIndexDocument {
$new = []; $new = [];
foreach ($excerpts as $entry) { foreach ($excerpts as $entry) {
$newExcerpts = array_map(function (string $excerpt): string {
return $this->cleanExcerpt($excerpt);
}, $entry['excerpt']);
$new[] = [ $new[] = [
'source' => $entry['source'], 'source' => $entry['source'],
'excerpt' => $newExcerpts 'excerpt' => $this->cleanExcerpt($entry['excerpt'])
]; ];
} }