首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Joomla智能搜索插件:没有结果

Joomla智能搜索插件:没有结果
EN

Stack Overflow用户
提问于 2013-11-07 00:55:03
回答 1查看 1K关注 0票数 0

我在为我的组件写一个插件。对于这个组件,我有表"#__radiocatalog_item“,列为idnamedescription,我需要查找列name。为此,我写了一个插件:

代码语言:javascript
复制
<?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;
   }
}
?>

完整索引之后,网站上的搜索将无法工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-04 17:52:02

我也在为同样的问题而挣扎。因此,我启用了Joomla调试{/ System / debugging = true},并尝试使用公共站点SmartSearch模块搜索术语"myterm“。然后,我检查了执行的SQL查询。首先,找到了这个词:

代码语言:javascript
复制
SELECT t.term, t.term_id
FROM j_finder_terms AS t
WHERE t.term = 'myterm' 
AND t.phrase = 0

使用ID=653 (稍后使用):

代码语言:javascript
复制
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作为访问,1作为状态“,并保留$state_field变量未设置。

对于一个模糊的解释,我很抱歉,我不知道SmartSearch是如何工作的,我只是想让它以某种方式与我的组件一起工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19825980

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档