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

[4.0] Decoupling highlighter plugin from com_finder #20571

Merged
merged 14 commits into from Jul 6, 2018

Conversation

Hackwar
Copy link
Member

@Hackwar Hackwar commented May 24, 2018

This PR tries to fix #20252.

This PR introduces a new event, "onFinderResult", which takes a single result object and the search query object. This allows plugins to modify the results (for example changing MIME types, link types, adding additional data, etc.) and in this case it allows the highlight plugin to modify the URL of the link of the search result to add the highlight parameter. This decouples the highlight system plugin from com_finder.

The ```FinderIndexerResult``` object has both an ```url``` and ```route``` attribute and we are now using ```url``` for display purposes and ```route``` for the links href.
I also tried to change a few of the calls to the new namespaced versions.

[UPDATE]
In further reviews, I also found out the issue why searchwords with utf8 characters are not properly highlighted. It turns out that OutputFilter::stringJSSafe() is not utf8 aware and I had to rewrite it. Now it properly encodes this into a utf8 escaped string.

[UPDATE]
Yet another update regarding the ```url``` and ```route```: url is actually the ID of the item and thus can not be used. Instead I added ```cleanurl``` instead.

## How to test
* Test smart search and see the highlighting parameter in the URL of the search results.
* Apply the patch and see that it works as before, except that the additional highlight parameter is in the URL below the result.
* This PR mainly needs a codereview.

@@ -112,19 +116,19 @@ class HtmlView extends BaseHtmlView
*/
public function display($tpl = null)
{
$app = \JFactory::getApplication();
$params = $app->getParams();
$app = Factory::getApplication();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra spaces before = or align with =.

*
* @return void
*
* @since 4.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to __DEPLOY_VERSION__

@carlitorweb
Copy link
Member

I got this. This PR depend of other?
error-1055--joomla-4devtparent-id--isn-t-in-group-by---google-chrome

@Hackwar
Copy link
Member Author

Hackwar commented May 24, 2018

No, but there is another bug that is fixed in #20185. Looks like this strict query handling was disabled again in a later version of 4.0-dev. Idk. Maybe update your 4.0-dev branch to the current state? It works there...

@carlitorweb
Copy link
Member

carlitorweb commented May 24, 2018

I test now without this PR, and give the same error. So, is not this PR. And yes, the branch is up to the current state

@carlitorweb
Copy link
Member

Ok, the error I get is fixed here #20185. Beside code review will be good test this, but we need #20185 merged for that

*
* @since __DEPLOY_VERSION__
*/
public function onFinderResult($item, $query)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is afterFinderResults. For consistency, make it onFinderResults with a s?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is a afterFinderResults, but that is only the name of a mark in the logging, not a plugin event. Since I want to run the event on each result separately, I don't really would want to add the s to the event name...

…4finder_highlighter

# Conflicts:
#	components/com_finder/View/Search/HtmlView.php
@Hackwar
Copy link
Member Author

Hackwar commented Jun 12, 2018

#20185 has been merged in here. Happy testing. 😄

@carlitorweb
Copy link
Member

Got this:
Warning: Invalid argument supplied for foreach() in .....components\com_finder\tmpl\search\default_results.php on line 49

$this->state = $this->get('State');
$this->query = $this->get('Query');
\JDEBUG ? Profiler::getInstance('Application')->mark('afterFinderQuery') : null;
$this->results = $this->get('Results');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this one, is $this->get('Items')

@carlitorweb
Copy link
Member

All work ok. Waiting for the fix of the error

@Hackwar
Copy link
Member Author

Hackwar commented Jun 18, 2018

This was a bug because of a conflict between the original code and #20185. In #20185 it was changed to "Items" and somehow that change was overwritten here. Should work now.

@carlitorweb
Copy link
Member

I have tested this item ✅ successfully on a52bd58


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

@Hackwar
Copy link
Member Author

Hackwar commented Jun 23, 2018

I've updated the PR and fixed some things. It would be nice if you could test this again and if we could get one more tester for this. 😄

@Quy
Copy link
Contributor

Quy commented Jun 23, 2018

The URLs don't match where the only difference should be the highlight query string.

http://localhost/joomla-cms-j4finder_highlighter/index.php/blog/5-your-modules?highlight=WyJqb29tbGEiXQ==

http://localhost/joomla-cms-j4finder_highlighter/index.php/component/content/article/5-your-modules

@Hackwar
Copy link
Member Author

Hackwar commented Jun 23, 2018

The issue here is, that FinderIndexerAdapter::getURL() returns the wrong URL. That method should actually be deprecated... We have to fix the finder plugins for that.

$route .= '&highlight=' . base64_encode(json_encode($this->query->highlight));
}

