Version Notes
Initial stable release
Download this release
Release Info
Developer | Activo Extensions |
Extension | Catalog_Search_Refinement |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
app/code/community/Activo/CatalogSearch/Model/Mysql4/Fulltext.php
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Activo
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to extensions@activo.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18 |
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19 |
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20 |
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
21 |
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
22 |
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23 |
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24 |
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25 |
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26 |
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
27 |
+
* THE POSSIBILITY OF SUCH DAMAGE.
|
28 |
+
*
|
29 |
+
* @category CatalogSearch
|
30 |
+
* @package Activo_CatalogSearch
|
31 |
+
* @copyright Copyright (c) 2011 Activo Inc. (http://www.activo.com)
|
32 |
+
* @license OSL 3.0
|
33 |
+
*/
|
34 |
+
class Activo_CatalogSearch_Model_Mysql4_Fulltext extends Mage_CatalogSearch_Model_Mysql4_Fulltext
|
35 |
+
{
|
36 |
+
/**
|
37 |
+
* Prepare results for query
|
38 |
+
*
|
39 |
+
* @param Mage_CatalogSearch_Model_Fulltext $object
|
40 |
+
* @param string $queryText
|
41 |
+
* @param Mage_CatalogSearch_Model_Query $query
|
42 |
+
* @return Mage_CatalogSearch_Model_Mysql4_Fulltext
|
43 |
+
*/
|
44 |
+
public function prepareResult($object, $queryText, $query)
|
45 |
+
{
|
46 |
+
if (!$query->getIsProcessed()) {
|
47 |
+
$searchType = $object->getSearchType($query->getStoreId());
|
48 |
+
|
49 |
+
$stringHelper = Mage::helper('core/string');
|
50 |
+
/* @var $stringHelper Mage_Core_Helper_String */
|
51 |
+
|
52 |
+
$bind = array(
|
53 |
+
':query' => $queryText
|
54 |
+
);
|
55 |
+
$like = array();
|
56 |
+
|
57 |
+
$fulltextCond = '';
|
58 |
+
$likeCond = '';
|
59 |
+
$separateCond = '';
|
60 |
+
|
61 |
+
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE
|
62 |
+
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
|
63 |
+
$words = $stringHelper->splitWords($queryText, true, $query->getMaxQueryWords());
|
64 |
+
$likeI = 0;
|
65 |
+
foreach ($words as $word) {
|
66 |
+
$like[] = '`s`.`data_index` LIKE :likew' . $likeI;
|
67 |
+
$bind[':likew' . $likeI] = '%' . $word . '%';
|
68 |
+
$likeI ++;
|
69 |
+
}
|
70 |
+
if ($like) {
|
71 |
+
$likeCond = '(' . join(' AND ', $like) . ')';
|
72 |
+
}
|
73 |
+
}
|
74 |
+
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT
|
75 |
+
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
|
76 |
+
$fulltextCond = 'MATCH (`s`.`data_index`) AGAINST (:query IN BOOLEAN MODE)';
|
77 |
+
}
|
78 |
+
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE && $likeCond) {
|
79 |
+
$separateCond = ' OR ';
|
80 |
+
}
|
81 |
+
|
82 |
+
$sql = sprintf("INSERT INTO `{$this->getTable('catalogsearch/result')}` "
|
83 |
+
. "(SELECT STRAIGHT_JOIN '%d', `s`.`product_id`, MATCH (`s`.`data_index`) "
|
84 |
+
. "AGAINST (:query IN BOOLEAN MODE) FROM `{$this->getMainTable()}` AS `s` "
|
85 |
+
. "INNER JOIN `{$this->getTable('catalog/product')}` AS `e` "
|
86 |
+
. "ON `e`.`entity_id`=`s`.`product_id` WHERE (%s%s%s) AND `s`.`store_id`='%d')"
|
87 |
+
. " ON DUPLICATE KEY UPDATE `relevance`=VALUES(`relevance`)",
|
88 |
+
$query->getId(),
|
89 |
+
$fulltextCond,
|
90 |
+
$separateCond,
|
91 |
+
$likeCond,
|
92 |
+
$query->getStoreId()
|
93 |
+
);
|
94 |
+
|
95 |
+
$this->_getWriteAdapter()->query($sql, $bind);
|
96 |
+
|
97 |
+
$query->setIsProcessed(1);
|
98 |
+
}
|
99 |
+
|
100 |
+
return $this;
|
101 |
+
}
|
102 |
+
}
|
app/code/community/Activo/CatalogSearch/etc/config.xml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<global>
|
4 |
+
<models>
|
5 |
+
<catalogsearch_mysql4>
|
6 |
+
<rewrite>
|
7 |
+
<fulltext>Activo_CatalogSearch_Model_Mysql4_Fulltext</fulltext>
|
8 |
+
</rewrite>
|
9 |
+
</catalogsearch_mysql4>
|
10 |
+
</models>
|
11 |
+
</global>
|
12 |
+
</config>
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Catalog_Search_Refinement</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Allow your users to refine their search when they add a search term for FREE!</summary>
|
10 |
+
<description>Allow your users to refine their search when they add a search term for FREE! This is a free and open source magento extension that modifies the Magento default search functionality to allow search refinement.</description>
|
11 |
+
<notes>Initial stable release</notes>
|
12 |
+
<authors><author><name>Activo Extensions</name><user>activo</user><email>extensions@activo.com</email></author></authors>
|
13 |
+
<date>2011-08-26</date>
|
14 |
+
<time>20:38:31</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Activo"><dir name="CatalogSearch"><dir><dir name="Model"><dir name="Mysql4"><file name="Fulltext.php" hash="ac145be8a5ae275eac97f361df0bd4ca"/></dir></dir><dir name="etc"><file name="config.xml" hash="27e29e4850087bc3ff27bd517281e8c2"/></dir></dir></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>Mage_CatalogSearch</name><channel>core</channel><min>0.1.0</min><max>2.0.0</max></package></required></dependencies>
|
18 |
+
</package>
|