0

我正在使用 Magento 1.7.0.2,我严重陷入了这个问题。问题是,当我第一次搜索该术语时,它没有显示任何内容,你可以在这里看到它这是我第一次搜索术语 gem 时

,当我再次搜索同一个词时,Magento 显示以下错误

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1-512' for key 'PRIMARY'

Trace:
#0 /home/stagerig/public_html/includes/src/Varien_Db_Statement_Pdo_Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /home/stagerig/public_html/includes/src/__default.php(63012): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /home/stagerig/public_html/includes/src/__default.php(52694): Zend_Db_Statement->execute(Array)
#3 /home/stagerig/public_html/includes/src/__default.php(53730): Zend_Db_Adapter_Abstract->query('INSERT INTO srl...', Array)
#4 /home/stagerig/public_html/includes/src/__default.php(54566): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO srl...', Array)
#5 /home/stagerig/public_html/includes/src/MageCoders_DefaultSearch_Model_Mysql4_Fulltext.php(27): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO srl...')
#6 /home/stagerig/public_html/includes/src/Mage_CatalogSearch_Model_Fulltext.php(136): MageCoders_DefaultSearch_Model_Mysql4_Fulltext->prepareResult(Object(Mage_CatalogSearch_Model_Fulltext), 'gem', Object(Mage_CatalogSearch_Model_Query))
#7 /home/stagerig/public_html/includes/src/Mage_CatalogSearch_Model_Resource_Fulltext_Collection.php(55): Mage_CatalogSearch_Model_Fulltext->prepareResult()
#8 /home/stagerig/public_html/includes/src/Mage_CatalogSearch_Model_Layer.php(58): Mage_CatalogSearch_Model_Resource_Fulltext_Collection->addSearchFilter('gem')
#9 /home/stagerig/public_html/includes/src/Mage_CatalogSearch_Model_Layer.php(42): Mage_CatalogSearch_Model_Layer->prepareProductCollection(Object(Mage_CatalogSearch_Model_Resource_Fulltext_Collection))

这些只是前几行,不是完整的,所有其他错误本质上都是相同的,表明文件存在一些问题......

我调查了这个问题,发现在

  1. catalogsearch_resultmagento 数据库中的表有一个名为 PRIMARY 的索引,并且由于该表而发生错误
  2. catalogsearch_query表记录搜索词
  3. 1062 Duplicate entry '1-512' for key 'PRIMARY 1是'搜索查询词 ID 和数据库,512 是与 gem 查询工作相关的产品 ID
  4. 我认为当 catalogusearch_result 表尝试再次更新查询字符串时会发生此错误,因为记录已经存在,因此会弹出此错误...

DONE SO FAR.. 5. 我清空了数据库中的所有日志表

  1. 我清空了 catalogsearch_results 和 catalogsearch_query 表,但再次弹出此错误

  2. 我下载了正确的magento版本,甚至替换了完整的catalagsearch文件夹,但没有白费..

  3. 我试过re-indexing了,完全清除magento缓存(通过后端管理员和手动删除var文件夹)

  4. 三重禁用CATALOGSEARCH模块并重新启用它...

  5. 尝试从 magento 论坛和谷歌搜索获得帮助,但没有任何证据证明对我有帮助......

我已经尝试了每一个选择,或者我知道,过去 4 天我一直在敲我的头,但一切都是徒劳的......

有人可以帮我吗,谢谢

为艾伦

class MageCoders_DefaultSearch_Model_Mysql4_Fulltext extends Mage_CatalogSearch_Model_Mysql4_Fulltext{

    public function prepareResult($object, $queryText, $query)
    {   
         $adapter = $this->_getWriteAdapter();

         if ($query->getIsProcessed()) { return $this; }
         $mainTable = $this->getTable('catalogsearch/result');
         $queryText = mysql_escape_string(trim($queryText));    
         $product = Mage::getModel('catalog/product')->loadByAttribute('sku',$queryText);   
         if($product){
            $sql = "INSERT INTO {$mainTable} SET query_id = '".$query->getId()."',
                                                 product_id = '".$product->getId()."',
                                                 relevance = '2'";
            $adapter->query($sql);                                   
         }else{
            $name = '%'.$queryText.'%';
            $collection = Mage::getResourceModel('catalog/product_collection')
                                ->addAttributeToFilter('name',array('like'=>$name));

            if($collection->count()){   
                foreach($collection as $item){
                        $sql = "INSERT INTO {$mainTable} SET query_id = '".$query->getId()."',
                                                             product_id = '".$item->getId()."',
                                                             relevance = '1'";
                        $adapter->query($sql);                                   
                }
            }                   
         }

    }  

这是您提到的文件中的代码,

对我来说,数据传递正确,有逻辑错误或类似的东西,不太确定

看看你能不能多指导我一点..

谢谢..

4

2 回答 2

3

简短版:停止使用该MageCoders_DefaultSearch模块。这个模块是

  1. 与您的 Magento 版本不兼容

  2. 与您安装的其他扩展不兼容

  3. 与错误插入系统的某些数据不兼容。

长版:

看看你的回溯,特别是这一行

#5 /home/stagerig/public_html/includes/src/MageCoders_DefaultSearch_Model_Mysql4_Fulltext.php(27): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO srl...')

这个错误源于MageCoders_DefaultSearch_Model_Mysql4_Fulltext资源模型的方式。具体来说,它试图以与数据库关系规则不兼容的方式将数据添加到您的系统中。这不是默认的 Magento 资源模型。看来MageCoders_DefaultSearch模块已经重写了prepareResult方法。您需要检查此方法中的代码并确定此代码中是否存在逻辑错误,以及此代码是否从其他地方接收到无效信息。

更新:(此外,Magento 1.7 似乎不支持此扩展)。

于 2012-10-12T20:16:38.833 回答
1

@newbee 如果我建议仅卸载此扩展程序,您会成功吗?您的代码与原始 magento 文件中实现的代码基本相同。唯一的方法不是那么好。此代码将 query_id、product_id 和相关性插入到 catalogsearch_results 表中。问题是对于每个搜索查询都会执行此查询,结果中至少有一个产品。

对 query_id-product_id 应该是唯一的。但每次客户发送搜索查询时,扩展都会尝试添加新行。

标准的 magento 全文资源检查重复并使用“ON DUPLICATE KEY UPDATE”指令进行插入。因此避免了查询重复。

于 2012-10-12T21:30:56.300 回答