【问题标题】:SphinxQL & Phalcon\Mvc\ModelSphinxQL & Phalcon\Mvc\Model
【发布时间】:2012-12-09 10:12:29
【问题描述】:

我有一个在 MySQL 协议上运行的 Sphinx 搜索引擎,我使用 Phalcon\Db\Adapter\Pdo\Mysql 连接到它。 Sphinx 表作为模型实现。

当我尝试选择(使用 SpinxQL)时,显然,当数据库适配器尝试提取表元数据运行查询时,这些表在 SpinxQL 中不受支持且不存在。文档中有一个解决方法,展示了如何手动分配元数据......但是天生懒惰,我想尝试自动生成元数据。

我假设元数据是由数据库适配器生成的,可能是由于在 getColumnDefinition() 之后的实例上调用 getColumnsList() 或其他东西 (???) 的结果。这是我的假设正确吗?我想要扩展 Phalcon\Db\Adapter\Pdo\Mysql 并覆盖这些方法以与 Sphinx 兼容。

提前感谢您的建议!

【问题讨论】:

    标签: sphinx phalcon


    【解决方案1】:

    好的,您至少需要重写两个方法才能使其工作,下面的类可以工作:

    <?php
    
    class SphinxQlAdapter extends Phalcon\Db\Adapter\Pdo\Mysql implements Phalcon\Db\AdapterInterface
    {
    
        /**
         * This method checks if a table exists
         *
         * @param string $table
         * @param string $schema
         * @return boolean
         */
        public function tableExists($table, $schema=null)
        {
    
        }
    
        /**
         * This method describe the table's columns returning an array of
         * Phalcon\Db\Column
         *
         * @param string $table
         * @param string $schema
         * @return Phalcon\Db\ColumnInterface[]
         */
        public function describeColumns($table, $schema=null)
        {
    
        }
    
    }
    

    然后在你的连接中,你使用新的适配器:

    $di->set('db', function(){
        return new SphinxQlAdapter(
            //...
        );
    });
    

    【讨论】:

      猜你喜欢
      • 2013-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-10
      • 1970-01-01
      • 2016-12-24
      • 1970-01-01
      相关资源
      最近更新 更多