+ Antworten
Ergebnis 1 bis 5 von 5

Thema: Search plugin

  1. #1
    Neu an Board
    Registriert seit
    01.09.2005
    Beiträge
    24
    Bedankte sich
    2
    Erhielt 0 Danksagungen
    in 0 Beiträgen

    Standard Search plugin

    Hallo Ich habe ein Problem mit einem selber geschrieben Plugin es findet zwar das zu suchende wort zeigt es aber nicht an bitte um Unterstützung.

    Auszug Datenbank table test
    Code:
      `id` int(11)
      `summary` text
      `boss` varchar(255) 
      `desc` text
    mein Plugin query
    Code:
    		case 'exact':
    			$text		= $db->Quote( '%'.$db->getEscaped( $text, true ).'%', false );
    			$wheres2 	= array();
    			$wheres2[] 	= 'LOWER(a.desc) LIKE '.$text;
    			$wheres2[] 	= 'LOWER(a.summary) LIKE '.$text;
    			$wheres2[] 	= 'LOWER(a.boss) LIKE '.$text;			
    			$where 		= '(' . implode( ') OR (', $wheres2 ) . ')';
    			break;
    
    //search all or any
    		case 'all':
    		case 'any':
    
    //set default
    		default:
    			$words = explode( ' ', $text );
    			$wheres = array();
    			foreach ($words as $word) {
    				$word		= $db->Quote( '%'.$db->getEscaped( $word, true ).'%', false );
    				$wheres2 	= array();
    				$wheres2[] 	= 'LOWER(a.desc) LIKE '.$word;
    				$wheres2[] 	= 'LOWER(a.summary) LIKE '.$word;
    				$wheres2[] 	= 'LOWER(a.boss) LIKE '.$word;
    				$wheres[] 	= implode( ' OR ', $wheres2 );
    			}
    			$where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';
    			break;
    	}
    		$query = 'SELECT a.desc,'
    . ' CASE WHEN CHAR_LENGTH(a.alias) THEN CONCAT_WS(\':\', a.id, a.desc) ELSE a.id END as slug, '
            . ' "1" AS browsernav'
            . ' FROM #__reports AS a'
            . ' WHERE ( '. $where .' )'
            . ' AND a.published = 1'
            . ' ORDER BY '. $order
            ;
    
    
    	$db->setQuery( $query, 0, $limit );
    	$rows = $db->loadObjectList();
    
    	foreach($rows as $key => $row) {
    				$rows[$key]->href = 'index.php?option=com_test&view=show&id='.$row->slug;
    
            }
    	$return = array();
    	foreach($rows AS $key => $weblink) {
    		if(searchHelper::checkNoHTML($weblink, $searchText, array('desc'))) {
    			$return[] = $weblink;
    		}
    	}
    
    	return $rows;

  2. #2
    Verbringt hier viel Zeit
    Registriert seit
    31.05.2008
    Beiträge
    801
    Bedankte sich
    0
    Erhielt 268 Danksagungen
    in 214 Beiträgen

    Standard

    Ich habe den Code nur grob überflogen und mir ist aufgefallen: warum "returnst" du $rows, wenn deine Ergebnisse in $return stehen?
    lg Måria

  3. #3
    Neu an Board
    Registriert seit
    01.09.2005
    Beiträge
    24
    Bedankte sich
    2
    Erhielt 0 Danksagungen
    in 0 Beiträgen

    Standard

    ich hab es nach den docs von joomla gemacht: http://docs.joomla.org/How_to_create_a_search_plugin

  4. #4
    NTM
    NTM ist offline
    Verbringt hier viel Zeit
    Registriert seit
    08.04.2008
    Ort
    Düsseldorf
    Alter
    38
    Beiträge
    535
    Bedankte sich
    134
    Erhielt 34 Danksagungen
    in 34 Beiträgen

    Standard

    Hallo,
    schau mal hier ich hatte das selbe Problem wie du ich habe es so gelöst.

    PHP-Code:
    <?php
    //First start with information about the Plugin and yourself. For example:
    /**
     * @version             $Id: nameofplugin.php versionnumber date author
     * @copyright           Copyright
     * @license             License, for example GNU/GPL
     * All other information you would like to add
     */
     
    //To prevent accessing the document directly, enter this code:
    // no direct access
    defined'_JEXEC' ) or die( 'Restricted access' );
     
    //Now define the registerEvent and the language file. Replace 'nameofplugin' with the name of your plugin.
    $mainframe->registerEvent'onSearch''plgSearchNudeln' );
    $mainframe->registerEvent'onSearchAreas''plgSearchNudelnAreas' );
     
    JPlugin::loadLanguage'plg_search_nudeln' );
     
    //Then define a function to return an array of search areas. Replace 'nameofplugin' with the name of your plugin.
    function &plgSearchNudelnAreas()
    {
            static 
    $areas = array(
                    
    'nudeln' => 'Nudeln'
            
    );
            return 
    $areas;
    }
     
    //Then the real function has to be created. The database connection should be made. 
    //The function will be closed with an } at the end of the file.
    function plgSearchNudeln$text$phrase=''$ordering=''$areas=null )
    {
            
    $db            =& JFactory::getDBO();
            
    $user  =& JFactory::getUser(); 
     
    //If the array is not correct, return it:
            
    if (is_array$areas )) {
                    if (!
    array_intersect$areasarray_keysplgSearchNudelnAreas() ) )) {
                            return array();
                    }
            }
     
    //It is time to define the parameters! First get the right plugin; 'search' (the group), 'nameofplugin'. 
    $plugin =& JPluginHelper::getPlugin('search''nudeln');
     
    //Then load the parameters of the plugin..
    $pluginParams = new JParameter$plugin->params );
     
    //And define the parameters. For example like this..
    $limit $pluginParams->def'search_limit'50 );
     
    //Use the function trim to delete spaces in front of or at the back of the searching terms
    $text trim$text );
     
    //Return Array when nothing was filled in
    if ($text == '') {
                    return array();
            }
     
    //After this, you have to add the database part. This will be the most difficult part, because this changes per situation.
    //In the coding examples later on you will find some of the examples used by Joomla! 1.5 core Search Plugins.
    //It will look something like this.
            
    $wheres = array();
            switch (
    $phrase) {
     
    //search exact
                    
    case 'exact':
                            
    $text          $db->Quote'%'.$db->getEscaped$texttrue ).'%'false );
                            
    $wheres2       = array();
                            
    $wheres2[]   = 'LOWER(a.nudeln) LIKE '.$text;
                            
    $wheres2[]   = 'LOWER(a.zutaten) LIKE '.$text;
                            
    $where                 '(' implode') OR ('$wheres2 ) . ')';
                            break;
     
    //search all or any
                    
    case 'all':
                    case 
    'any':
     
    //set default
                    
    default:
                            
    $words         explode' '$text );
                            
    $wheres = array();
                            foreach (
    $words as $word)
                            {
                                    
    $word          $db->Quote'%'.$db->getEscaped$wordtrue ).'%'false );
                                    
    $wheres2       = array();
                                    
    $wheres2[]   = 'LOWER(a.nudeln) LIKE '.$word;
                                     
    $wheres2[]  = 'LOWER(a.zutaten) LIKE '.$word;
                                    
    $wheres[]    = implode' OR '$wheres2 );
                            }
                            
    $where '(' implode( ($phrase == 'all' ') AND (' ') OR ('), $wheres ) . ')';
                            break;
            }
     
    //ordering of the results
            
    switch ( $ordering ) {
     
    //alphabetic, ascending
                    
    case 'alpha':
                            
    $order 'a.nudeln ASC';
                            break;
     
    //oldest first
                    
    case 'oldest':
     
    //popular first
                    
    case 'popular':
     
    //newest first
                    
    case 'newest':
     
    //default setting: alphabetic, ascending
                    
    default:
                            
    $order 'a.nudeln ASC';
            }
     
    //replace nameofplugin
            
    $searchnudeln JText::_'Nudeln' );
     
    //the database query; differs per situation! It will look something like this:
           
    $query 'SELECT a.nudeln AS title,a.zutaten as text'
            
    ' FROM #__nudeln AS a'
            
    ' WHERE ( '$where .' )'
            
    ' AND a.published = 1'
            
    ' ORDER BY '$order
            
    ;


     
    //Set query
            
    $db->setQuery$query0$limit );
            
    $rows $db->loadObjectList();
     
    //The 'output' of the displayed link
            
    foreach($rows as $key => $row) {
                    
    $rows[$key]->href 'index.php?option=com_nudeln&view=nudeln';

            }
     
    //Return the search results in an array
    return $rows;
    }
    Du muß aber noch in deiner default.php im Adminbereich von deiner Komponete eine Zeile als titel bezeichnen. z. B. so
    PHP-Code:
    <th class="title">
                    <?php echo JHTML::_('grid.sort',   'Nudeln''a.nudeln', @$lists['order_Dir'], @$this->lists['order'] ); ?>
                </th>
    Viel Glück dabei

  5. Erhielt Danksagungen von:


  6. #5
    Neu an Board
    Registriert seit
    01.09.2005
    Beiträge
    24
    Bedankte sich
    2
    Erhielt 0 Danksagungen
    in 0 Beiträgen

    Standard

    Danke habe es jetzt so gelöst ohne extra Eintrag in einer default.php:

    Code:
    <?php
    
    // no direct access
    defined( '_JEXEC' ) or die( 'Restricted access' );
    
    
    $mainframe->registerEvent( 'onSearch', 'plgSearchNameofplugin' );
    $mainframe->registerEvent( 'onSearchAreas', 'plgSearchNameofpluginAreas' );
    
    //Load the Plugin language file out of the administration
    JPlugin::loadLanguage( 'plg_search_Nameofplugin', JPATH_ADMINISTRATOR);
    
    /**
     * @return array An array of search areas
     */
    function &plgSearchNameofpluginAreas() {
    	static $areas = array(
    		'Nameofplugin' => 'Nameofplugin'
    	);
    	return $areas;
    }
    
    /**
     * Search method
     *
     * @param string Target search string
     * @param string mathcing option, exact|any|all
     * @param string ordering option, newest|oldest|popular|alpha|category
     * @param mixed An array if restricted to areas, null if search all
     */
    function plgSearchNameofplugin( $text, $phrase='', $ordering='', $areas=null )
    {
    	$db		=& JFactory::getDBO();
    	$user	=& JFactory::getUser();
    
    	require_once(JPATH_SITE.DS.'components'.DS.'com_Nameofplugin'.DS.'controllers'.DS.'controller.php');
    //	require_once(JPATH_COMPONENT.DS.'controllers'.DS.'controller.php');
    
    	if (is_array( $areas )) {
    		if (!array_intersect( $areas, array_keys( plgSearchNameofpluginAreas() ) )) {
    			return array();
    		}
    	}
    
    	// load plugin params info
    	$plugin =& JPluginHelper::getPlugin('search', 'Nameofplugin');
    	$pluginParams = new JParameter( $plugin->params );
    
    	$limit = $pluginParams->def( 'search_limit', 50 );
    
    	$text = trim( $text );
    	if ( $text == '' ) {
    		return array();
    	}
    
    	$text = $db->getEscaped($text);
    
    	$searchNameofplugin = JText::_( 'Nameofplugin' );
    
    	switch ($phrase) {
    
    //search exact
    		case 'exact':
    			$text		= $db->Quote( '%'.$db->getEscaped( $text, true ).'%', false );
    			$wheres2 	= array();
    			$wheres2[] 	= 'LOWER(a.desc) LIKE '.$text;
    			$wheres2[] 	= 'LOWER(a.summary) LIKE '.$text;
    			$wheres2[] 	= 'LOWER(a.boss) LIKE '.$text;	
    				$wheres2[] 	= 'LOWER(a.address) LIKE '.$text;
    			$where 		= '(' . implode( ') OR (', $wheres2 ) . ')';
    			break;
    
    //search all or any
    		case 'all':
    		case 'any':
    
    //set default
    		default:
    			$words = explode( ' ', $text );
    			$wheres = array();
    			foreach ($words as $word) {
    				$word		= $db->Quote( '%'.$db->getEscaped( $word, true ).'%', false );
    				$wheres2 	= array();
    				$wheres2[] 	= 'LOWER(a.desc) LIKE '.$word;
    				$wheres2[] 	= 'LOWER(a.summary) LIKE '.$word;
    				$wheres2[] 	= 'LOWER(a.boss) LIKE '.$word;
    				$wheres2[] 	= 'LOWER(a.address) LIKE '.$word;
    				$wheres[] 	= implode( ' OR ', $wheres2 );
    			}
    			$where = '(' . implode( ($phrase == 'all' ? ') AND (' : ') OR ('), $wheres ) . ')';
    			break;
    	}
    
    //ordering of the results
    	switch ( $ordering ) {
    		case 'oldest':
    
    		case 'popular':
    
    //alphabetic, ascending
    		case 'alpha':
    			$order = 'a.desc ASC';
    			break;
    
    		case 'newest':
    			$order = 'a.date1 DESC';
    			
    //default setting: alphabetic, ascending		
    		default:
    			$order = 'a.date1 ASC';
    	}
    	
    //the database query;	
    $query = "SELECT a.summary AS title, a.desc as text, a.id AS slug" // should directly include Jroute... how to?
    		." FROM #__Nameofplugin AS a"
            ."\n WHERE   ( $where )"
            ."\n AND published = '1'"
            ."\n ORDER BY $order";
    	
    	$db->setQuery( $query, 0, $limit );
    	$rows = $db->loadObjectList();
    
    	foreach($rows as $key => $row) {
    				$rows[$key]->href = 'index.php?option=com_Nameofplugin&view=show&id='.$row->slug;
            }
    
    	return $rows;
    }
    ?>

+ Antworten

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein