0

我正在为我的组件编写插件。对于这个组件,我有表“#__radiocatalog_item”,其中包含 、 、 列,id我需要在列中查找。为此,我编写了这个插件:namedescriptionname

<?php

defined('JPATH_BASE') or die;

require_once JPATH_ADMINISTRATOR.'/components/com_finder/helpers/indexer/adapter.php';

class PlgFinderRadioitem extends FinderIndexerAdapter
{
   protected $context = 'Radioitem';
   protected $extension = 'com_radiocatalog';
   protected $layout = 'item';
   protected $type_title = 'item';
   protected $table = '#__radiocatalog_item';
   protected $state_field = 'parent';
   protected $autoloadLanguage = true;

   protected function setup()
        {
           return true;
        }


   public function onFinderDelete($context, $table)
   {
      if ($context == 'com_radiocatalog.item')
      {
         $id = $table->id;
      }
      elseif ($context == 'com_finder.index')
      {
         $id = $table->id;
      }
      else
      {
         return true;
      }

      return $this->remove($id);
   }

   public function onFinderChangeState($context, $pks, $value)
   {
      if ($context == 'com_radiocatalog.item')
      {
         $this->itemStateChange($pks, $value);
      }

      if ($context == 'com_plugins.plugin' && $value === 0)
      {
         $this->pluginDisable($pks);
      }
   }

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

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

   protected function getListQuery($sql = null)
   {
      $db = JFactory::getDbo();
      $sql = $sql instanceof JDatabaseQuery ? $sql : $db->getQuery(true);
      $sql->select('a.id as id, a.name as title, a.description as description');
      $sql->from('#__radiocatalog_item AS a');

      return $sql;
   }

   protected function getStateQuery()
   {
      $sql = $this->db->getQuery(true);
      $sql->select($this->db->quoteName('a.id'));
      $sql->select($this->db->quoteName('a.name').' as title');
      $sql->from($this->db->quoteName('#__radiocatalog_item') . ' AS a');
      return $sql;
   }
}
?>

完全索引后,网站上的搜索不起作用。

4

1 回答 1

2

我正在努力解决同样的问题。所以我启用了 Joomla 调试 {Global Configuration / System / Debug System = true} 并尝试使用公共站点 SmartSearch 模块搜索术语“myterm”。然后我检查了执行的 SQL 查询。首先,找到了这个词:

SELECT t.term, t.term_id
FROM j_finder_terms AS t
WHERE t.term = 'myterm' 
AND t.phrase = 0

ID=653(稍后使用):

SELECT l.link_id,m.weight AS ordering
FROM `j_finder_links` AS l
INNER JOIN `j_finder_links_terms2` AS m 
ON m.link_id = l.link_id
WHERE l.access IN (1,1) 
AND l.state = 1 
AND (l.publish_start_date = '0000-00-00 00:00:00' OR l.publish_end_date <= '2014-01-04 17:34:00') 
AND (l.publish_end_date = '0000-00-00 00:00:00' OR l.publish_end_date >= '2014-01-04 17:34:00') 
AND m.term_id IN (653)

但是这个查询没有返回任何结果,因为 j_finder_links.access 和 j_finder_links.state 的值被设置为 0 而不是 1。

所以我建议您检查查询,如果您有同样的问题,请尝试从 getStateQuery() 方法更改您的查询或在 getListQuery() 查询中选择“1 AS 访问,1 AS 状态”并保留 $state_field 变量未设置.

对于模糊的解释,我很抱歉,我不太了解 SmartSearch 的工作原理,我只是想让它以某种方式与我的组件一起工作。

于 2014-01-04T17:52:02.343 回答