Search plugin ordering Topic is solved
Moderators: ooffick, General Support Moderators
Forum rules
- andypooz
- Joomla! Guru
- Posts: 728
- Joined: Sat Dec 30, 2006 3:03 pm
- Location: London, UK
- Contact:
Search plugin ordering
I've just created a search plugin that grabs the results of an rss feed from a hubspot blog they have set up and returns an array of objects as per the requirements of a J! search plugin. It works. The results are added to search results. But. They are always last on the list (as the plugin is set last).
The ordering of the search results is my area of confusion. I have set up the ordering of the data set from my plugin according to the ordering value passed in, and this orders the results at the end of the list of combined search results in the order I have set, BUT it does not order the combined search resullts according to most recent, title ASC or whatever else. I get joomla contents ordered, then K2 items ordered, then my results ordered.
Is the search plugin supposed to get the results of all of the different search plugins and reprocess them according to the order attribute? There are $item->created and $item->title object attributes that could be used to order the combined results. If this were the case (and this is what makes me believe what i wan't isn't possible), there'd be no need to order the results within the plugin at all, because that would just be duplicating processing. I'm assuming that what I'm seeing is default behaviour, but it's a bit disappointing.
Can't I have all the search results ordered alphabetically or by date regardless of the plugin retrieving them?
The ordering of the search results is my area of confusion. I have set up the ordering of the data set from my plugin according to the ordering value passed in, and this orders the results at the end of the list of combined search results in the order I have set, BUT it does not order the combined search resullts according to most recent, title ASC or whatever else. I get joomla contents ordered, then K2 items ordered, then my results ordered.
Is the search plugin supposed to get the results of all of the different search plugins and reprocess them according to the order attribute? There are $item->created and $item->title object attributes that could be used to order the combined results. If this were the case (and this is what makes me believe what i wan't isn't possible), there'd be no need to order the results within the plugin at all, because that would just be duplicating processing. I'm assuming that what I'm seeing is default behaviour, but it's a bit disappointing.
Can't I have all the search results ordered alphabetically or by date regardless of the plugin retrieving them?
Last edited by imanickam on Tue Oct 17, 2017 3:33 am, edited 1 time in total.
Reason: Moved the topic from the forum Extensions for Joomla! 3.x to the forum Joomla! 3.x - Coding
Reason: Moved the topic from the forum Extensions for Joomla! 3.x to the forum Joomla! 3.x - Coding
-
- Joomla! Hero
- Posts: 2903
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: Search plugin ordering
This isn't possible since different search plugins use different data sources. Although a single plugin could be made to search in multiple database tables (e.g. Content and K2) and sort results properly. Another way would be to get all results (i.e. no pagination) and sort them afterwards. But that would be extremely slow.
You could also try Smart Search.
You could also try Smart Search.
- andypooz
- Joomla! Guru
- Posts: 728
- Joined: Sat Dec 30, 2006 3:03 pm
- Location: London, UK
- Contact:
Re: Search plugin ordering
Thanks Sharky. Seems like a shame to me. All of the plugins are supposed to return an array of objects with the same attributes 'created' , 'title', etc, and at that stage it doesn't matter the source. Perfect for ordering in the search component rather than in the plugin.
I'm assuming there's a circumstance where you might like to have results divided by source, but in most cases this is just a limitation, I would have thought. The results aren't even identifiable as coming from different sources, it mostly just appears that the ordering has gone wrong.
I don't think smart search works any different in this regard either (from my basic research).
I've put the idea of combining K2 and my search plugin in order to get the bulk of items ordered properly to my client, so we'll see.
I'll create a proof of concept on a development site and submit it to see what the team think.
Anyway, thanks for the input Sharky, appreciate it!
I'm assuming there's a circumstance where you might like to have results divided by source, but in most cases this is just a limitation, I would have thought. The results aren't even identifiable as coming from different sources, it mostly just appears that the ordering has gone wrong.
I don't think smart search works any different in this regard either (from my basic research).
I've put the idea of combining K2 and my search plugin in order to get the bulk of items ordered properly to my client, so we'll see.
I'll create a proof of concept on a development site and submit it to see what the team think.
Anyway, thanks for the input Sharky, appreciate it!
-
- Joomla! Intern
- Posts: 54
- Joined: Mon Jun 19, 2017 10:57 am
Re: Search plugin ordering
I have similar problem. I use only one search plugin (content) and set the ordering to newest first but the result isn't in a proper order. As far as I'm right it displays first the results where the keyword is in the title of the articles and then it starts with the articles where the keyword is in only the text.
I checked SearchViewSearch class and a simple code snippet after
solved the problem
Of course it's hardcoded but shows that the result list is using the same fields from the search plugins so sorting the result array should be a task of the view
I checked SearchViewSearch class and a simple code snippet after
Code: Select all
$results = $this->get('data');
Code: Select all
usort($results,function($first,$second){
return $first->created < $second->created;
});
- brian
- Joomla! Master
- Posts: 12787
- Joined: Fri Aug 12, 2005 7:19 am
- Location: Leeds, UK
- Contact:
Re: Search plugin ordering
@sandomatyas yes it does sort the results if the keyword in the title before the keyword is in the content - that is the intended behaviour. You want to serve the user with the best match for the content and if the keyword is in the title its obviously going to be a better match than if it is in the content
"Exploited yesterday... Hacked tomorrow"
Blog http://brian.teeman.net/
Joomla Hidden Secrets http://hiddenjoomlasecrets.com/
Blog http://brian.teeman.net/
Joomla Hidden Secrets http://hiddenjoomlasecrets.com/
-
- Joomla! Fledgling
- Posts: 1
- Joined: Fri Sep 28, 2018 7:15 am
Re: Search plugin ordering
Try using expertrec search engine .
-
- Joomla! Intern
- Posts: 54
- Joined: Mon Jun 19, 2017 10:57 am
Re: Search plugin ordering
Wrong logic. I want to display results with an ordering what I set. If it is ordering by date, it doesn't matter if the title or the content contains the keyword. What you set is a secondary/primary sorting the result by the strength of the field. I don't need that or any relevance-related extra sorting.brian wrote: ↑Wed Sep 26, 2018 8:35 am@sandomatyas yes it does sort the results if the keyword in the title before the keyword is in the content - that is the intended behaviour. You want to serve the user with the best match for the content and if the keyword is in the title its obviously going to be a better match than if it is in the content
You wrote: "if the keyword is in the title its obviously going to be a better match than if it is in the content"
In my case and with my site structure this is a totally wrong way.
-
- Joomla! Apprentice
- Posts: 21
- Joined: Thu Dec 31, 2009 8:56 pm
Re: Search plugin ordering
Hi Sandomatyas,
Thanks for posting your solution. I am not a coder, but I think I managed to implement what you did. I added your code snippet in the file /components/com_search/views/search/view.html.php
A user of mine brought to my attention he got seemingly unordered results when searching 3 keywords together. This thread clued me into the results being grouped by keyword in title first and then in the article content. However in the case of multiple keywords, I think the results are segmented into even more groups, and it's impossible for a user to discern a logic to the search results.
Your solution seems to work for me when all the results are displayed without pagination, but if pagination is used, clicking through the results, the ordering is not correct from page to page, even though it is corrected within each page itself.
Do you have any idea why this might be happening? Any help would be greatly appreciated. Thanks
Thanks for posting your solution. I am not a coder, but I think I managed to implement what you did. I added your code snippet in the file /components/com_search/views/search/view.html.php
A user of mine brought to my attention he got seemingly unordered results when searching 3 keywords together. This thread clued me into the results being grouped by keyword in title first and then in the article content. However in the case of multiple keywords, I think the results are segmented into even more groups, and it's impossible for a user to discern a logic to the search results.
Your solution seems to work for me when all the results are displayed without pagination, but if pagination is used, clicking through the results, the ordering is not correct from page to page, even though it is corrected within each page itself.
Do you have any idea why this might be happening? Any help would be greatly appreciated. Thanks
sandomatyas wrote: ↑Mon Sep 24, 2018 3:50 pmI have similar problem. I use only one search plugin (content) and set the ordering to newest first but the result isn't in a proper order. As far as I'm right it displays first the results where the keyword is in the title of the articles and then it starts with the articles where the keyword is in only the text.
I checked SearchViewSearch class and a simple code snippet aftersolved the problemCode: Select all
$results = $this->get('data');
Of course it's hardcoded but shows that the result list is using the same fields from the search plugins so sorting the result array should be a task of the viewCode: Select all
usort($results,function($first,$second){ return $first->created < $second->created; });
-
- Joomla! Hero
- Posts: 2903
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: Search plugin ordering
It's because you're doing this in the view. The view only displays data given to it. To have this working correctly you need to modify the database query used to retrieve results. Usually it would be in the model but in this case it's in the search plugin.gumibear wrote: ↑Wed Nov 14, 2018 4:16 pmHi Sandomatyas,
Thanks for posting your solution. I am not a coder, but I think I managed to implement what you did. I added your code snippet in the file /components/com_search/views/search/view.html.php
A user of mine brought to my attention he got seemingly unordered results when searching 3 keywords together. This thread clued me into the results being grouped by keyword in title first and then in the article content. However in the case of multiple keywords, I think the results are segmented into even more groups, and it's impossible for a user to discern a logic to the search results.
Your solution seems to work for me when all the results are displayed without pagination, but if pagination is used, clicking through the results, the ordering is not correct from page to page, even though it is corrected within each page itself.
Do you have any idea why this might be happening? Any help would be greatly appreciated. Thanks
-
- Joomla! Apprentice
- Posts: 21
- Joined: Thu Dec 31, 2009 8:56 pm
Re: Search plugin ordering
Thank you SharkyKZ! I got it sorted out with your help.