I have a list of 600 products in my store. When I use the quick search feautre of magento , it will display products that have the keywords. For example if I search for 'ck' it will display results that has names like 'ck calvin klien' and 'black'. I need to display products that has only words beginning with 'ck' and not words that ends with ck. The search at the moment is it for the name attribute.

  • I'm not sure what you are talking about. Please edit your question, add context and what you want to achieve and then request reopening. – Fabian Blechschmidt Mar 3 '15 at 16:40
  • Frankly, Magento's search is a piece of junk. This is one of those times when you need to buy a module that implements Zend Lucene which is already built partially into Magento or else peruse Solr or Sphinx search. – Fiasco Labs Apr 25 '16 at 20:09

You can change the behavior for search in Settings / Configuration / Catalog how search results are loaded.

Suggestions are shown based on earlier search queries from the catalogsearch_query

Magento's default behavior is to only show results where the word starts with your search query.

As taken from Mage_CatalogSearch_Model_Resource_Query_Collection

/**
 * Set search query text to filter
 *
 * @param string $query
 * @return Mage_CatalogSearch_Model_Resource_Query_Collection
 */
public function setQueryFilter($query)
{
    $ifSynonymFor = $this->getConnection()
        ->getIfNullSql('synonym_for', 'query_text');
    $this->getSelect()->reset(Zend_Db_Select::FROM)->distinct(true)
        ->from(
            array('main_table' => $this->getTable('catalogsearch/search_query')),
            array('query'      => $ifSynonymFor, 'num_results')
        )
        ->where('num_results > 0 AND display_in_terms = 1 AND query_text LIKE ?',
            Mage::getResourceHelper('core')->addLikeEscape($query, array('position' => 'start')))
        ->order('popularity ' . Varien_Db_Select::SQL_DESC);
    if ($this->getStoreId()) {
        $this->getSelect()
            ->where('store_id = ?', (int)$this->getStoreId());
    }
    return $this;
}

The addLikeEscape position start will create a string 'ck%';

If this is not your case, you most probably have a custom module installed which overrides the default.

  • Hi Jeroen , Thank you very much for your answer, I have one more doubt is , What if the product name are like 'CK One by Calvin Klein for Men 100ml' and 'Calvin Klein CkIn2U for Women 100ml' . So if the search is done using position start then I guess It will only fetch the product that has ck at the starting of the name right? – Mimoh2008 Mar 4 '15 at 6:38
  • We are talking about two different thing here, suggestions are based on past searches and the searches can be done in a like or fulltext behavior. So if you hit search when typing ck and it isn't searched before it will search in the fulltext table, stores the result in the query table with the matching products. Second time you search the same, it will show the suggesting(based on past search) and will show the result very fast because it was indexed – Jeroen Mar 4 '15 at 8:40

I know your problem if you search sony to display sony product.

if you search ony also display all product end with onk.

Go to :

System -> Configuration -> Catalog Tab -> Catalog Search ->

Search Type Select as FullText.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.