Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search results in title show search keyword tag #16979

Closed
vladav opened this issue Jul 5, 2017 · 52 comments
Closed

Search results in title show search keyword tag #16979

vladav opened this issue Jul 5, 2017 · 52 comments

Comments

@vladav
Copy link

@vladav vladav commented Jul 5, 2017

Steps to reproduce the issue

Use search box to find keyword in title

Expected result

yellow highlighted keyword

Actual result

" span class="highlight" keyword /span " (I had to remove <> to be able to show text)

System information (as much as possible)

Joomla updated to 3.7.3

Additional comments

On every Joomla instalation, after upgrade

@dgrammatiko
Copy link
Contributor

@dgrammatiko dgrammatiko commented Jul 5, 2017

The way that highlighter.js works is by wrapping the keyword with a <span class='highlight'>. Thus this is expected behaviour. You might need to adjust the way you're using the script or, maybe easier, the way the the title is displayed (e.g. preg_replace('<span...', '', $title);).

By the way where are you getting this? In core highlighter is used only for the search results AFAIK

@joomla-cms-bot joomla-cms-bot changed the title Search results in title show <span class="highlight">search keyword</span> tag Search results in title show search keyword tag Jul 5, 2017
@ghost
Copy link

@ghost ghost commented Jul 5, 2017

@vladav thanks for reporting.

Related to #16484?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16979.

@vladav
Copy link
Author

@vladav vladav commented Jul 5, 2017

Yes, related to #16484. We will change code as per 35752ef and test it out.

@vladav
Copy link
Author

@vladav vladav commented Jul 5, 2017

Removing line 270 from components/com_search/views/search/view.html.php solved the issue. (Still, now the keyword in title is not highlighted, but it does not show html span tags).

@nicksavov
Copy link
Contributor

@nicksavov nicksavov commented Jul 5, 2017

Same issue here using a Shaper_helix3 template. Removing line 270 has provided a temporary fix.

@vladaaa13
Copy link

@vladaaa13 vladaaa13 commented Jul 6, 2017

@vladav I remove line 270 and problem is gone, tnx :)

@alexfedorin
Copy link

@alexfedorin alexfedorin commented Jul 11, 2017

I have same issue Yootheme template.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16979.

@joomla-cms-bot
Copy link

@joomla-cms-bot joomla-cms-bot commented Jul 11, 2017

Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/16979

@ghost
Copy link

@ghost ghost commented Jul 11, 2017

closed as having PR ##16484


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16979.

@nicksavov
Copy link
Contributor

@nicksavov nicksavov commented Jul 14, 2017

@franz-wohlkoenig isn't #16484 the source of the bug, rather than a fix for the bug?

@mahsite
Copy link

@mahsite mahsite commented Jul 15, 2017

سلام دوستان ایرانی
این مشکل در ورژن جدید جوملا واقع شده است
برای رفع این مشکل

به ادرس زیر بروید

public_html/components/com_search/views/search/view.html.php

و کد زیر را پیدا . غیر فعال نمایید با //

$result->title = StringHelper::str_ireplace($needle, $hl1 . $needle . $hl2, htmlspecialchars($result->title, ENT_COMPAT, 'UTF-8'));

موفق باشید

@wojsmol
Copy link
Contributor

@wojsmol wojsmol commented Jul 16, 2017

@mahsite Plese use English in this repo.

@rolandverhaar
Copy link

@rolandverhaar rolandverhaar commented Jul 18, 2017

I have two websites.
One produces in HTML code:
<a href="/home/nieuws/12257-bloot-op-de-fiets-tijdens-de-world-naked-bike-ride"> Bloot op de fiets tijdens de <span class="highlight">world</span> Naked Bike Ride </a>
So, this is correct.
The other produces in HTML code:
<a href="/nieuws/14334-niet-meer-praten-tegen-de-praatpaal" title="Niet meer praten tegen de <span class=&quot;highlight&quot;> praatpaal </span> ">Niet meer praten tegen de &lt;span class="highlight"&gt; praatpaal &lt;/span&gt; </a>
This is incorrect, as it will show tags in the output.
Code base for both websites: Joomla! 3.7.3

@ghost
Copy link

@ghost ghost commented Jul 18, 2017

@nicksavov should ths Issue be reopened?

@rolandverhaar
Copy link

@rolandverhaar rolandverhaar commented Jul 19, 2017

No, I think the problem is in the Warp framework.
Will have to resolve it there.

@nicksavov
Copy link
Contributor

@nicksavov nicksavov commented Jul 19, 2017

@franz-wohlkoenig Yes, I think so. The two sites I experienced this on had a custom template and a Helix 3 framework template.

@joomla-cms-bot
Copy link

@joomla-cms-bot joomla-cms-bot commented Jul 20, 2017

Set to "open" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/16979

@ghost
Copy link

@ghost ghost commented Jul 20, 2017

reopened as stated above.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16979.

@sc00zy
Copy link

@sc00zy sc00zy commented Jul 20, 2017

I saw this on a few websites with templates that override com_search. Yootheme seem to have updated their templates to fix this.

