I'm not completely following you, maybe a sample file would help. But maybe you make a stored calculation field that concatenates the category, part number and item. Then search that field and/or use it in the portal filter calculation expression.
At first I think you would get your category / subcategory selection to globals and use a script to determine if they are empty or not. Based on that use an eSQL query to pull in the matches.
if it's just a keyword or a category the script defaults to the way you have it. If it's all three the query goes to work.
I am sure you will get some other answers that might be better.
I wouldn't use the If function like you have. Might use case, or might use (), and, and or functions.
Example for just filtering by Category:
IsEmpty ( Layout::Category ) OR
Portal::Category = Layout::Category
If you don't specify a category, you get all categories.
The same method works for keyword or other partial string matching. Combining both for the same search portal can get complex, but is workable if the table being searched is not so large that you get delays waiting for the portal to update.
( IsEmpty ( Layout::Category ) OR
Portal::Category = Layout::Category )
(IsEmpty ( Layout::Keyword ) OR
PatternCount ( Portal::Description ; Layout::Keyword ) > 0 )
Is just one possible expression that you might use.
Thank you for all your comments. After implementing Phil's calculation to my portal filter, that's got it working as id like.