MyBB Community Forums

Full Version: Search hooking - Best Practice
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys,

i'm actually extending the tags plugin to hook into the board search, because its more convenient for users to have it all in one place... NOW everything isjust working great... AS LONG as the default search is giving a proper result. the 'search_do_search_process' hook isnt called because the execution is aborted with the No Result error.... BUT i cant really inject results on search start, or am i missing something
I always use the search_do_search_process hook, yes. However, it seems you are correct. It is curious at best no customer has complained about this before as I did code a tagging plugin before and this is the hook I did use.

In theory, I think you could hook to error and the hijack the templates->get() object (using control_object()) to stop the error and return :
https://github.com/mybb/mybb/blob/d1b1d4....php#L1412
https://github.com/mybb/mybb/blob/d1b1d4....php#L1437

This should allow the code to continue so search_do_search_process ultimately runs.

I won't be sure if this is actually possible, but it seems to be what I would try.

Ideally, the script shouldn't stop abruptly like it does or should offer hooks before it does so devs are able to bypass it. That would require you to edit the core or wait for the change to be implemented, though.
Another thing I did implement in my plugin was to allow filtering by tags in forums, so it is possible this compensates for the limitations of the search feature.

This filtering also required hijacking the code for it to work, though.
(2024-02-07, 02:02 AM)Omar G. Wrote: [ -> ]Another thing I did implement in my plugin was to allow filtering by tags in forums, so it is possible this compensates for the limitations of the search feature.

This filtering also required hijacking the code for it to work, though.

Yes, additional filtering is working great, because you are reducing the resultset, but expanding it is just possible if there is minimum one result actually Smile atleast i'm not a huge fan of such big template hijacking, actually reading pluginlibrary mod to inject a custom hook right before the error to manipulate the resultcount, i think this is a more straight forwars solution that hijacking and reimplementing everything through the templates
Yes, perhaps adding your own hook using PluginLibrary would be the most reliable way.