web-dev-qa-db-fra.com

plugin de recherche intelligente pour le composant personnalisé non indexé

Je ne parviens pas à implémenter un plugin de recherche intelligente pour mon composant. J'ai cherché et je n'ai trouvé que cette question qui ressemblait un peu au mien, mais cela n'a pas fonctionné dans mon cas.

Dans ce composant, j'ai une table #__descontos_promocoes À partir de laquelle j'aimerais rechercher la colonne nome.

Le Finder n'indexe rien de mon composant. J'ai essayé d'utiliser la ligne de commande pour exécuter php cli/Finder_indexer.php Et j'ai corrigé tous les avertissements/erreurs qui apparaissaient, y compris l'index non défini: HTTP_Host .

Je pense que le problème se situe peut-être quelque part dans ma fonction index(FinderIndexerResult $item, $format = 'html') mais je ne sais pas comment le résoudre.

Est-ce que quelqu'un peut m'aider s'il vous plait? Ceci est le fichier php de mon plugin:

<?php

defined('JPATH_BASE') or die;
require_once JPATH_ADMINISTRATOR . '/components/com_Finder/helpers/indexer/adapter.php';

class PlgFinderDescontosPromocoes extends FinderIndexerAdapter
{
    protected $context = 'Promocoes';
    protected $extension = 'com_descontos';
    protected $layout = 'promocoes';
    protected $type_title = 'Promocao';
    protected $table = '#__descontos_promocoes';
    protected $state_field = 'state';
    protected $autoloadLanguage = true;

    /**
     * Method to index an item. The item must be a FinderIndexerResult object.
     *
     * @param   FinderIndexerResult  $item    The item to index as an FinderIndexerResult object.
     * @param   string               $format  The item format.  Not used.
     *
     * @return  void
     *
     * @since   2.5
     * @throws  Exception on database error.
     */
    protected function index(FinderIndexerResult $item, $format = 'html')
    {
        // Check if the extension is enabled.
        if (JComponentHelper::isEnabled($this->extension) == false)
        {
            return;
        }

        $item->setLanguage();

        // Need to import component route helpers dynamically, hence the reason it's handled here.
        $path = JPATH_SITE . '/components/' . $item->extension . '/helpers/route.php';

        if (is_file($path))
        {
            include_once $path;
        }

        $extension = ucfirst(substr($item->extension, 4));

        // Initialize the item parameters.
        $registry = new JRegistry;
        $registry->loadString($item->params);
        $item->params = $registry;

        $registry = new JRegistry;
        $registry->loadString($item->metadata);
        $item->metadata = $registry;

        /*
         * Add the meta-data processing instructions based on the category's
         * configuration parameters.
         */
        // Add the meta-author.
        $item->metaauthor = $item->metadata->get('author');

        // Handle the link to the meta-data.
        $item->addInstruction(FinderIndexer::META_CONTEXT, 'link');
        $item->addInstruction(FinderIndexer::META_CONTEXT, 'metakey');
        $item->addInstruction(FinderIndexer::META_CONTEXT, 'metadesc');
        $item->addInstruction(FinderIndexer::META_CONTEXT, 'metaauthor');
        $item->addInstruction(FinderIndexer::META_CONTEXT, 'author');

        // Deactivated Methods
        // $item->addInstruction(FinderIndexer::META_CONTEXT, 'created_by_alias');

        // // Trigger the onContentPrepare event.
        // $item->summary = FinderIndexerHelper::prepareContent($item->summary, $item->params);

        // // Build the necessary route and path information.
        // $item->url = $this->getURL($item->id, $item->extension, $this->layout);

        // $class = $extension . 'HelperRoute';

        // if (class_exists($class) && method_exists($class, 'getCategoryRoute'))
        // {
        //  $item->route = $class::getCategoryRoute($item->id, $item->language);
        // }
        // else
        // {
        //  $item->route = ContentHelperRoute::getCategoryRoute($item->slug, $item->catid);
        // }

        // $item->path = FinderIndexerHelper::getContentPath($item->route);

        // // Get the menu title if it exists.
        // $title = $this->getItemMenuTitle($item->url);

        // // Adjust the title if necessary.
        // if (!empty($title) && $this->params->get('use_menu_title', true))
        // {
        //  $item->title = $title;
        // }

        // Translate the state. Categories should only be published if the parent category is published.
        // $item->state = $this->translateState($item->state);

        // Add the type taxonomy data.
        $item->addTaxonomy('Type', 'Promocao');

        // Add the language taxonomy data.
        $item->addTaxonomy('Language', $item->language);

        // Get content extras.
        FinderIndexerHelper::getContentExtras($item);

        // Index the item.
        $this->indexer->index($item);




        /**
         * I have previously tested this function with only the code bellow (still doesn't index anything):
         */

        // if (JComponentHelper::isEnabled($this->extension) == false) {
        //  return;
        // }

        // $item->url = $this->getURL($item->id, 'com_descontos&layout=promocoes', $this->layout);
        // $item->route = 'index.php?option=com_descontos&view=promocoes&layout=promocoes&id='.$item->id;
        // $item->addTaxonomy('Type', 'Promocao');
        // $item->addTaxonomy('Language', $item->language);
        // $this->indexer->index($item);
    }

