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

filter catalog search
 
carlosalvet
Jr. Member
 
Total Posts:  4
Joined:  2011-11-24
 

Hi how can i filter the catalogsearch results by category?, y change this int file Mage_CatalogSearch_Model_Layer the function

/**
     * Prepare product collection
     *
     * @param Mage_Catalog_Model_Resource_Eav_Resource_Product_Collection $collection
     * @return Mage_Catalog_Model_Layer
     */
    public function prepareProductCollection($collection)
    
{

         
// getting root category for filter
        
$_rootcatID Mage::app()->getStore()->getRootCategoryId();
        
// subcategories information
        
$children Mage::getModel('catalog/category')
                                                   ->
getCategories($_rootcatID);

        
// new array for new store filter (condition)
        
$_array_like_condition = array('like' => $_rootcatID);

        
$collection
            
->addAttributeToSelect(Mage::getSingleton('catalog/config')
                                                       ->
getProductAttributes())
                                                       
            ->
addSearchFilter(Mage::helper('catalogsearch')->getQuery()
                                                           ->
getQueryText())
            ->
setStore(Mage::app()->getStore())
            
            
//filter root products category anexing category table anf dilter, lines added
            
->joinField('category_id','catalog/category_product','category_id',
                                             
'product_id=entity_id',null,'left')
            ->
distinct(true)
            ->
addAttributeToFilter('category_id', array('in' => $_rootcatID))

            ->
addMinimalPrice()
            ->
addFinalPrice()
            ->
addTaxPercents()
            ->
addStoreFilter()
            ->
addUrlRewrite()
            ->
groupByAttribute('entity_id'); // lines added

        
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);

        return 
$this;
    
}

but it shows me all the results, for a while was working good, and then showsme “same id 123” and add distinct and groupBy but now show me all the products.

 
Magento Community Magento Community
Magento Community
Magento Community
 
serpyre
Enthusiast
 
Avatar
Total Posts:  771
Joined:  2013-05-20
 

For reference, the problem with Sphinx is that it does not do Levenshtein distance which is available in SOLR and therefore has less accurate results. One of the many reasons the top sites use SOLR, the information below is still valid as enterprise class software has 7year cycles.

http://blogs.burnsidedigital.com/2009/07/solr-vs-sphinx-fuzzy-search/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top