I am using Magento 1.7.0.2 and I am badly stuck in the problem.
the issue is, when I search the term for first time, it does not show anything, you can see it here this was when I searched the term gem for the first time
, and when I search the same term again, Magento shows the following error
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))
these are only first few line, not the complete, all other error are same in nature, showing some issue with files…
I investigated the issue and found that in
catalogsearch_resulttable in magento database has an index named PRIMARY and error happens due this tablecatalogsearch_query table records the search term- in
1062 Duplicate entry '1-512' for key 'PRIMARY'1 is the search query term ID and database and 512 is the product ID related to gem query work - I think this error happens when catalogusearch_result table is tried to update for the query string again, as record already exist, so this error pops up…
DONE SO FAR..
5. I emptied all log tables in database
-
I emptied catalogsearch_results and catalogsearch_query tables but this error pops up again
-
I download the right magento version, replaced even complete
catalagsearchfolder, but no vain.. -
I tried
re-indexing, clearing the magento cache fully (both through back end admin and manually deletingvarfolder) -
triead disabling
CATALOGSEARCHmodule and re-enabling it… -
Tried getting help from magento forums and google search but nothing proved to be helpful to me…
I have tried each and every option I had or I came to knw, I am striking my head for last 4 days but all in vain…
Can somebody help me please, thanks
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);
}
}
}
}
this is code in file which you are mentioning,
to me, data is passed correctly, there is logic error or something like that, not quite sure about it
see if you can guide me a bit more..
thanks..
@newbee if I propose just to uninstall this extension you’ll make it ? Your code does mostly the same what is implemented in original magento files. Only approach is not so good. This code inserts query_id, product_id and relevance into the catalogsearch_results table. The problem is that this query is executed for every search query with at least one product in result.
Pair query_id-product_id should be unique. But extension tries to add new line every time customer sends search query.
Standard magento fulltext resource checks for duplications and makes insert with “ON DUPLICATE KEY UPDATE” instruction. So query duplication is avoided.