    /**
     * Method to setup the indexer to be run.
     *
     * @return  boolean  True on success.
     *
     * @since   2.5
     */
    protected function setup()
    {
        // Load com_content route helper as it is the fallback for routing in the indexer in this instance.
        include_once JPATH_SITE . '/components/com_content/helpers/route.php';

        return true;
    }

    /**
     * Method to get the SQL query used to retrieve the list of content items.
     *
     * @param   mixed  $query  A JDatabaseQuery object or null.
     *
     * @return  JDatabaseQuery  A database object.
     *
     * @since   2.5
     */
    protected function getListQuery($query = null)
    {
        $db = JFactory::getDbo();

        // Check if we can use the supplied SQL query.
        $query = $query instanceof JDatabaseQuery ? $query : $db->getQuery(true)
            ->select('a.id as id, a.nome as title')
        //  ->select('a.id, a.catid, a.title, a.alias, a.url AS link, a.description AS summary')
        //  ->select('a.metakey, a.metadesc, a.metadata, a.language, a.access, a.ordering')
        //  ->select('a.created_by_alias, a.modified, a.modified_by')
        //  ->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date')
        //  ->select('a.state AS state, a.created AS start_date, a.params')
        //  ->select('c.title AS category, c.published AS cat_state, c.access AS cat_access');

        // // Handle the alias CASE WHEN portion of the query.
        // $case_when_item_alias = ' CASE WHEN ';
        // $case_when_item_alias .= $query->charLength('a.alias', '!=', '0');
        // $case_when_item_alias .= ' THEN ';
        // $a_id = $query->castAsChar('a.id');
        // $case_when_item_alias .= $query->concatenate(array($a_id, 'a.alias'), ':');
        // $case_when_item_alias .= ' ELSE ';
        // $case_when_item_alias .= $a_id . ' END as slug';
        // $query->select($case_when_item_alias);

        // $case_when_category_alias = ' CASE WHEN ';
        // $case_when_category_alias .= $query->charLength('c.alias', '!=', '0');
        // $case_when_category_alias .= ' THEN ';
        // $c_id = $query->castAsChar('c.id');
        // $case_when_category_alias .= $query->concatenate(array($c_id, 'c.alias'), ':');
        // $case_when_category_alias .= ' ELSE ';
        // $case_when_category_alias .= $c_id . ' END as catslug';
        // $query->select($case_when_category_alias)

            ->from('#__descontos_promocoes AS a');
            // ->join('LEFT', '#__categories AS c ON c.id = a.catid');

        return $query;
    }
}

Voici le résultat de la ligne de commande: (il indexe tout sauf les éléments de mon composant)

artur@artur-desktop:/var/www/10contos$ php5 cli/Finder_indexer.php 
Smart Search INDEXER
============================

Starting Indexer
Setting up Finder plugins
Setup 9 items in 0.072 seconds.
 * Processed batch 1 in 0.021 seconds.
Total Processing Time: 0.094 seconds.

Même essayer d’indexer dans le backend à l’intérieur du Finder ne fonctionne pas. Je ne reçois aucune erreur ou quoi que ce soit à l'intérieur de /var/log/Apache2/error.log

4
kingarthurpt

Vérifiez que vous utilisez la dernière version de Joomla 2.5 Assurez-vous que le plug-in SmartSearch/Finder est publié. Utilisez le module SmartSearch/Finder. Il y a 2 ... recherche et smartsearch. Exécuter l'indexeur depuis Smart Search enter image description here

Il est également utile d’avoir un lien vers Smart Search/Finder dans votre menu. Cela peut être dans un menu caché.

1
Montano