首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在搜索项时出现Magento错误

问在搜索项时出现Magento错误
EN

Stack Overflow用户
提问于 2012-10-12 20:03:25
回答 2查看 2K关注 0票数 0

我使用的是Magento 1.7.0.2,我在这个问题上陷入了困境。问题是,当我第一次搜索这个词时,它没有显示任何东西,你可以看到它,这里 --这是我第一次搜索这个术语的时候

,当我再次搜索同一术语时,Magento将显示以下错误

代码语言:javascript
复制
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. magento数据库中的catalogsearch_result表有一个名为PRIMARY的索引,错误发生在此表中
  2. catalogsearch_query表记录搜索项。
  3. 在1062 Duplicate entry '1-512' for key '中,主'1是搜索查询项ID和数据库,512是与gem查询工作相关的产品ID。
  4. 我认为当catalogusearch_result表再次试图更新查询字符串时会发生此错误,因为记录已经存在,因此该错误弹出.

到目前为止,已经完成了. 5。

  1. 我清空了catalogsearch_results和catalogsearch_query表,但是这个错误再次弹出
  2. 我下载了正确的magento版本,替换了甚至完整的catalagsearch文件夹,但没有徒劳无功。
  3. 我尝试了re-indexing,完全清除magento缓存(通过后端管理和手动删除var文件夹)
  4. triead禁用CATALOGSEARCH模块并重新启用它.
  5. 我试着从magento论坛和谷歌搜索那里得到帮助,但是没有什么对我有帮助.

我已经试过了我所有的选择,或者我来到这里,在过去的4天里,我一直在敲我的头,但都是徒劳的……

有谁能帮帮我吗,谢谢

for alan

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

    }  

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

对我来说,数据是正确传递的,有逻辑错误之类的,不太确定。

看看你能不能再指导我一点..。

谢谢..。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-12 21:30:56

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

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

标准magento全文资源检查的重复,并使插入与“上重复的键更新”指令。因此,避免了查询重复。

票数 1
EN

Stack Overflow用户

发布于 2012-10-12 20:16:38

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

  1. 与Magento版本不兼容
  2. 与您安装的其他扩展名不兼容
  3. 与某些数据不兼容,这些数据被错误地插入到系统中。

长篇版本:

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

代码语言:javascript
复制
#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中不支持)。

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

https://stackoverflow.com/questions/12866292

复制
相关文章

相似问题

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