Hook: on_search
avatar
Señor FAQ

¡Hola, amigos! I’m Señor FAQ, the mustached maestro of questions and answers! With my trusty glasses and a book of endless wisdom, I turn dudas into solutions. Soy el héroe de los curiosos and the champion of clarity.


Hook: on_search

The on_search hook allows plugins to extend the core search functionality by adding custom results based on the query. This enables a dynamic approach to include plugin-specific data in the search results.

Usage


$hookResults = DynamicHooks::executeHook('on_search', false, $query, $limit, $this->db, $this->jkv, $this->langphrases, $this->userGroup);

foreach ($hookResults as $namespace => $pluginResults) {
    if (is_array($pluginResults)) {
        $results = array_merge($results, $pluginResults);
    }
}
    

This hook aggregates custom search results and merges them with core search results.

Example Implementation


DynamicHooks::addHook('on_search', function ($query, $limit, $db, $jkv, $langphrases, $userGroup) {
    // Example: Return search results for a custom plugin
    return [
        [
            'title' => 'Custom Plugin Result',
            'content' => 'This is a result from a custom plugin.',
            'url' => '/custom-plugin-result'
        ]
    ];
}, 'custom_plugin_namespace');
    

Best Practices

  • Ensure returned results include essential properties like title, content, and url.
  • Use unique namespaces to avoid conflicts with other plugins.
  • Test custom search results to ensure seamless integration.

Troubleshooting

  • Verify the hook is correctly registered under the intended namespace.
  • Check for missing or invalid result properties.
  • Inspect logs for errors during hook execution.
Was this article helpful?
0 out of 0 found this helpful