Version Notes
Improves the Quick Search functionality with weight on each attribute and OR/AND operator for the search query.
Download this release
Release Info
Developer | Maillotte |
Extension | 16092523a84af2a2dacb3b75a8504df4 |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- app/code/community/Evolutis/QuickSearch/Helper/Data.php +76 -0
- app/code/community/Evolutis/QuickSearch/LICENSE.txt +48 -0
- app/code/community/Evolutis/QuickSearch/Model/AdminObserver.php +93 -0
- app/code/community/Evolutis/QuickSearch/Model/Adminhtml/System/Config/Source/AndOr.php +36 -0
- app/code/community/Evolutis/QuickSearch/Model/Mysql4/Fulltext.php +299 -0
- app/code/community/Evolutis/QuickSearch/etc/adminhtml.xml +44 -0
- app/code/community/Evolutis/QuickSearch/etc/config.xml +156 -0
- app/code/community/Evolutis/QuickSearch/etc/system.xml +106 -0
- app/code/community/Evolutis/QuickSearch/sql/evolutis_quicksearch_setup/mysql4-install-1.0.0.php +63 -0
- app/etc/modules/Evolutis_QuickSearch.xml +12 -0
- app/locale/fr_FR/Evolutis_QuickSearch.csv +7 -0
- package.xml +21 -0
app/code/community/Evolutis/QuickSearch/Helper/Data.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Evolutis_QuickSearch
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to contact@evolutis.fr so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category QuickSearch
|
17 |
+
* @package Evolutis_QuickSearch
|
18 |
+
* @copyright Copyright (c) 2001-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
|
19 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
20 |
+
*/
|
21 |
+
|
22 |
+
class Evolutis_QuickSearch_Helper_Data extends Mage_Core_Helper_Abstract {
|
23 |
+
|
24 |
+
public function getNbWeight() {
|
25 |
+
return 3; //au lieu d'une const car la classe fulltext réclame cette valeur
|
26 |
+
}
|
27 |
+
|
28 |
+
/*
|
29 |
+
* Retourne le type de recherche depuis la BDD core_config_data
|
30 |
+
* false = OR ; true = AND
|
31 |
+
*
|
32 |
+
* Si pas trouvé dans la BDD alors les valeurs par défaut du XML sont utilisés
|
33 |
+
*
|
34 |
+
* Utilisée dans la classe Fulltext->prepareResult
|
35 |
+
*/
|
36 |
+
public function getTypeSearch() {
|
37 |
+
return (bool) Mage::getStoreConfig('evolutis_quicksearch/search/type', Mage::app()->getStore());
|
38 |
+
}
|
39 |
+
|
40 |
+
/*
|
41 |
+
* Retourne les valeurs des poids pour chaque Id de poids depuis la BDD core_config_data
|
42 |
+
* Id => poids
|
43 |
+
*
|
44 |
+
* Si pas trouvé dans la BDD alors les valeurs par défaut du XML sont utilisés
|
45 |
+
*
|
46 |
+
* Utilisée dans la classe Fulltext->prepareResult
|
47 |
+
*/
|
48 |
+
public function getIdWithWeight() {
|
49 |
+
$weights = array();
|
50 |
+
|
51 |
+
for ($i = 1; $i <= $this->getNbWeight(); $i++) {
|
52 |
+
$weight = Mage::getStoreConfig('evolutis_quicksearch/weight/weight_' . $i, Mage::app()->getStore());
|
53 |
+
$weights[$i] = $weight;
|
54 |
+
}
|
55 |
+
return $weights;
|
56 |
+
}
|
57 |
+
|
58 |
+
/*
|
59 |
+
* Retourne les noms des poids pour chaque Id de poids depuis la BDD core_config_data
|
60 |
+
* Id => nom
|
61 |
+
*
|
62 |
+
* Si pas trouvé dans la BDD alors les valeurs par défaut du XML sont utilisés
|
63 |
+
*
|
64 |
+
* Utilisée dans la classe AdminObserver->addFieldToAttributeEditForm
|
65 |
+
*/
|
66 |
+
public function getNameWithId() {
|
67 |
+
$weights = array();
|
68 |
+
|
69 |
+
for ($i = 1; $i <= $this->getNbWeight(); $i++) {
|
70 |
+
$weightName = $this->__(Mage::getStoreConfig('evolutis_quicksearch/weight_name/weight_' . $i, Mage::app()->getStore()));
|
71 |
+
$weights[$i] = $weightName;
|
72 |
+
}
|
73 |
+
|
74 |
+
return $weights;
|
75 |
+
}
|
76 |
+
}
|
app/code/community/Evolutis/QuickSearch/LICENSE.txt
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
Open Software License ("OSL") v. 3.0
|
3 |
+
|
4 |
+
This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work:
|
5 |
+
|
6 |
+
Licensed under the Open Software License version 3.0
|
7 |
+
|
8 |
+
1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following:
|
9 |
+
|
10 |
+
1. to reproduce the Original Work in copies, either alone or as part of a collective work;
|
11 |
+
|
12 |
+
2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work;
|
13 |
+
|
14 |
+
3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License;
|
15 |
+
|
16 |
+
4. to perform the Original Work publicly; and
|
17 |
+
|
18 |
+
5. to display the Original Work publicly.
|
19 |
+
|
20 |
+
2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works.
|
21 |
+
|
22 |
+
3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work.
|
23 |
+
|
24 |
+
4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license.
|
25 |
+
|
26 |
+
5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c).
|
27 |
+
|
28 |
+
6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
|
29 |
+
|
30 |
+
7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer.
|
31 |
+
|
32 |
+
8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation.
|
33 |
+
|
34 |
+
9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c).
|
35 |
+
|
36 |
+
10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
|
37 |
+
|
38 |
+
11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License.
|
39 |
+
|
40 |
+
12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
|
41 |
+
|
42 |
+
13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
|
43 |
+
|
44 |
+
14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
45 |
+
|
46 |
+
15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
|
47 |
+
|
48 |
+
16. Modification of This License. This License is Copyright � 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.
|
app/code/community/Evolutis/QuickSearch/Model/AdminObserver.php
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Evolutis_QuickSearch
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to contact@evolutis.fr so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category QuickSearch
|
17 |
+
* @package Evolutis_QuickSearch
|
18 |
+
* @copyright Copyright (c) 2001-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
|
19 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
20 |
+
*/
|
21 |
+
|
22 |
+
class Evolutis_QuickSearch_Model_AdminObserver {
|
23 |
+
|
24 |
+
/*
|
25 |
+
* Oberser qui se déclenche lors de la construction du formulaire d'édition d'attribut : adminhtml_catalog_product_attribute_edit_prepare_form
|
26 |
+
* On y ajoute le champs poids pour que l'utilisateur puisse choisir le niveau d'importante qu'il possède dans la recherche.
|
27 |
+
*
|
28 |
+
* Ce poids n'est prit en compte que si l'attribut est utilisé dans la Quick Search.
|
29 |
+
*/
|
30 |
+
public function addFieldToAttributeEditForm($observer) {
|
31 |
+
$fieldset = $observer->getForm()->getElement('front_fieldset');
|
32 |
+
|
33 |
+
$helper = Mage::helper('evolutis_quicksearch');
|
34 |
+
|
35 |
+
$fieldset->addField('evolutis_weight_id', 'select', array(
|
36 |
+
'name' => 'evolutis_weight_id',
|
37 |
+
'label' => $helper->__('Search weight'),
|
38 |
+
'title' => $helper->__('Search weight'),
|
39 |
+
'values'=> $helper->getNameWithId(),
|
40 |
+
'class' => 'validate-digits'
|
41 |
+
));
|
42 |
+
}
|
43 |
+
|
44 |
+
/*
|
45 |
+
* Oberser qui se déclenche avant de l'enregistrement d'un formulaire d'un model quelconque : model_save_before
|
46 |
+
* Correspond au formulaire de parametrage du module dans System > Configuration
|
47 |
+
*
|
48 |
+
* Puisqu'il est appelé par toutes les sauvegardes de formulaire, on test si l'objet de données qu'on a dans la main est du type Mage_Core_Model_Config_Data (page configuration de system)
|
49 |
+
* Puis on test si on modifie notre module
|
50 |
+
* Enfin on test si la valeur du champs type est différente de l'ancienne.
|
51 |
+
* Si les conditions sont respectés, on efface les résultats de recherches pour qu'ils soient recréés lors d'une nouvelle. On informe l'utilisateur également.
|
52 |
+
*/
|
53 |
+
public function clearResultAfterChangeConfiguration($observer) {
|
54 |
+
try {
|
55 |
+
$object = $observer->getEvent()->getData()['object'];
|
56 |
+
$helper = Mage::helper('evolutis_quicksearch');
|
57 |
+
|
58 |
+
if ($object instanceof Mage_Core_Model_Config_Data && $object->getData("path") == 'evolutis_quicksearch/search/type') {
|
59 |
+
//tableau des anciens poids (actuels)
|
60 |
+
$weightsOld = $helper->getIdWithWeight();
|
61 |
+
//tableau des nouveaux poids provenant du formulaire
|
62 |
+
$weightNew = $object->getData('groups')['weight']['fields'];
|
63 |
+
|
64 |
+
$idWeight = 1;
|
65 |
+
//on boucle tant que les poids sont identiques
|
66 |
+
while ($idWeight <= count($weightsOld) && $weightsOld[$idWeight] == $weightNew['weight_' . $idWeight]['value']) {
|
67 |
+
$idWeight++;
|
68 |
+
}
|
69 |
+
|
70 |
+
//on change le type de recherche donc on efface les résultats si ce n'était pas le même type ou un poids qui a changé
|
71 |
+
if (($idWeight - 1) != count($weightNew) || (bool) $object->getData("value") != $helper->getTypeSearch()) {
|
72 |
+
Mage::getModel('catalogsearch/fulltext')->resetSearchResults();
|
73 |
+
}
|
74 |
+
}
|
75 |
+
} catch (Exception $e) {
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
/*
|
80 |
+
* Oberser qui se déclenche avant l'enregistrement du formulaire d'édition d'attribut : catalog_entity_attribute_save_before
|
81 |
+
*
|
82 |
+
* Si sa valeur a changé alors la table evolutis_quicksearch_fulltext doit être totalement recréée.
|
83 |
+
* Un FLAG reindex pour la Fulltext est levé afin que l'utilisateur sache ce qu'il doit faire.
|
84 |
+
*/
|
85 |
+
public function addFlagReindexAfterSaveAttribute($observer) {
|
86 |
+
$attribute = $observer->getEvent()->getAttribute();
|
87 |
+
|
88 |
+
if ($attribute->getOrigData('evolutis_weight_id') != $attribute->getData('evolutis_weight_id')) {
|
89 |
+
//on change le poids d'un attribut donc on demande à reindexer si ce n'était pas le même
|
90 |
+
Mage::getSingleton('index/indexer')->getProcessByCode('catalogsearch_fulltext')->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
|
91 |
+
}
|
92 |
+
}
|
93 |
+
}
|
app/code/community/Evolutis/QuickSearch/Model/Adminhtml/System/Config/Source/AndOr.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Evolutis_QuickSearch
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to contact@evolutis.fr so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category QuickSearch
|
17 |
+
* @package Evolutis_QuickSearch
|
18 |
+
* @copyright Copyright (c) 2001-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
|
19 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
20 |
+
*/
|
21 |
+
|
22 |
+
class Evolutis_QuickSearch_Model_Adminhtml_System_Config_Source_AndOr {
|
23 |
+
|
24 |
+
/*
|
25 |
+
* Cette fonction est appelé grâce à system.xml
|
26 |
+
* Elle donne les valeurs au select de la page parametre du module.
|
27 |
+
*/
|
28 |
+
public function toOptionArray() {
|
29 |
+
$helper = Mage::helper('evolutis_quicksearch');
|
30 |
+
|
31 |
+
return array(
|
32 |
+
array('value' => '0', 'label' => $helper->__('OR (at least one word must match)')),
|
33 |
+
array('value' => '1', 'label' => $helper->__('AND (all words must match)'))
|
34 |
+
);
|
35 |
+
}
|
36 |
+
}
|
app/code/community/Evolutis/QuickSearch/Model/Mysql4/Fulltext.php
ADDED
@@ -0,0 +1,299 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Evolutis_QuickSearch
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to contact@evolutis.fr so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category QuickSearch
|
17 |
+
* @package Evolutis_QuickSearch
|
18 |
+
* @copyright Copyright (c) 2001-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
|
19 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
20 |
+
*/
|
21 |
+
|
22 |
+
class Evolutis_QuickSearch_Model_Mysql4_Fulltext extends Mage_CatalogSearch_Model_Mysql4_Fulltext {
|
23 |
+
|
24 |
+
protected function _construct() {
|
25 |
+
$this->_init('evolutis_quicksearch/fulltext', 'product_id');
|
26 |
+
$this->_engine = Mage::helper('catalogsearch')->getEngine();
|
27 |
+
$this->_helper = Mage::helper('evolutis_quicksearch');
|
28 |
+
}
|
29 |
+
|
30 |
+
public function prepareResult($object, $queryText, $query) {
|
31 |
+
//Récupération des poids
|
32 |
+
$weights = $this->_helper->getIdWithWeight();
|
33 |
+
$nbWeight = count($weights);
|
34 |
+
$andSearch = $this->_helper->getTypeSearch(); //false = or ; true = and
|
35 |
+
|
36 |
+
/*
|
37 |
+
* Requête générée pour recherches (mode débug):
|
38 |
+
*
|
39 |
+
* Ici nous recherchons les termes "1234 4567 coucou" en mode "ET"
|
40 |
+
*
|
41 |
+
* Le Match de MySQL retourne un nombre décimal correspondant à la pertinence de la recherche passée dans AGAINST pour la colonne passé dans MATCH
|
42 |
+
* Ce résultat est multiplié par le poids afin d'éviter de nous retrouvé avec des relevances (pertinences = la valeur) en doubles. Ceci pour mettre des priorités.
|
43 |
+
* Le Match en mode ET est utilisé avec des + devant chaque mots.
|
44 |
+
* Le Match ne fonctionne pas avec moins de 4 caractères (limitation MySQL) donc il faut se servir du LIKE à la fin.
|
45 |
+
* Nous décomposons dont nos 3 termes que nous lions avec des AND dans notre cas (OR sinon).
|
46 |
+
* Afin que la recherche retourne des résultats avec le mode ET alors qu'ils ne sont pas tous présents dans le même champs "poids",
|
47 |
+
* nous appliquons un Match sur le champs data_index qui les comporte tous.
|
48 |
+
*
|
49 |
+
* data_index = tous les champs concaténés sans soucis de poids
|
50 |
+
* data_index_1 = tous les champs cacaténés ayant le poids d'Id 1
|
51 |
+
* data_index_2 = tous les champs cacaténés ayant le poids d'Id 2
|
52 |
+
* data_index_3 = tous les champs cacaténés ayant le poids d'Id 3
|
53 |
+
|
54 |
+
set @query = '+"1234" +"4567" +"coucou"';
|
55 |
+
|
56 |
+
SELECT *,
|
57 |
+
|
58 |
+
match(`data_index`) against(@query in boolean mode) as relevance,
|
59 |
+
|
60 |
+
match(`data_index_1`) against(@query in boolean mode) as relevance_1,
|
61 |
+
match(`data_index_2`) against(@query in boolean mode) as relevance_2,
|
62 |
+
match(`data_index_3`) against(@query in boolean mode) as relevance_3,
|
63 |
+
|
64 |
+
(
|
65 |
+
match(`data_index_1`) against(@query in boolean mode) * 1 +
|
66 |
+
|
67 |
+
match(`data_index_2`) against(@query in boolean mode) * 2 +
|
68 |
+
match(`data_index_3`) against(@query in boolean mode) * 3
|
69 |
+
) * match(`data_index`) against(@query in boolean mode)as relevanceTotal
|
70 |
+
|
71 |
+
FROM `evolutis_quicksearch_fulltext`
|
72 |
+
|
73 |
+
WHERE
|
74 |
+
|
75 |
+
match(`data_index`) against(@query in boolean mode) OR
|
76 |
+
(`data_index` LIKE '%1234%' AND `data_index` LIKE '%4567%' AND `data_index` LIKE '%coucou%'))
|
77 |
+
|
78 |
+
ORDER BY relevanceTotal DESC
|
79 |
+
*/
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
/*
|
84 |
+
* Code original Magento recopié
|
85 |
+
*/
|
86 |
+
$adapter = $this->_getWriteAdapter();
|
87 |
+
if (!$query->getIsProcessed()) {
|
88 |
+
$searchType = $object->getSearchType($query->getStoreId());
|
89 |
+
|
90 |
+
$preparedTerms = Mage::getResourceHelper('catalogsearch')
|
91 |
+
->prepareTerms($queryText, $query->getMaxQueryWords());
|
92 |
+
|
93 |
+
$bind = array();
|
94 |
+
$like = array();
|
95 |
+
$likeCond = '';
|
96 |
+
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE
|
97 |
+
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE
|
98 |
+
) {
|
99 |
+
$helper = Mage::getResourceHelper('core');
|
100 |
+
$words = Mage::helper('core/string')->splitWords($queryText, true, $query->getMaxQueryWords());
|
101 |
+
foreach ($words as $word) {
|
102 |
+
$like[] = $helper->getCILike('s.data_index', $word, array('position' => 'any'));
|
103 |
+
}
|
104 |
+
if ($like) {
|
105 |
+
/*
|
106 |
+
* Modification pour le type de recherce
|
107 |
+
*/
|
108 |
+
$operator = ($andSearch ? ' AND ' : ' OR ');
|
109 |
+
$likeCond = '(' . join($operator, $like) . ')';
|
110 |
+
}
|
111 |
+
}
|
112 |
+
$mainTableAlias = 's';
|
113 |
+
$fields = array(
|
114 |
+
'query_id' => new Zend_Db_Expr($query->getId()),
|
115 |
+
'product_id',
|
116 |
+
);
|
117 |
+
$select = $adapter->select()
|
118 |
+
->from(array($mainTableAlias => $this->getMainTable()), $fields)
|
119 |
+
->joinInner(array('e' => $this->getTable('catalog/product')),
|
120 |
+
'e.entity_id = s.product_id',
|
121 |
+
array())
|
122 |
+
->where($mainTableAlias.'.store_id = ?', (int)$query->getStoreId());
|
123 |
+
|
124 |
+
if ($searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_FULLTEXT
|
125 |
+
|| $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
|
126 |
+
$operator = ($andSearch ? ' +' : ' ');
|
127 |
+
//enlever les " pour que match autocomplete les mots
|
128 |
+
$bind[':query'] = implode($operator, $preparedTerms[0]);
|
129 |
+
|
130 |
+
//pour le where on match sur la première colonne data_index afin que les résultats ressortent
|
131 |
+
$where = 'MATCH ('.$mainTableAlias.'.data_index) AGAINST (:query IN BOOLEAN MODE)';
|
132 |
+
|
133 |
+
//ici match sql
|
134 |
+
$match = "";
|
135 |
+
for ($i = 1; $i <= $nbWeight; $i++) {
|
136 |
+
$match .= 'MATCH ('.$mainTableAlias.'.data_index_' . $i . ') AGAINST (:query IN BOOLEAN MODE) * ' . $weights[$i];
|
137 |
+
if ($i != $nbWeight) {
|
138 |
+
$match .= ' + ';
|
139 |
+
}
|
140 |
+
}
|
141 |
+
$relevance = new Zend_Db_Expr('(' . $match . ') * ' . $where);
|
142 |
+
$select->columns(array('relevance' => $relevance));
|
143 |
+
}
|
144 |
+
|
145 |
+
if ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_COMBINE) {
|
146 |
+
$where .= ($where ? ' OR ' : '') . $likeCond;
|
147 |
+
} elseif ($likeCond != '' && $searchType == Mage_CatalogSearch_Model_Fulltext::SEARCH_TYPE_LIKE) {
|
148 |
+
$select->columns(array('relevance' => new Zend_Db_Expr(0)));
|
149 |
+
$where = $likeCond;
|
150 |
+
}
|
151 |
+
|
152 |
+
if ($where != '') {
|
153 |
+
$select->where($where);
|
154 |
+
}
|
155 |
+
|
156 |
+
$sql = $adapter->insertFromSelect($select,
|
157 |
+
$this->getTable('catalogsearch/result'),
|
158 |
+
array(),
|
159 |
+
Varien_Db_Adapter_Interface::INSERT_ON_DUPLICATE);
|
160 |
+
$adapter->query($sql, $bind);
|
161 |
+
$query->setIsProcessed(1);
|
162 |
+
}
|
163 |
+
|
164 |
+
return $this;
|
165 |
+
}
|
166 |
+
|
167 |
+
protected function _saveProductIndexes($storeId, $productIndexes) {
|
168 |
+
$nbWeight = $this->_helper->getNbWeight(); //Nombre de poids maximum
|
169 |
+
|
170 |
+
$valuesIntero = array(); //Les ? pour la requête SQL
|
171 |
+
$fulltextValues = array(); //Les valeurs à enregistrer dans les champs de la table evolutis_quicksearch_fulltext
|
172 |
+
|
173 |
+
//Pour chaque produits on veut son Id et son tableau d'attributs => valeurs
|
174 |
+
foreach ($productIndexes as $productId => $index) {
|
175 |
+
//Ligne de base propre à Magento (cuicksearch_fulltext) et reproduit dans notre table : product_id, store_id, data_index
|
176 |
+
$rowBase = array($productId, $storeId, '?');
|
177 |
+
|
178 |
+
for ($i = 0; $i < $nbWeight; $i++) {
|
179 |
+
//Les ? en plus pour chaque poids
|
180 |
+
$rowBase[] = '?';
|
181 |
+
}
|
182 |
+
|
183 |
+
//La chaîne temporaire qui contiendra les attributs concaténés à enregistrer dans les champs
|
184 |
+
$all = "";
|
185 |
+
//Tableau de regroupement des attributs par poids tableau[poids_id][attribut_id]
|
186 |
+
$data_index = array();
|
187 |
+
|
188 |
+
//Pour notre tableau d'attributs propre à notre produit (qu'on a dans la main), on veut son id => sa valeur
|
189 |
+
foreach ($index as $entity_id => $value) {
|
190 |
+
//On prend la valeur au premier l'indice (qui est une chaîne d'où le reset() qui pointe sur la première valeur) + '|' pour la séparation (arbitraire)
|
191 |
+
$all .= reset($value) . '|';
|
192 |
+
|
193 |
+
//Ce tableau est utilisé plus loin mais est initialisé ici
|
194 |
+
//Pour la valeur de l'attribut poids nous enregistrons dans une "nouvelle case" la valeur de l'attribut
|
195 |
+
$data_index[$value["weight_id"]][$entity_id] = reset($value);
|
196 |
+
}
|
197 |
+
//data_index full On enlève le dernier |
|
198 |
+
$fulltextValues[] = substr($all, 0, -1);
|
199 |
+
|
200 |
+
//Pour chaque poids
|
201 |
+
for ($i = 1; $i <= $nbWeight; $i++) {
|
202 |
+
if ($data_index[$i] == null) {
|
203 |
+
$data_index[$i][] = "";
|
204 |
+
}
|
205 |
+
$fulltextValues[] = implode('|', $data_index[$i]);
|
206 |
+
}
|
207 |
+
|
208 |
+
//On crée des "rangés" de ? qui définissent chaque valeurs à rajouter dans la table
|
209 |
+
$valuesIntero[] = '('.implode(',', $rowBase).')';
|
210 |
+
}
|
211 |
+
|
212 |
+
//On remplace ou insert dans notre table les champs de bases
|
213 |
+
$sql = "REPLACE INTO `{$this->getMainTable()}`(product_id, store_id, data_index";
|
214 |
+
//puis les data_index_i
|
215 |
+
for ($i = 1; $i <= $nbWeight; $i++) {
|
216 |
+
$sql .= ", data_index_" . $i;
|
217 |
+
}
|
218 |
+
//on ajoute les ? (autant qu'il en faut séparés par des ,)
|
219 |
+
$sql .= ") VALUES" . join(',', $valuesIntero);
|
220 |
+
|
221 |
+
//On lance avec notre tableau de valeurs généré juste avant :)
|
222 |
+
$this->_getWriteAdapter()->query($sql, $fulltextValues);
|
223 |
+
|
224 |
+
return $this;
|
225 |
+
}
|
226 |
+
|
227 |
+
protected function _prepareProductIndex($indexData, $productData, $storeId) {
|
228 |
+
/*
|
229 |
+
* Code original Magento recopié
|
230 |
+
*
|
231 |
+
* Seulement ajouté notre champs "weight_id" à l'index renvoyé pour chaque boucle que fait Magento
|
232 |
+
*/
|
233 |
+
$index = array();
|
234 |
+
|
235 |
+
foreach ($this->_getSearchableAttributes('static') as $attribute) {
|
236 |
+
$attributeCode = $attribute->getAttributeCode();
|
237 |
+
|
238 |
+
if (isset($productData[$attributeCode])) {
|
239 |
+
$value = $this->_getAttributeValue($attribute->getId(), $productData[$attributeCode], $storeId);
|
240 |
+
if ($value) {
|
241 |
+
//For grouped products
|
242 |
+
if (isset($index[$attributeCode])) {
|
243 |
+
if (!is_array($index[$attributeCode])) {
|
244 |
+
$index[$attributeCode] = array($index[$attributeCode]);
|
245 |
+
}
|
246 |
+
$index[$attributeCode][] = $value;
|
247 |
+
}
|
248 |
+
//For other types of products
|
249 |
+
else {
|
250 |
+
$index[$attributeCode][] = $value;
|
251 |
+
}
|
252 |
+
//On ajoute notre attribut dans l'index
|
253 |
+
$index[$attributeCode]["weight_id"] = $attribute->getEvolutisWeightId();
|
254 |
+
}
|
255 |
+
}
|
256 |
+
}
|
257 |
+
|
258 |
+
foreach ($indexData as $entityId => $attributeData) {
|
259 |
+
foreach ($attributeData as $attributeId => $attributeValue) {
|
260 |
+
$value = $this->_getAttributeValue($attributeId, $attributeValue, $storeId);
|
261 |
+
if (!is_null($value) && $value !== false) {
|
262 |
+
$attributeCode = $this->_getSearchableAttribute($attributeId)->getAttributeCode();
|
263 |
+
|
264 |
+
if (isset($index[$attributeCode])) {
|
265 |
+
$index[$attributeCode][$entityId] = $value;
|
266 |
+
} else {
|
267 |
+
$index[$attributeCode] = array($entityId => $value);
|
268 |
+
}
|
269 |
+
//On ajoute notre attribut dans l'index
|
270 |
+
$index[$attributeCode]["weight_id"] = $this->_getSearchableAttribute($attributeId)->getEvolutisWeightId();
|
271 |
+
}
|
272 |
+
}
|
273 |
+
}
|
274 |
+
|
275 |
+
if (!$this->_engine->allowAdvancedIndex()) {
|
276 |
+
$product = $this->_getProductEmulator()
|
277 |
+
->setId($productData['entity_id'])
|
278 |
+
->setTypeId($productData['type_id'])
|
279 |
+
->setStoreId($storeId);
|
280 |
+
$typeInstance = $this->_getProductTypeInstance($productData['type_id']);
|
281 |
+
if ($data = $typeInstance->getSearchableData($product)) {
|
282 |
+
$index['options'] = $data;
|
283 |
+
}
|
284 |
+
}
|
285 |
+
|
286 |
+
if (isset($productData['in_stock'])) {
|
287 |
+
$index['in_stock'][] = $productData['in_stock'];
|
288 |
+
//On ajoute notre attribut dans l'index
|
289 |
+
$index['in_stock']["weight_id"] = $this->_getSearchableAttribute($attributeId)->getEvolutisWeightId();
|
290 |
+
}
|
291 |
+
|
292 |
+
/*
|
293 |
+
* On retourne le tableau pour que la fonction appelante (_rebuildStoreIndex) qui appelera ensuite notre fonction _saveProductIndexes (surchargée) l'insert dans notre table
|
294 |
+
*
|
295 |
+
* Le code de base retournait un $index "string" avec toutes les valeurs des attributs concaténés ce qui empêchait de trvailler avec.
|
296 |
+
*/
|
297 |
+
return $index;
|
298 |
+
}
|
299 |
+
}
|
app/code/community/Evolutis/QuickSearch/etc/adminhtml.xml
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Evolutis_QuickSearch
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to contact@evolutis.fr so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category QuickSearch
|
17 |
+
* @package Evolutis_QuickSearch
|
18 |
+
* @copyright Copyright (c) 2001-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
|
19 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
20 |
+
*/
|
21 |
+
-->
|
22 |
+
<config>
|
23 |
+
<acl>
|
24 |
+
<resources>
|
25 |
+
<admin>
|
26 |
+
<children>
|
27 |
+
<system>
|
28 |
+
<children>
|
29 |
+
<config>
|
30 |
+
<children>
|
31 |
+
<!-- Champs permission pour le module dans l'interface System -->
|
32 |
+
<evolutis_quicksearch module="quicksearch">
|
33 |
+
<title>Evolutis</title>
|
34 |
+
<sort_order>9999</sort_order>
|
35 |
+
</evolutis_quicksearch>
|
36 |
+
</children>
|
37 |
+
</config>
|
38 |
+
</children>
|
39 |
+
</system>
|
40 |
+
</children>
|
41 |
+
</admin>
|
42 |
+
</resources>
|
43 |
+
</acl>
|
44 |
+
</config>
|
app/code/community/Evolutis/QuickSearch/etc/config.xml
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Evolutis_QuickSearch
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to contact@evolutis.fr so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category QuickSearch
|
17 |
+
* @package Evolutis_QuickSearch
|
18 |
+
* @copyright Copyright (c) 2001-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
|
19 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
20 |
+
*/
|
21 |
+
-->
|
22 |
+
<config>
|
23 |
+
<modules>
|
24 |
+
<Evolutis_QuickSearch>
|
25 |
+
<version>1.0.0</version>
|
26 |
+
</Evolutis_QuickSearch>
|
27 |
+
</modules>
|
28 |
+
|
29 |
+
<global>
|
30 |
+
<models>
|
31 |
+
<evolutis_quicksearch>
|
32 |
+
<class>Evolutis_QuickSearch_Model</class>
|
33 |
+
<resourceModel>evolutis_quicksearch_mysql4</resourceModel>
|
34 |
+
</evolutis_quicksearch>
|
35 |
+
|
36 |
+
<!-- Surchage de Mage_CatalogSearch_Mysql4_Fulltext qui permet d'avoir les fonctions de préparation de recherches et d'indexages -->
|
37 |
+
<catalogsearch_mysql4>
|
38 |
+
<rewrite>
|
39 |
+
<fulltext>Evolutis_QuickSearch_Model_Mysql4_Fulltext</fulltext>
|
40 |
+
</rewrite>
|
41 |
+
</catalogsearch_mysql4>
|
42 |
+
|
43 |
+
<!-- Déclaration de l'utilisation de notre table evolutis_quicksearch_fulltext -->
|
44 |
+
<evolutis_quicksearch_mysql4>
|
45 |
+
<class>Evolutis_QuickSearch_Model_Mysql4</class>
|
46 |
+
<entities>
|
47 |
+
<fulltext>
|
48 |
+
<table>evolutis_quicksearch_fulltext</table>
|
49 |
+
</fulltext>
|
50 |
+
</entities>
|
51 |
+
</evolutis_quicksearch_mysql4>
|
52 |
+
</models>
|
53 |
+
|
54 |
+
<helpers>
|
55 |
+
<!-- Helper pour la traduction et les méthodes autour du poids dans core_config_data -->
|
56 |
+
<evolutis_quicksearch>
|
57 |
+
<class>Evolutis_QuickSearch_Helper</class>
|
58 |
+
</evolutis_quicksearch>
|
59 |
+
</helpers>
|
60 |
+
|
61 |
+
<resources>
|
62 |
+
<!-- Setup du module -->
|
63 |
+
<evolutis_quicksearch_setup>
|
64 |
+
<setup>
|
65 |
+
<module>Evolutis_QuickSearch</module>
|
66 |
+
</setup>
|
67 |
+
<connection>
|
68 |
+
<use>core_setup</use>
|
69 |
+
</connection>
|
70 |
+
</evolutis_quicksearch_setup>
|
71 |
+
<!-- "Permissio"n d'écrire dans la BDD -->
|
72 |
+
<evolutis_quicksearch_write>
|
73 |
+
<connection>
|
74 |
+
<use>core_write</use>
|
75 |
+
</connection>
|
76 |
+
</evolutis_quicksearch_write>
|
77 |
+
<!-- "Permission" de lire dans la BDD -->
|
78 |
+
<evolutis_quicksearch_read>
|
79 |
+
<connection>
|
80 |
+
<use>core_read</use>
|
81 |
+
</connection>
|
82 |
+
</evolutis_quicksearch_read>
|
83 |
+
</resources>
|
84 |
+
</global>
|
85 |
+
|
86 |
+
<!-- /!\ Partie importante !
|
87 |
+
Ici sont saisies les données par défaut pour les poids et le type de recherche.
|
88 |
+
-->
|
89 |
+
<default>
|
90 |
+
<evolutis_quicksearch>
|
91 |
+
<!--
|
92 |
+
weight_name => nom du poids
|
93 |
+
weight => valeur du poids
|
94 |
+
|
95 |
+
Il faut respecter les _Id
|
96 |
+
-->
|
97 |
+
<weight_name>
|
98 |
+
<weight_1>Low</weight_1>
|
99 |
+
<weight_2>Normal</weight_2>
|
100 |
+
<weight_3>High</weight_3>
|
101 |
+
</weight_name>
|
102 |
+
<weight>
|
103 |
+
<weight_1>1</weight_1>
|
104 |
+
<weight_2>2</weight_2>
|
105 |
+
<weight_3>3</weight_3>
|
106 |
+
</weight>
|
107 |
+
<search>
|
108 |
+
<type>0</type> <!-- 0 = OR ; 1 = AND type search -->
|
109 |
+
</search>
|
110 |
+
</evolutis_quicksearch>
|
111 |
+
</default>
|
112 |
+
|
113 |
+
<adminhtml>
|
114 |
+
<events>
|
115 |
+
<adminhtml_catalog_product_attribute_edit_prepare_form>
|
116 |
+
<observers>
|
117 |
+
<Evolutis_QuickSearch_Model_AdminObserver>
|
118 |
+
<type>singleton</type>
|
119 |
+
<class>Evolutis_QuickSearch_Model_AdminObserver</class>
|
120 |
+
<method>addFieldToAttributeEditForm</method>
|
121 |
+
</Evolutis_QuickSearch_Model_AdminObserver>
|
122 |
+
</observers>
|
123 |
+
</adminhtml_catalog_product_attribute_edit_prepare_form>
|
124 |
+
|
125 |
+
<model_save_before>
|
126 |
+
<observers>
|
127 |
+
<Evolutis_QuickSearch_Model_AdminObserver>
|
128 |
+
<type>singleton</type>
|
129 |
+
<class>Evolutis_QuickSearch_Model_AdminObserver</class>
|
130 |
+
<method>clearResultAfterChangeConfiguration</method>
|
131 |
+
</Evolutis_QuickSearch_Model_AdminObserver>
|
132 |
+
</observers>
|
133 |
+
</model_save_before>
|
134 |
+
|
135 |
+
<catalog_entity_attribute_save_before >
|
136 |
+
<observers>
|
137 |
+
<Evolutis_QuickSearch_Model_AdminObserver>
|
138 |
+
<type>singleton</type>
|
139 |
+
<class>Evolutis_QuickSearch_Model_AdminObserver</class>
|
140 |
+
<method>addFlagReindexAfterSaveAttribute</method>
|
141 |
+
</Evolutis_QuickSearch_Model_AdminObserver>
|
142 |
+
</observers>
|
143 |
+
</catalog_entity_attribute_save_before >
|
144 |
+
</events>
|
145 |
+
|
146 |
+
<translate>
|
147 |
+
<modules>
|
148 |
+
<Evolutis_QuickSearch>
|
149 |
+
<files>
|
150 |
+
<default>Evolutis_QuickSearch.csv</default>
|
151 |
+
</files>
|
152 |
+
</Evolutis_QuickSearch>
|
153 |
+
</modules>
|
154 |
+
</translate>
|
155 |
+
</adminhtml>
|
156 |
+
</config>
|
app/code/community/Evolutis/QuickSearch/etc/system.xml
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Evolutis_QuickSearch
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to contact@evolutis.fr so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category QuickSearch
|
17 |
+
* @package Evolutis_QuickSearch
|
18 |
+
* @copyright Copyright (c) 2001-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
|
19 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
20 |
+
*/
|
21 |
+
-->
|
22 |
+
<!-- Affichage de la section (page de parametres) dans System > Configuration -->
|
23 |
+
<config>
|
24 |
+
<tabs>
|
25 |
+
<evolutis_quicksearch module="evolutis_quicksearch">
|
26 |
+
<label>Evolutis</label>
|
27 |
+
<sort_order>9999</sort_order>
|
28 |
+
</evolutis_quicksearch>
|
29 |
+
</tabs>
|
30 |
+
<sections>
|
31 |
+
<evolutis_quicksearch module="evolutis_quicksearch">
|
32 |
+
<label>Evolutis QuickSearch</label>
|
33 |
+
<class>separator-top</class>
|
34 |
+
<tab>evolutis_quicksearch</tab>
|
35 |
+
<sort_order>1000</sort_order>
|
36 |
+
<show_in_default>1</show_in_default>
|
37 |
+
<show_in_website>0</show_in_website>
|
38 |
+
<show_in_store>0</show_in_store>
|
39 |
+
|
40 |
+
<groups>
|
41 |
+
<weight translate="label">
|
42 |
+
<label>Weight Settings</label>
|
43 |
+
<frontend_type>text</frontend_type>
|
44 |
+
<sort_order>1000</sort_order>
|
45 |
+
<show_in_default>1</show_in_default>
|
46 |
+
<show_in_website>0</show_in_website>
|
47 |
+
<show_in_store>0</show_in_store>
|
48 |
+
<expanded>true</expanded>
|
49 |
+
|
50 |
+
<fields>
|
51 |
+
<weight_1 translate="label">
|
52 |
+
<label>Low</label>
|
53 |
+
<frontend_type>text</frontend_type>
|
54 |
+
<validate>validate-digits</validate>
|
55 |
+
<sort_order>10</sort_order>
|
56 |
+
<show_in_default>1</show_in_default>
|
57 |
+
<show_in_website>0</show_in_website>
|
58 |
+
<show_in_store>0</show_in_store>
|
59 |
+
</weight_1>
|
60 |
+
|
61 |
+
<weight_2 translate="label">
|
62 |
+
<label>Normal</label>
|
63 |
+
<frontend_type>text</frontend_type>
|
64 |
+
<validate>validate-digits</validate>
|
65 |
+
<sort_order>20</sort_order>
|
66 |
+
<show_in_default>1</show_in_default>
|
67 |
+
<show_in_website>0</show_in_website>
|
68 |
+
<show_in_store>0</show_in_store>
|
69 |
+
</weight_2>
|
70 |
+
|
71 |
+
<weight_3 translate="label">
|
72 |
+
<label>High</label>
|
73 |
+
<frontend_type>text</frontend_type>
|
74 |
+
<validate>validate-digits</validate>
|
75 |
+
<sort_order>30</sort_order>
|
76 |
+
<show_in_default>1</show_in_default>
|
77 |
+
<show_in_website>0</show_in_website>
|
78 |
+
<show_in_store>0</show_in_store>
|
79 |
+
</weight_3>
|
80 |
+
</fields>
|
81 |
+
</weight>
|
82 |
+
<search translate="label">
|
83 |
+
<label>Search type</label>
|
84 |
+
<frontend_type>text</frontend_type>
|
85 |
+
<sort_order>2000</sort_order>
|
86 |
+
<show_in_default>1</show_in_default>
|
87 |
+
<show_in_website>0</show_in_website>
|
88 |
+
<show_in_store>0</show_in_store>
|
89 |
+
<expanded>true</expanded>
|
90 |
+
|
91 |
+
<fields>
|
92 |
+
<type translate="label">
|
93 |
+
<label>Search type</label>
|
94 |
+
<frontend_type>select</frontend_type>
|
95 |
+
<sort_order>10</sort_order>
|
96 |
+
<show_in_default>1</show_in_default>
|
97 |
+
<show_in_website>0</show_in_website>
|
98 |
+
<show_in_store>0</show_in_store>
|
99 |
+
<source_model>Evolutis_QuickSearch_Model_Adminhtml_System_Config_Source_AndOr</source_model>
|
100 |
+
</type>
|
101 |
+
</fields>
|
102 |
+
</search>
|
103 |
+
</groups>
|
104 |
+
</evolutis_quicksearch>
|
105 |
+
</sections>
|
106 |
+
</config>
|
app/code/community/Evolutis/QuickSearch/sql/evolutis_quicksearch_setup/mysql4-install-1.0.0.php
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Evolutis_QuickSearch
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to contact@evolutis.fr so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* @category QuickSearch
|
17 |
+
* @package Evolutis_QuickSearch
|
18 |
+
* @copyright Copyright (c) 2001-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
|
19 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
20 |
+
*/
|
21 |
+
|
22 |
+
$installer = $this;
|
23 |
+
$installer->startSetup();
|
24 |
+
|
25 |
+
/*
|
26 |
+
* Ligne de base propre à Magento (CatalogSearch_fulltext) et reproduit dans notre table :
|
27 |
+
* product_id, store_id, data_index
|
28 |
+
*
|
29 |
+
* data_index = tous les champs concaténés sans soucis de poids
|
30 |
+
* data_index_1 = tous les champs cacaténés ayant le poids d'Id 1
|
31 |
+
* data_index_2 = tous les champs cacaténés ayant le poids d'Id 2
|
32 |
+
* data_index_3 = tous les champs cacaténés ayant le poids d'Id 3
|
33 |
+
*
|
34 |
+
*
|
35 |
+
* ALTER TABLE afin de créer un nouvel attribut dans catalog_eav_attribut.
|
36 |
+
* Nom => "weight_id", référence l'Id d'un poids dans le XML ou BDD (core_config_data), default à 2 qui est l'id du poids dit "normal"
|
37 |
+
*/
|
38 |
+
$installer->run("
|
39 |
+
CREATE TABLE `{$this->getTable('evolutis_quicksearch/fulltext')}` (
|
40 |
+
`product_id` int(10) unsigned NOT NULL,
|
41 |
+
`store_id` smallint(5) unsigned NOT NULL,
|
42 |
+
`data_index` longtext NOT NULL,
|
43 |
+
`data_index_1` longtext NOT NULL,
|
44 |
+
`data_index_2` longtext NOT NULL,
|
45 |
+
`data_index_3` longtext NOT NULL,
|
46 |
+
PRIMARY KEY (`product_id`,`store_id`),
|
47 |
+
FULLTEXT KEY `data_index` (`data_index`),
|
48 |
+
FULLTEXT KEY `data_index_1` (`data_index_1`),
|
49 |
+
FULLTEXT KEY `data_index_2` (`data_index_2`),
|
50 |
+
FULLTEXT KEY `data_index_3` (`data_index_3`)
|
51 |
+
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
52 |
+
|
53 |
+
ALTER TABLE `{$installer->getTable('catalog/eav_attribute')}` ADD `evolutis_weight_id` INT(10) NOT NULL DEFAULT '2';
|
54 |
+
");
|
55 |
+
|
56 |
+
/*
|
57 |
+
* Arès la création de notre Fulltext, il faut le générer afin que la recherche refonctionne !
|
58 |
+
*
|
59 |
+
* Signalement à l'utilisateur par un FLAG
|
60 |
+
*/
|
61 |
+
Mage::getSingleton('index/indexer')->getProcessByCode('catalogsearch_fulltext')->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
|
62 |
+
|
63 |
+
$installer->endSetup();
|
app/etc/modules/Evolutis_QuickSearch.xml
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Evolutis_QuickSearch>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
<depends>
|
8 |
+
<Mage_CatalogSearch />
|
9 |
+
</depends>
|
10 |
+
</Evolutis_QuickSearch>
|
11 |
+
</modules>
|
12 |
+
</config>
|
app/locale/fr_FR/Evolutis_QuickSearch.csv
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"Search weight","Poids dans la recherche"
|
2 |
+
"Weight Settings","Paramétrage des poids"
|
3 |
+
"Search type","Type de recherche"
|
4 |
+
"Low","Faible"
|
5 |
+
"High","Important"
|
6 |
+
"OR (at least one word must match)","OU (au moins un mot doit correspondre)"
|
7 |
+
"AND (all words must match)","ET (tous les mots doivent correspondre)"
|
package.xml
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Evolutis_QuickSearch</name>
|
4 |
+
<version>1.0.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="https://opensource.org/licenses/OSL-3.0">Open Software License 3.0</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Improves the Quick Search functionality with weight on each attribute and OR/AND operator for the search query.</summary>
|
10 |
+
<description>This extension improves the Quick Search functionality of Magento. 
|
11 |
+
It adds a “Search weight” property on product attributes, with possible values being “Low”, “Normal” (the default) and “High”. For example, you may want to make the “Name” attribute more important than the others (such as “Description”).
|
12 |
+
This can improve the relevance of the first search results, and allow customers to find your products quicker, without having to browse several pages of results.
|
13 |
+
The extension also allows you to switch between an OR operator and an AND operator for queries with multiple words.</description>
|
14 |
+
<notes>Improves the Quick Search functionality with weight on each attribute and OR/AND operator for the search query.</notes>
|
15 |
+
<authors><author><name>Maillotte</name><user>Pierre-Adrien</user><email>contact@evolutis.fr</email></author></authors>
|
16 |
+
<date>2016-04-28</date>
|
17 |
+
<time>14:08:24</time>
|
18 |
+
<contents><target name="magecommunity"><dir name="Evolutis"><dir name="QuickSearch"><dir name="Helper"><file name="Data.php" hash="7544cf9c5f39994ecd577ca1239e2b8c"/></dir><file name="LICENSE.txt" hash="59563e7be45096d0833dade102989042"/><dir name="Model"><file name="AdminObserver.php" hash="8ae6f8ff7b711157bc9f14a8f0cfcd76"/><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Source"><file name="AndOr.php" hash="e9e41671867d8a7122a1a4da4f45a6a1"/></dir></dir></dir></dir><dir name="Mysql4"><file name="Fulltext.php" hash="d3da05082cd18613eb051689dea80617"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="37a9d8471f04348be93ec72d9fa3f32e"/><file name="config.xml" hash="f55bddaa50ca289bdd9b3e3907c89b73"/><file name="system.xml" hash="27a03095fb2430ebe547bce8e49e70f9"/></dir><dir name="sql"><dir name="evolutis_quicksearch_setup"><file name="mysql4-install-1.0.0.php" hash="b888ba69885a923d3828936ebfb01148"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Evolutis_QuickSearch.xml" hash="5d8c2ad9ca511153281020e31b974d66"/></dir></target><target name="magelocale"><dir name="fr_FR"><file name="Evolutis_QuickSearch.csv" hash="037ebc218d28acde6ee25a434878e14e"/></dir></target></contents>
|
19 |
+
<compatible/>
|
20 |
+
<dependencies><required><php><min>5.2.0</min><max>7.0.0</max></php></required></dependencies>
|
21 |
+
</package>
|