1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Models\Wiki;
7
8use App\Libraries\Elasticsearch\Hit;
9
10class PageSearchResult extends Page
11{
12 /** @var Hit */
13 private $hit;
14
15 public static function fromEs($hit)
16 {
17 $page = parent::fromEs($hit);
18 $page->hit = $hit;
19
20 return $page;
21 }
22
23 public function highlightedTitle()
24 {
25 $highlights = $this->hit->highlights('title');
26 if (empty($highlights)) {
27 return $this->title(true);
28 }
29
30 $title = $highlights[0];
31
32 if (present($this->subtitle())) {
33 $title = $this->subtitle().' / '.$title;
34 }
35
36 return $title;
37 }
38
39 public function highlights()
40 {
41 return implode(
42 ' ... ',
43 $this->hit->highlights(
44 'page_text',
45 300
46 )
47 );
48 }
49}