$url = JRoute::_($this->result->route);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line above. Or not assign it to a variable and leave it where it was before.

@Hackwar
Copy link
Member Author

Hackwar commented Jun 26, 2018

I've changed the way the URLs are produced, which should fix the issue that you had and also cleaned up the result layout. Please test again.

@Hackwar
Copy link
Member Author

Hackwar commented Jun 27, 2018

Ok, I got this right now. I removed the FinderIndexerHelper::getContentPath() method, since we don't need that with the new router anymore. I also cleaned up the finder plugins and improved the comments there. Last but not least, I added a cleanURL attribute after unserialising the object in the model, where I simply copy the route attribute to this. That allows us to render the clean URL in the result layout and at the same time allow the highlighter plugin to add to the URL.

So please test and have a go. 😄

@Hackwar
Copy link
Member Author

Hackwar commented Jun 27, 2018

Since @infograf768 requested this, I also reviewed the highlighting of search words with utf8 chars in the search results page. It turns out that \Joomla\CMS\Filter\OutputFilter::stringJSSafe() is not utf8 aware and mangles all characters that are not ASCII. I rewrote that and now it should work fine for utf8. Looking for your test, @infograf768 😉

@infograf768
Copy link
Member

@Hackwar
Indeed, the issue was whether in js or the method ( #20562 (comment) ).

You solved it here and utf8 is now correctly highlighted. 👍

Remains an issue here with terms surrounded by doublequotes or singlequotes. If one does not search WITH the quotes, i.e. for example 'frontale (term in text is 'frontale') then we have no suggestion. If I enter frontale no suggestion and no result but I am proposed to search for 'frontale'.
(That issue does not exist in com_search although highlighting is broken for com_search in 4.0. Works on 3.x)

@Hackwar
Copy link
Member Author

Hackwar commented Jun 28, 2018

The suggestions have nothing to do with highlighting. I hope no one now gets confused and delays this PR because you are bringing up unrelated bugs here.

@infograf768
Copy link
Member

I sincereley hope not. As usual I test a few things when I test any of your PRs. Just consider it as a note about something to remember if it can be solved or not.

As I only tested the highlighting and not the hardcoupling issue, I can't set the my test as OK on issues.joomla.org

@carlitorweb
Copy link
Member

About search for specific phrases, we can continue this talk in #20384 , is where @Hackwar change this.

@carlitorweb
Copy link
Member

I have tested this item ✅ successfully on 9834dd9


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

@infograf768
Copy link
Member

I have tested this item ✅ successfully on 9834dd9

@laoneo @mbabker
This PR is fine concerning the highlighting of terms. But I have no idea about the decoupling.

Can you have a look at that aspect and set RTC/Merge if OK?


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

@@ -304,8 +306,6 @@ protected function index(FinderIndexerResult $item, $format = 'html')
$item->route = ContentHelperRoute::getCategoryRoute($item->id, $item->language);
}

$item->path = FinderIndexerHelper::getContentPath($item->route);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this removal necessary then or can J3 plugins still work with that code in place?

@Hackwar
Copy link
Member Author

Hackwar commented Jun 29, 2018 via email

@laoneo
Copy link
Member

laoneo commented Jun 29, 2018

Is it then deprecated in J3?

@Hackwar
Copy link
Member Author

Hackwar commented Jun 29, 2018 via email

@Hackwar
Copy link
Member Author

Hackwar commented Jun 29, 2018

PR for deprecation: #20934

@carlitorweb
Copy link
Member

I have tested this item ✅ successfully on 55057f2


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

1 similar comment
@infograf768
Copy link
Member

I have tested this item ✅ successfully on 55057f2


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

@infograf768
Copy link
Member

RTC. Thanks


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

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jul 6, 2018
@Hackwar
Copy link
Member Author

Hackwar commented Jul 6, 2018

Thank you!

@laoneo laoneo added this to the Joomla 4.0 milestone Jul 6, 2018
@laoneo laoneo merged commit 0650916 into joomla:4.0-dev Jul 6, 2018
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jul 6, 2018
@Hackwar Hackwar deleted the j4finder_highlighter branch October 23, 2020 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants