X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/3b31ac75ec41b3990cea770a9e48e2066bd8e9a3..refs/pull/5291/head:/app/Search/SearchIndex.php diff --git a/app/Search/SearchIndex.php b/app/Search/SearchIndex.php index e882e987b..d9fc4e7aa 100644 --- a/app/Search/SearchIndex.php +++ b/app/Search/SearchIndex.php @@ -6,7 +6,7 @@ use BookStack\Activity\Models\Tag; use BookStack\Entities\EntityProvider; use BookStack\Entities\Models\Entity; use BookStack\Entities\Models\Page; -use DOMDocument; +use BookStack\Util\HtmlDocument; use DOMNode; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Collection; @@ -138,16 +138,11 @@ class SearchIndex 'h6' => 1.5, ]; - $html = '' . $html . ''; $html = str_ireplace(['
', '
', '
'], "\n", $html); + $doc = new HtmlDocument($html); - libxml_use_internal_errors(true); - $doc = new DOMDocument(); - $doc->loadHTML($html); - - $topElems = $doc->documentElement->childNodes->item(0)->childNodes; /** @var DOMNode $child */ - foreach ($topElems as $child) { + foreach ($doc->getBodyChildren() as $child) { $nodeName = $child->nodeName; $termCounts = $this->textToTermCountMap(trim($child->textContent)); foreach ($termCounts as $term => $count) { @@ -168,7 +163,6 @@ class SearchIndex */ protected function generateTermScoreMapFromTags(array $tags): array { - $scoreMap = []; $names = []; $values = [];