0

I have created a custom finder plugin to reference my custom component content, however, the content indexes as expected but it doesn't show up in the results on the front end.

Have I missed a step?

protected function index(FinderIndexerResult $item, $format = 'html')
{
    // Check if the extension is enabled
    if (JComponentHelper::isEnabled($this->extension) == false)
    {
        return;
    }

    $item->setLanguage();

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

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

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

    // Build the necessary route and path information.
    $item->url = $this->getUrl($item->id, $this->extension, $this->layout);
    $item->route = AgshowsHelperRoute::getShowRoute($item->slug, 0, $item->language);
    $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;
    }

    /*
     * Add the meta-data processing instructions based on the contact
     * configuration parameters.
     */
    // Handle the contact position.
    $item->addInstruction(FinderIndexer::META_CONTEXT, 'secretary');

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

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

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

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

/**
 * Method to setup the indexer to be run.
 *
 * @return  boolean  True on success.
 *
 * @since   2.5
 */
protected function setup()
{
    // Load dependent classes.
    require_once JPATH_SITE . '/components/com_agshows/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, a.title, a.alias, a.description, a.details AS info, a.secretary')
        ->select('a.state, a.catid')
        ->select('a.created_by_alias, a.modified, a.modified_by')
        ->select('a.metakey, a.metadesc, a.metadata, a.language')
        ->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date')
        ->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)

        ->select('us.name AS secretary')
        ->from('#__agshows_shows AS a')
        ->join('LEFT', '#__categories AS c ON c.id = a.catid')
        ->join('LEFT', '#__users AS us ON us.id = a.secretary');

    return $query;
}

I do have the rest of the standard functions for dealing with saved content and deleted content but they are almost identical to the core components.

I have noticed that the detail hover box doesn't appear on any of my indexed content like it does for articles and contacts. Is this a sign its not indexing properly.

I have debugged as best I can but just can't find whats going on.

Thanks

Lee

1

In case anyone else has this issue, I accidentally omitted the access column from the database query. So it was saving with an access level of 0 and therefore not returning any results.

New getListQuery function:

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, a.title, a.alias, a.description, a.details AS info, a.secretary')
        ->select('a.state, a.catid')
        ->select('a.created_by_alias, a.modified, a.modified_by')
        ->select('a.metakey, a.metadesc, a.metadata, a.language, a.access')
        ->select('a.publish_up AS publish_start_date, a.publish_down AS publish_end_date')
        ->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)

        ->select('us.name AS secretary')
        ->from('#__agshows_shows AS a')
        ->join('LEFT', '#__categories AS c ON c.id = a.catid')
        ->join('LEFT', '#__users AS us ON us.id = a.secretary');

    return $query;
}

All fixed now!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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