Skip to content

Instantly share code, notes, and snippets.

@balloz
Created October 13, 2016 12:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balloz/d526e7dbe14c295d706be748e294c8a4 to your computer and use it in GitHub Desktop.
Save balloz/d526e7dbe14c295d706be748e294c8a4 to your computer and use it in GitHub Desktop.
Magento 1.9.3 fixed search
From d48811b478c59299eacce45c49f2d3bb25291151 Mon Sep 17 00:00:00 2001
From: Bas Mostert <bas@iweb.co.uk>
Date: Thu, 13 Oct 2016 13:30:37 +0100
Subject: [PATCH] Fixed 1.9.3 search
---
.../Mage/CatalogSearch/Model/Resource/Fulltext.php | 56 +++++++++++-----------
.../Model/Resource/Fulltext/Collection.php | 3 +-
2 files changed, 30 insertions(+), 29 deletions(-)
diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php
index 20e9ffc..148f93c 100644
--- a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php
+++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php
@@ -350,39 +350,39 @@ class Mage_CatalogSearch_Model_Resource_Fulltext extends Mage_Core_Model_Resourc
if ($like) {
$likeCond = '(' . join(' OR ', $like) . ')';
}
+ }
- $mainTableAlias = 's';
- $fields = array('product_id');
-
- $select = $adapter->select()
- ->from(array($mainTableAlias => $this->getMainTable()), $fields)
- ->joinInner(array('e' => $this->getTable('catalog/product')),
- 'e.entity_id = s.product_id',
- array())
- ->where($mainTableAlias . '.store_id = ?', (int)$query->getStoreId());
-
- $where = "";
- if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT
- || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
- ) {
- $bind[':query'] = implode(' ', $preparedTerms[0]);
- $where = Mage::getResourceHelper('catalogsearch')
- ->chooseFulltext($this->getMainTable(), $mainTableAlias, $select);
- }
- if ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
- $where .= ($where ? ' OR ' : '') . $likeCond;
- } elseif ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE) {
- $select->columns(array('relevance' => new Zend_Db_Expr(0)));
- $where = $likeCond;
- }
+ $mainTableAlias = 's';
+ $fields = array('product_id');
- if ($where != '') {
- $select->where($where);
- }
+ $select = $adapter->select()
+ ->from(array($mainTableAlias => $this->getMainTable()), $fields)
+ ->joinInner(array('e' => $this->getTable('catalog/product')),
+ 'e.entity_id = s.product_id',
+ array())
+ ->where($mainTableAlias . '.store_id = ?', (int)$query->getStoreId());
+
+ $where = "";
+ if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT
+ || $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
+ ) {
+ $bind[':query'] = implode(' ', $preparedTerms[0]);
+ $where = Mage::getResourceHelper('catalogsearch')
+ ->chooseFulltext($this->getMainTable(), $mainTableAlias, $select);
+ }
+ if ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
+ $where .= ($where ? ' OR ' : '') . $likeCond;
+ } elseif ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE) {
+ $select->columns(array('relevance' => new Zend_Db_Expr(0)));
+ $where = $likeCond;
+ }
- $this->_foundData = $adapter->fetchPairs($select, $bind);
+ if ($where != '') {
+ $select->where($where);
}
+ $this->_foundData = $adapter->fetchPairs($select, $bind);
+
return $this;
}
diff --git a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Collection.php b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Collection.php
index bb364f2..d43e073 100644
--- a/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Collection.php
+++ b/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Collection.php
@@ -111,6 +111,7 @@ class Mage_CatalogSearch_Model_Resource_Fulltext_Collection extends Mage_Catalog
{
if (!$this->_isSearchFiltersApplied) {
$this->_applySearchFilters();
+
}
return parent::getSize();
@@ -127,7 +128,7 @@ class Mage_CatalogSearch_Model_Resource_Fulltext_Collection extends Mage_Catalog
if (!empty($foundIds)) {
$this->addIdFilter($foundIds);
} else {
- $this->getSelect()->orWhere('FALSE');
+ $this->getSelect()->where('FALSE');
}
$this->_isSearchFiltersApplied = true;
--
2.10.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment