Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:32:04+00:00 2026-06-12T20:32:04+00:00

I am using Magento 1.7.0.2 and I am badly stuck in the problem. the

  • 0

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

  1. catalogsearch_result table in magento database has an index named PRIMARY and error happens due this table
  2. catalogsearch_query table records the search term
  3. 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
  4. 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

  1. I emptied catalogsearch_results and catalogsearch_query tables but this error pops up again

  2. I download the right magento version, replaced even complete catalagsearch folder, but no vain..

  3. I tried re-indexing, clearing the magento cache fully (both through back end admin and manually deleting var folder)

  4. triead disabling CATALOGSEARCH module and re-enabling it…

  5. 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..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:32:06+00:00Added an answer on June 12, 2026 at 8:32 pm

    @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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first time using Magento. I upgraded this site from 1.4.1.1 to
I'm setting up Magento installation (using bitnami magento image 1.7.0) and can't get PayPal
Using Magento i want to create website where user can upload their products to
I'm using Magento 1.5.1 and I try to show the total of the cart
I'm using the Magento Soap Api to upload pictures of products. I can't seem
I am using Magento and I'm trying to fix a small issue I have
I am currently using Magento ver. 1.5.0.1. Can anyone tell me how do i
I'm using magento and all my urls contains index.php. Can anyone give me the
I really hope someone here can help out with this. I'm using Magento 1.6.1.0
I am using Magento. I would like someone to confirm the following issue pertaining

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.