Search plugin ordering Topic is solved

For Joomla! 3.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Locked
User avatar
andypooz
Joomla! Guru
Joomla! Guru
Posts: 728
Joined: Sat Dec 30, 2006 3:03 pm
Location: London, UK
Contact:

Search plugin ordering

Post by andypooz » Mon Oct 16, 2017 1:17 pm

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?
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
Andy Hickey
Bespoke Joomla Extension Developer
http://www.netamity.com

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2903
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Search plugin ordering

Post by SharkyKZ » Tue Oct 17, 2017 8:00 am

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.

User avatar
andypooz
Joomla! Guru
Joomla! Guru
Posts: 728
Joined: Sat Dec 30, 2006 3:03 pm
Location: London, UK
Contact:

Re: Search plugin ordering

Post by andypooz » Tue Oct 17, 2017 10:33 am

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!
Andy Hickey
Bespoke Joomla Extension Developer
http://www.netamity.com

sandomatyas
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Mon Jun 19, 2017 10:57 am

Re: Search plugin ordering

Post by sandomatyas » Mon Sep 24, 2018 3:50 pm

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

Code: Select all

$results    = $this->get('data');
solved the problem

Code: Select all

usort($results,function($first,$second){
	return $first->created < $second->created;
});
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

User avatar
brian
Joomla! Master
Joomla! Master
Posts: 12787
Joined: Fri Aug 12, 2005 7:19 am
Location: Leeds, UK
Contact:

Re: Search plugin ordering

Post by brian » 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
"Exploited yesterday... Hacked tomorrow"
Blog http://brian.teeman.net/
Joomla Hidden Secrets http://hiddenjoomlasecrets.com/

muthaliganesh77
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Fri Sep 28, 2018 7:15 am

Re: Search plugin ordering

Post by muthaliganesh77 » Fri Sep 28, 2018 7:22 am

Try using expertrec search engine .

sandomatyas
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Mon Jun 19, 2017 10:57 am

Re: Search plugin ordering

Post by sandomatyas » Wed Oct 10, 2018 11:39 am

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
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.
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.

gumibear
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Thu Dec 31, 2009 8:56 pm

Re: Search plugin ordering

Post by gumibear » Wed Nov 14, 2018 4:16 pm

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




sandomatyas wrote:
Mon Sep 24, 2018 3:50 pm
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

Code: Select all

$results    = $this->get('data');
solved the problem

Code: Select all

usort($results,function($first,$second){
	return $first->created < $second->created;
});
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

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2903
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Search plugin ordering

Post by SharkyKZ » Wed Nov 14, 2018 5:39 pm

gumibear wrote:
Wed Nov 14, 2018 4:16 pm
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
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
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Thu Dec 31, 2009 8:56 pm

Re: Search plugin ordering

Post by gumibear » Wed Nov 14, 2018 8:29 pm

Thank you SharkyKZ! I got it sorted out with your help.


Locked

Return to “Joomla! 3.x Coding”