Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 2 of 2
SphinxSearch on Magento - Quick Guide
 
dtcuk
Member
 
Total Posts:  55
Joined:  2009-02-28
 

Good,

Just go to catalog -> search terms and select all -> action -> delete

 
Magento Community Magento Community
Magento Community
Magento Community
 
webtrade
Jr. Member
 
Total Posts:  10
Joined:  2011-05-23
 

Hi again

Any reason you can think of why there are only a maximum of 399 results showing in magento despite $results showing there are more matches?

I really appreciate your help so far.

 
Magento Community Magento Community
Magento Community
Magento Community
 
dtcuk
Member
 
Total Posts:  55
Joined:  2009-02-28
 

Hi,

The bit that sets the amount of results in Sphinx is

$cl->SetLimits(0250);

Therefore adjust SetLimits.

Otherwise it would be because some of the results are duplicated and not unique.

Each product id has to be unique.

Thats all i can think of.

 
Magento Community Magento Community
Magento Community
Magento Community
 
webtrade
Jr. Member
 
Total Posts:  10
Joined:  2011-05-23
 

Thanks for the reply. Figured it out now, there’s also a 3rd argument to SetLimits() API call that also defaults to 1000 and must be raised if you want to return more than 1000 results.

 
Magento Community Magento Community
Magento Community
Magento Community
 
chaosinmind
Jr. Member
 
Total Posts:  14
Joined:  2009-06-28
 

Hey guys im a bit entry-level to development, php, sql, etc. but I’m very technical in nature.  I’ve worked with linux web servers and web sites for roughly 10 years on a basic level.

Can you just briefly explain what each of those scripts are and where to place them? I know the INSERT statement is for SQL for example but overall I’m not sure what to do with the code provided.

I just need pointed in the right direction.

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
chaosinmind
Jr. Member
 
Total Posts:  14
Joined:  2009-06-28
 

EDIT: Accidently posted twice.

 
Magento Community Magento Community
Magento Community
Magento Community
 
chaosinmind
Jr. Member
 
Total Posts:  14
Joined:  2009-06-28
 

I completely understand what needs to be done now. 

dtcuk - 13 February 2011 06:37 AM

The only Magent code that needs changing is Mage_CatalogSearch_Model_Mysql4_Fulltext

At the top you need to add:

include(' *****[path to your sphinx php api on your server]  ');

then find the function

public function prepareResult($object$queryText$query)

One issue though.  I looked in /app/code/core/Mage/CatalogSearch/Model/Mysql4/Fulltext but none of the .php files had any reference to public function prepareResult($object, $queryText, $query) .

The only thing I found in all of those files is class Mage_CatalogSearch_Model_Mysql4_Fulltext extends Mage_CatalogSearch_Model_Resource_Fulltext.  The rest of the file was completely empty.

So exactly what file do I need to perform the edit?

EDIT: NEVERMIND!!!

A quick

sudo find / -name *Fulltext*
resulted in /var/www/mydomain.com/includes/src/Mage_CatalogSearch_Model_Fulltext.php

I found what I needed in that file.

 
Magento Community Magento Community
Magento Community
Magento Community
 
dtcuk
Member
 
Total Posts:  55
Joined:  2009-02-28
 

Yes, just to clarify, the file that need to be edited is now

Mage_CatalogSearch_Model_Resource_Fulltext

remember to make a copy in Local folder

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mirasvit
Guru
 
Avatar
Total Posts:  639
Joined:  2009-08-22
 

EDIT: Posted below.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ukhan2012
Jr. Member
 
Total Posts:  7
Joined:  2012-04-19
 

SOLVED
It took me a while to figure out what was going on but I finally solved the above problem basically i had deleted some products from my Magento store and sphinx search was using my older catalogsearch table from my db with the deleted products still in it.

So when a user searched the site Sphinx returned the product ID’s of the deleted products thus causing Magento to spit out a nasty error as those ID’s no longer existed.

So guys make sure Sphinx has your latest up to data catalogsearch table or you could find the same errors on your search…
SOLVED
I was wondering if anybody could help me this guide is great btw and helped me setup Spinx for my Magento store it was working fine until now when you make a search you get an error page come up and referencing to the report log this is the error below

Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`magento/catalogsearch_result`, CONSTRAINT `FK_CATSRCH_RESULT_PRD_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON

I know this is definately an error cause by the sphinx code below as when i replace the Fulltext file back to default the error is not there anymore and search results are displayed...

My sphinx config in full text is as follows

Please if anyone could help me it would be a great help as Magento default search is really rubbish and sphinx was GREAT while it lasted.....

public function prepareResult($object$queryText$query)
    
{
        
if (!$query->getIsProcessed()) {
            $searchType 
$object->getSearchType($query->getStoreId());

            
$stringHelper Mage::helper('core/string');
            
/* @var $stringHelper Mage_Core_Helper_String */

            
$bind = array(
                
':query' => $queryText
            
);
            
$like = array();

            
$fulltextCond   '';
            
$likeCond       '';
            
$separateCond   '';

            if (
$searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE
                
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE{
                $words 
$stringHelper->splitWords($queryTexttrue$query->getMaxQueryWords());
                
$likeI 0;
                foreach (
$words as $word{
                    $like[] 
'`s`.`data_index` LIKE :likew' $likeI;
                    
$bind[':likew' $likeI] '%' $word '%';
                    
$likeI ++;
                
}
                
if ($like{
                    $likeCond 
'(' join(' OR '$like) . ')';
                
}
            }
            
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT
                
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE{
                $fulltextCond 
'MATCH (`s`.`data_index`) AGAINST (:query IN BOOLEAN MODE)';
            
}
            
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE && $likeCond{
                $separateCond 
' OR ';
            
}
            
//weight devided by 1000
         
$cl = new SphinxClient();          
$cl->SetServer"localhost"9312 );
$cl->SetMatchMode(SPH_MATCH_EXTENDED2);
$cl->SetSortMode SPH_SORT_RELEVANCE  );
$cl->SetLimits(0250);
$queryText str_replace(' ','|',$queryText);
$cl->AddQuery $queryText"mysearch" );
$results $cl->RunQueries();
print_r($results);
foreach(
$results as $result){
    
if ( ! empty($result["matches"]) ) {
        
foreach ( $result["matches"as $doc => $docinfo {
            $sql
sprintf("INSERT INTO catalogsearch_result"
                
." (`query_id`, `product_id`, `relevance`) VALUES "
                
"(%d, %d, %s)"
                
" ON DUPLICATE KEY UPDATE `relevance`=VALUES(`relevance`)",
            
1,
            
$doc,
            
$docinfo['weight']/1000                
            
);
            
$this->_getWriteAdapter()->query($sql);
        
}
    }
}
            
/*$sql = sprintf("INSERT INTO `{$this->getTable('catalogsearch/result')}` "
                . "(SELECT STRAIGHT_JOIN '%d', `s`.`product_id`, MATCH (`s`.`data_index`) "
                . "AGAINST (:query IN BOOLEAN MODE) FROM `{$this->getMainTable()}` AS `s` "
                . "INNER JOIN `{$this->getTable('catalog/product')}` AS `e` "
                . "ON `e`.`entity_id`=`s`.`product_id` WHERE (%s%s%s) AND `s`.`store_id`='%d')"
                . " ON DUPLICATE KEY UPDATE `relevance`=VALUES(`relevance`)",
                $query->getId(),
                $fulltextCond,
                $separateCond,
                $likeCond,
                $query->getStoreId()
            );*/

            

            
$query->setIsProcessed(1);
        
}

        
return $this;
    
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
Mirasvit
Guru
 
Avatar
Total Posts:  639
Joined:  2009-08-22
 

Hi,

In fact, Magenta search is not perfect. Very often a user doesn’t find what he was looking for and leaves the store. Good decision is to integrate the Sphinx search engine. It greatly improves the quality and relevance of search results. Look at http://mirasvit.com/magento-extensions/magento-sphinx-search.html. You can download the trial version for free, install it to your website and make sure that the search quality is greatly improved.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 2