Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Search only this (parent) category but also show links/results from all subcategories

Quote Reply
Search only this (parent) category but also show links/results from all subcategories
Hello,

How can I do the this - when there is a restricted search option at the bottom footer like "search all categories" or "search only this category" and when I select "search only this category" option and enter a keyword in the field, right now it will return links/results with matching keywords from ONLY that category id which is fine the way it is but if it is a PARENT/MAIN category then it will only show links from that category and will NOT show links/results from all the CHILD/Subcategories under that Parent category. What I want is to show not only links in that parent category and if there are other subcategories under that category (which have links matching the search term) then I want it to also show links/results from all child/subcategories under that Parent category.

Thanks!
Quote Reply
Re: [socrates] Search only this (parent) category but also show links/results from all subcategories In reply to
Hi,

If I'm understanding what you are asking for correctly, I don't think that is possible.

Code:
catid=123
will search the category ID and all its sub-cats.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Search only this (parent) category but also show links/results from all subcategories In reply to
Thanks Andy. From your post you seem to indicate that if it is set for catid=123 then it will search the category ID and "all its sub-cats" - which is what I want but it only shows links from category ID 123 and doesn't show links from any of the sub-cats ie. if the main catid is 123 and if there are sub-cats under it like 234, 456 then it won't show results from those sub-cats 234 or 456 but only shows links from 123.
Quote Reply
Re: [socrates] Search only this (parent) category but also show links/results from all subcategories In reply to
Hi,

If you don't mind editing the code, you could open up /admin/Links/User/Search.pm, and find:

Code:
@children = grep !$seen{$_}++, @children;

Then add this below it:

Code:
if ($IN->param('catid-only')) {
@children = $IN->param('catid-only');
}

Now when calling search.cgi, if you ONLY want to search the specific category, pass in catid-only=1234 , and it should ONLY search the category 1234, while ignoring any sub-cats.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Search only this (parent) category but also show links/results from all subcategories In reply to
Quote:
while ignoring any sub-cats

No, I don't want it to ignore sub-cats (it is doing that currently) but I actually want it to show results from all sub-cats and the main cat.

Basically, here is what I want - say I have parent category Automobiles and then sub-cats Cars, Trucks, Motorcycles under that and some cats have links related to my keyword. Automobiles (the main cat) has 2 links, Cars has 1 link, Trucks has 3 links, and Motorcycles 0.

Now when I set the search form to search only this category as "Automobiles" and then enter the keyword in the field as "repair" and submit the form, it should return all links in the main cat Automobiles and also links from Cars, Trucks, Motorcyles. Currently, it returns results 2 links from Automobiles cat only and does not show any links/results from Cars, Trucks.

May be one way to do is it to not set catid in the form but is it possible to use "isstart" in the form input where it will look for all sub-cats under that main category.

currently it has something like this:
Quote:
<input type="radio" id="searchcat" name="catid" value="14" /><label for="searchcat">only this category</label>

Instead of setting the catid value, is there way to use isstart or something in the form?


Thanks!

Last edited by:

socrates: Oct 21, 2017, 12:03 AM
Quote Reply
Re: [socrates] Search only this (parent) category but also show links/results from all subcategories In reply to
Hi,

I'm not sure why you are not seeing the results you want. That sounds like how it works as default:

Code:
my @cat_ids = $IN->param('catid') or return $results;
my (@children, %seen);
foreach my $id (@cat_ids) {
next if ($id !~ /^\d+$/);
my $child = $cat_db->children($id) or next;
push @children, @$child, $id;
}

This bit:

Code:
my $child = $cat_db->children($id) or next;

Will get all the sub-categories, and then add those ID's into the list of ID's to search for. Are you sure its not working right?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Search only this (parent) category but also show links/results from all subcategories In reply to
Hi Andy,

Ok, I thought that is how it worked by default too but it does not. I will have to open up search.pm and see if there are any changes and if it is because of another mod that I did with your help in this thread P316813 (I don't know how to post the forum link here). I will test it further and will post again later. Thanks!
Quote Reply
Re: [socrates] Search only this (parent) category but also show links/results from all subcategories In reply to
Hi,

In Search.pm, you could find:

Code:
@children = grep !$seen{$_}++, @children;

and then dump out the ID's with:

Code:
print $IN->header;
use Data::Dumper;
print Dumper(@children);

...to see what ID's it is actually grabbing.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!