joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

Highlight plugin breaks links with #fragment in search results

Open MSGroupFM opened this issue 1 year ago • 0 comments

Steps to reproduce the issue

My finder plugin indexes paragraphs of content and links to headings with the specified anchors. But if you enable the highlight_terms parameter in the finder settings, then the links will not lead to a fragment of the article.

Indexed links look like: index.php?option=com_content&view=article&id=56#anchor

Expected result

In finder search results i expected links with SEF: /pages/article-alias?0=highlight&1=WyJcdTA0MzdcdTA0MzBcdTA0MzJcdTA0MzVcdTA0MzRcdTA0MzVcdTA0M2RcdTA0MzhcdTA0NGYiXQ==#anchor

Actual result

/pages/article-alias#anchor&highlight=WyJcdTA0MzdcdTA0MzBcdTA0MzJcdTA0MzVcdTA0MzRcdTA0MzVcdTA0M2RcdTA0MzhcdTA0NGYiXQ==

Query with highlight is simply added to the end of the link

System information (as much as possible)

Joomla! 5.1.0 PHP 8.2

Additional comments

Fix this with code in file plugins/system/highlight/src/Extension/Highlight.php

Old code $item->route .= '&highlight=' . base64_encode(json_encode(\array_slice($query->highlight, 0, 10)));

New code $uri = new Uri($item->route); $uri->setQuery(array_merge($uri->getQuery(true), ['highlight' => base64_encode(json_encode(\array_slice($query->highlight, 0, 10)))])); $item->route = $uri->toString(['path', 'query', 'fragment']);

MSGroupFM avatar May 02 '24 10:05 MSGroupFM