How can I improve the Search component in joomla 2.5 to set search by my custom component? Can't find, where I can modify the search request to database.


With help of Rene Korss I solve the problem.

  1. Made a custom search plugin with files:
    • customsearch.php

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once JPATH_SITE .  '/components/com_nhotel/helpers/route.php';

class plgSearchCustomsearch extends JPlugin {

    function __construct(& $subject, $config)
        parent::__construct($subject, $config);

    function onContentSearchAreas() {
        static $areas = array(
            'customsearch' => 'Customsearch'
        return $areas;

     function onContentSearch( $text, $phrase='', $ordering='', $areas=null ) {
        $db = JFactory::getDBO();
        $user   = JFactory::getUser();
        $groups = implode(',', $user->getAuthorisedViewLevels());

        // If the array is not correct, return it:
        if (is_array( $areas )) {
            if (!array_intersect( $areas, array_keys( $this->onContentSearchAreas() ) )) {
                return array();

        $text = trim( $text );

        // Return Array when nothing was filled in.
        if ($text == '') {
            return array();

        $wheres = array();

        switch ($phrase) {

            // Search exact
            case 'exact':
                $text       = $db->Quote( '%'.$db->escape( $text, true ).'%', false );
                $wheres2    = array();
                $wheres2[]  = 'LOWER(a.greeting) LIKE '.$text;
                $where      = '(' . implode( ') OR (', $wheres2 ) . ')';

            // Search all or any
            case 'all':
            case 'any':

                // Set default
                $words  = explode( ' ', $text );
                $wheres = array();
                foreach ($words as $word)
                    $word       = $db->Quote( '%'.$db->escape( $word, true ).'%', false );
                    $wheres2    = array();
                    $wheres2[]  = 'LOWER(a.greeting) LIKE '.$word;
                    $wheres[]   = implode( ' OR ', $wheres2 );
                $where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';

        // Ordering of the results
        switch ( $ordering ) {

            //Alphabetic, ascending
            case 'alpha':
                $order = 'a.greeting ASC';

            // Oldest first
            case 'oldest':

                // Popular first
            case 'popular':

                // Newest first
            case 'newest':

                // Default setting: alphabetic, ascending
                $order = 'a.greeting ASC';

        $section = JText::_( 'Customsearch' );

        $query  = $db->getQuery(true);
        $query->select('a.greeting AS title, a.description AS text');
        $query->select('"1" AS browsernav');
        $query->from('#__customtable AS a');
        $db->setQuery( $query, 0, $limit );
        $rows = $db->loadObjectList();

        foreach($rows as $key => $row) {
            // This link I will correct later to my link structure
            $rows[$key]->href = 'custom_link_to_result_article';

        //Return the search results in an array
        return $rows;

next, I install the plugin and switch it on. Ready to use!

  • Joomla! 2.5´s how to create search plugin docs is here. You said that 3.x one was understandable, what exactly was understandable?
    – Rene Korss
    Mar 23, 2016 at 10:36
  • I tried to make a search plugin by manual. But there is no result. I think the problem in SQL query and i don't understand how the switch "exact-all-any" working. The plugin pack is here - link Mar 23, 2016 at 13:37
  • In plugin I tried to search rsults from DB table - #__nhotel. Searching by greeting and description, where state = 1. Mar 23, 2016 at 13:40
  • I looked at your plugin. Your query is definately incorrect. Use print_r($db->getQuery()); to print out resulting SQL query and fix it. For starters c.state=1 in WHERE is not needed, since you don't join categories in. And $case_when and $case_when1 is not needed etc. Just go step by step. Also, you are searching by a.name, it seems your table dosen't have such column. Try searching by title (a.greeting) to get going.
    – Rene Korss
    Mar 24, 2016 at 6:39
  • 2
    Please edit your question - add your initial code to it and tell the exact issue. Then we can vote to reopen this and I can answer it with already existing solution.
    – Rene Korss
    Mar 25, 2016 at 10:02

1 Answer 1


You can't use joomla search engine for custom component.

The only thing if component doesn't have it's own search engine, write a new component which will look in a specific place of Your data base.

  • And what about search plugin for custom component? I found the manual to make this plugin link, but it is for joomla 3.0 and not really understandable -( Mar 22, 2016 at 21:53
  • Try something like Joomla extension it has some of the extensions included maybe it will have yours.
    – ekavet
    Mar 22, 2016 at 22:35
  • And by the way never try it but i looks kinda cool component-creator maybe it will give some ideas for You:)
    – ekavet
    Mar 22, 2016 at 22:50
  • This component "Universal Ajax Search" will search only by articles and/or vm products. My component have it own DB table and won't be included in search results i think. Mar 23, 2016 at 6:04
  • Actually you can use search engine on your custom components, you just need to develop the plugins to index your contents.
    – Kitase88
    Apr 1, 2016 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.