搜索项目时Magento错误

时间:2012-10-12 20:03:26

标签: php mysql sql magento indexing

我正在使用Magento 1.7.0.2而且我严重陷入了问题。 问题是,当我第一次搜索这个词时,它没有显示任何内容,你可以看到here这是我第一次搜索“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))

这些只是前几行,而不是完整的,所有其他错误本质上是相同的,显示文件的一些问题......

我调查了这个问题并发现了

    magento数据库中的
  1. catalogsearch_result表有一个名为PRIMARY的索引,由于此表发生错误
  2. catalogsearch_quer y表记录搜索字词
  3. in 1062 Duplicate entry '1-512' for key ' PRIMARY ' 1是搜索查询字词ID和数据库,512是与gem查询工作相关的产品ID
  4. 我认为当catalogusearch_result表再次尝试更新查询字符串时会发生此错误,因为记录已经存在,因此弹出此错误...
  5. DONE SO FAR ..  5.我清空了数据库中的所有日志表

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

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

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

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

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

    6. 我已经尝试了我所拥有的每一个选项,或者我来了,我在最近4天醒目但是徒劳无功......

      请有人帮助我,谢谢

      对于alan

      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);                                   
                      }
                  }                   
               }
      
          }  
      

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

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

      看看你是否可以引导我一点..

      感谢..

2 个答案:

答案 0 :(得分:3)

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

  1. 与您的Magento版本不兼容

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

  3. 与某些未正确插入系统的数据不兼容。

  4. 长版:

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

    #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方法。您需要检查此方法中的代码,并确定此代码中是否存在逻辑错误,如果此代码从其他位置接收到无效信息。

    已更新 :(另外,看起来像此扩展程序isn't supported on Magento 1.7)。

答案 1 :(得分:1)

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

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

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

相关问题