@nicksavov
Copy link
Contributor

@nicksavov nicksavov commented Jul 21, 2017

Both templates here have an override for com_search. I could implement the fix in the overrides (wouldn't be an issue).

Is there a way to fix this in core for all users, including those that have template overrides? I'm guessing the answer is going to be no, but thought I'd ask

@brianteeman
Copy link
Member

@brianteeman brianteeman commented Jul 21, 2017

If the issue is in the override then nothing changed in the core will effect the override. Thats the whole point of an override.

Closing as it is not a core issue

@INOSIM
Copy link

@INOSIM INOSIM commented Jul 25, 2017

We also had this issue as described above. We found that we needed to fix our template override, as described under 35752ef. After fixing our template override, highlighting of the keyword in the title line worked allright. But still, the highlighted keyword is not displayed correctly. For example, if you enter a search like "joomla", and "Joomla" would be the correct writing in the title line, instead you see "joomla" highlighted in the title line. In the content snippet below the title line, though, you see the keyword in correct writing, e. g., "Joomla". Apparently, in the search result not the complete original string from the title line is displayed but the string from the search input is integrated here.

@premierinternet
Copy link

@premierinternet premierinternet commented Jul 25, 2017

Try this to fix the case issue:
if(stripos(htmlspecialchars($result->title, ENT_COMPAT, 'UTF-8'),$needle) > 0){ $needlepos = stripos(htmlspecialchars($result->title, ENT_COMPAT, 'UTF-8'),$needle); $firstneedle = substr(htmlspecialchars($result->title, ENT_COMPAT, 'UTF-8'),$needlepos,1); if (ctype_upper($firstneedle)) { $needle = StringHelper::ucwords($needle); } }
Insert the code above in components/com_search/views/search/view.html.php at line 269 before $result->title = StringHelper::str_ireplace($needle, $hl1 . $needle . $hl2, htmlspecialchars($result->title, ENT_COMPAT, 'UTF-8'));
You will want to make this an override or it will disappear the next time you upgrade Joomla. The lines are referenced in Joomla 3.7.3

@INOSIM
Copy link

@INOSIM INOSIM commented Jul 26, 2017

Thanks for taking the time to reply and trying to provide a fix. Sadly there are two problems though. First, the fix only works around case differences of the first character and more importantly second, isn’t the “view.html.php” part of the core and cannot simply be overridden contrary to e.g. the “default_results.php”?

@nicksavov
Copy link
Contributor

@nicksavov nicksavov commented Jul 28, 2017

If the issue is in the override then nothing changed in the core will effect the override.

Not exactly. Many things can change in the core and affect an override. The only thing that can change in core that for sure won't affect an override is the file that's being overridden.

In this particular case, the core change in components/com_search/views/search/view.html.php (which isn't getting overridden) affected the override (for components/com_search/views/search/tmpl/default_results.php).

@INOSIM
Copy link

@INOSIM INOSIM commented Jul 31, 2017

Thanks!

@nicksavov
Copy link
Contributor

@nicksavov nicksavov commented Aug 8, 2017

Can this issue be reopened please?

@joomla-cms-bot
Copy link

@joomla-cms-bot joomla-cms-bot commented Aug 8, 2017

Set to "open" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/16979

@joomla-cms-bot joomla-cms-bot reopened this Aug 8, 2017
@ghost
Copy link

@ghost ghost commented Aug 8, 2017

reopened as stated above.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16979.

@brianteeman
Copy link
Member

@brianteeman brianteeman commented Aug 8, 2017

why is this re-opened

@nicksavov
Copy link
Contributor

@nicksavov nicksavov commented Aug 10, 2017

Thanks!

It shouldn't have been closed. See #16979 (comment) for more info.

@mbabker
Copy link
Contributor

@mbabker mbabker commented Aug 10, 2017

I'm missing something then. What is left for us to do to address this issue? Introducing a new property does not fix overrides because overrides will be unaware of it, reverting to the old way restores a bug. At this point it is unclear what the issue to be resolved is.

@nicksavov
Copy link
Contributor

@nicksavov nicksavov commented Aug 10, 2017

Good question! This part needs to be addressed:

Is there a way to fix this in core for all users, including those that have template overrides? I'm guessing the answer is going to be no, but thought I'd ask

As to the old way, I wouldn't call it bug per se. It's a design choice of whether to highlight the search word in the title or not. That design choice has likely been there since the plugin was first added to core. For that reason, some would consider highlighting the title as a nice new feature, rather than a bug fix.

@brianteeman
Copy link
Member

@brianteeman brianteeman commented Aug 10, 2017

If we are highlighting matching search terms and we are searching for those terms in the title then it was a bug that they were not highlighted before. That bug has been fixed. There is nothing that can be changed in the core to make your override with a bug work correctly

@mbabker
Copy link
Contributor

@mbabker mbabker commented Aug 10, 2017

Then the answer is no. If you change something in a layout, that is specific to that layout. If you change something in the data objects being fed into a layout, it is a global change affecting anything using that data object.

@rolandverhaar
Copy link

@rolandverhaar rolandverhaar commented Aug 10, 2017

In the core, the Title of an article is not put through any html-encoding. Therefore the handling of the title string is left to the template or override. Now the title string is changed in the core and overrides or templates do not expect this.
Naturally it can be fixed in the override, however, it would be nice if all data objects are treated the same (preferably do nothing in the core), then all overrides and templates can handle all objects the same way.
A bug that has ben around for ages is not a bug anymore.

@nicksavov
Copy link
Contributor

@nicksavov nicksavov commented Aug 10, 2017

@mbabker thanks!

@brianteeman
Copy link
Member

@brianteeman brianteeman commented Aug 10, 2017

So can we close it now?

@ReLater
Copy link
Contributor

@ReLater ReLater commented Aug 12, 2017

@rolandverhaar

In the core, the Title of an article is not put through any html-encoding. Therefore the handling of the title string is left to the template or override. Now the title string is changed in the core and overrides or templates do not expect this.

You have to remove the escape thing from your template overrides NOT because the title has been htmlspecialchared in core but because parts of the title are surrounded sometimes by HTML-SPAN-tags to highlight search hits.

I think removing the highlightning of titles is not an option at all.

So, yes, please close this issue.

@joomla-cms-bot
Copy link

@joomla-cms-bot joomla-cms-bot commented Aug 13, 2017

Set to "closed" on behalf of @franz-wohlkoenig by The JTracker Application at issues.joomla.org/joomla-cms/16979

@ghost
Copy link

@ghost ghost commented Aug 13, 2017

closed as stated above.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16979.

nicksavov added a commit to nicksavov/wright that referenced this issue Sep 13, 2017
Due to https://github.com/joomla/joomla-cms/pull/16484/files , search results titles that have a search keyword now display as:
<span class="highlight">Sample</span> title...

Instead of:
Same Title

This fixes it.

If needed, more about this issue is found at joomla/joomla-cms#16979
@ittoufiq
Copy link

@ittoufiq ittoufiq commented Sep 19, 2017

Hi,
Please enter the file location
templates/Your_template/html/com_search/search/default_results.php

Please open the file default_results.php And find out the code

<a href="<?php echo JRoute::_($result->href); ?>"<?php if ($result->browsernav == 1) :?> target="_blank"<?php endif;?>>
<?php echo $this->escape($result->title);?>
</a>

And replace with this code

<a href="<?php echo JRoute::_($result->href); ?>"<?php if ($result->browsernav == 1) : ?> target="_blank"<?php endif; ?>>
<?php // $result->title should not be escaped in this case, as it may ?>
<?php // contain span HTML tags wrapping the searched terms, if present ?>
<?php // in the title. ?>
<?php echo $result->title; ?>
</a>

-Thanks

@ZerooCool
Copy link

@ZerooCool ZerooCool commented Oct 21, 2017

Resolved with the ittoufiq method.

Translate to french :

Résolu avec la méthode de ittoufiq.
highlight affiche des balises span dans les titres des résultats de la recherche :
https://www.visionduweb.eu/wiki/index.php?title=JSN_Artista_Free#highlight_affiche_des_balises_span_dans_les_titres_des_résultats_de_la_recherche

@oisvidi
Copy link
Contributor

@oisvidi oisvidi commented Nov 23, 2017

My fix in /components/com_search/views/search/view.html.php on line 162 insert code "break;"

@QuotesUK
Copy link

@QuotesUK QuotesUK commented Jul 19, 2018

I have this issue in Joomla v3.8.10

I know that previous discussion has explained how to fix this but without the context of surrounding code fragments for a "before" and "after" it is difficult working out what I need to do. Some authors have refered to modifying two files, and others in different places. Where exactly - line 19, 20, 162 or 270?

For example my file (v3.8.10) com_search/views/search/view.html.php line 162...
$result->title = $rowTitleHighLighted;

For example my file (v3.8.10) com_search/views/search/view.html.php line 270...
ksort($posCollector);

I would appreciate it someone could provide clear guidance of what is being changed and perhaps make it future proof by showing several of the existing lines of code before and after, to help us locate it. Thank you.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16979.

@ghost
Copy link

@ghost ghost commented Jul 19, 2018

@QuotesUK please open a new Issue (and link to this Issue) as Comments on closed Issues didn't get much Notice, thanks.

@rpmconsulting
Copy link

@rpmconsulting rpmconsulting commented Jan 31, 2019

I'm having this issue in Joomla 3.9.2. What ultimately fix's the showing up as header in search results?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16979.

@sc00zy
Copy link

@sc00zy sc00zy commented Feb 4, 2019

I'm having this issue in Joomla 3.9.2. What ultimately fix's the showing up as header in search results?

This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16979.

You need to update the template override of the template you're using

@rpmconsulting
Copy link

@rpmconsulting rpmconsulting commented Feb 5, 2019

Do you have the info/instructions on how to do the override?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/16979.

@sc00zy
Copy link

@sc00zy sc00zy commented Feb 5, 2019

It depends on the template you are using. You can read more about template overrides here https://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet