我使用的是Magento 1.7.0.2,我在这个问题上陷入了困境。问题是,当我第一次搜索这个词时,它没有显示任何东西,你可以看到它,这里 --这是我第一次搜索这个术语的时候
,当我再次搜索同一术语时,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))这些只是前几行,不是完整的,所有其他错误本质上都是一样的,显示了一些文件的问题.
我调查了这个问题,发现在
catalogsearch_result表有一个名为PRIMARY的索引,错误发生在此表中catalogsearch_query表记录搜索项。1062 Duplicate entry '1-512' for key '中,主'1是搜索查询项ID和数据库,512是与gem查询工作相关的产品ID。到目前为止,已经完成了. 5。
catalagsearch文件夹,但没有徒劳无功。re-indexing,完全清除magento缓存(通过后端管理和手动删除var文件夹)CATALOGSEARCH模块并重新启用它.我已经试过了我所有的选择,或者我来到这里,在过去的4天里,我一直在敲我的头,但都是徒劳的……
有谁能帮帮我吗,谢谢
for 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);
}
}
}
} 这是你提到的文件中的代码,
对我来说,数据是正确传递的,有逻辑错误之类的,不太确定。
看看你能不能再指导我一点..。
谢谢..。
发布于 2012-10-12 21:30:56
@newbee,如果我建议卸载这个分机,你会做吗?您的代码与在原始magento文件中实现的基本相同。唯一的方法不是那么好。此代码将query_id、product_id和关联插入到catalogsearch_results表中。问题是,对于每个搜索查询,结果中至少有一个产品,则执行此查询。
对查询_id-产品_id应该是唯一的。但是每次客户发送搜索查询时,扩展都会尝试添加新行。
标准magento全文资源检查的重复,并使插入与“上重复的键更新”指令。因此,避免了查询重复。
发布于 2012-10-12 20:16:38
短版本:停止使用MageCoders_DefaultSearch模块。这个模块是
长篇版本:
看看你的回溯,特别是这一行
#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中不支持)。
https://stackoverflow.com/questions/12866292
复制相似问题