Exact Match Search in Magento



There are two type of searching one the exact match search(AND) and other is not exact match search(OR). Exact Match(AND), it means the search implemented with the entire search phrase. Like if you have searched for ‘Samsung Mobile‘ then you will get only the results for ‘Samsung Mobile‘. Not Exact Match(OR), it means the search implemented with the specific word in search phrase. Like if you have searched for Samsung Mobile you will get all the results with each word separately.

By default Magento does not provide the exact match search. To achieve Exact Match search functionality in Magento Search for 1.8 follow below steps.

  1. Get the fileĀ Fulltext.php from app\code\Core\Mage\CatalogSearch\Model\Resource\ and copy to App\code\local with same structure like app\code\local\Mage\CatalogSearch\Model\Resource\Fulltext.php.
  2. Now open this file(Fulltext.php) and find following line in function prepareResult at around 330 in
    if ($like) {
       $likeCond = '(' . join(' OR ', $like) . ')';
    
  3. Now Change OR with AND like below:
    if ($like) {
        $likeCond = '(' . join(' AND ', $like) . ')';
    
  4. Now find below lines at around 354
    if ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
        $where .= ($where ? ' OR ' : '') . $likeCond;
    
  5. change OR to AND like below:
    if ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
        $where .= ($where ? ' AND ' : '') . $likeCond;
    
  6. Save the changes.
  7. Now for the final step to set the Exact match search in Magento Search go to Magento Admin > Configuration > Catalog > Catalog > Catalog Search and change the search type to Like or FullText.
Exact Match Search in Magento
Exact Match Search in Magento

So with these steps can implement your exact match search in Magento Search. Hope this will help you.