-
Notifications
You must be signed in to change notification settings - Fork 63
Custom Search Function
Programmers have the ability to customize or override the Web Store search functionality. Customers may wish to change what fields are searched, or to parse the search string in different ways to affect what results are returned.
The properly way to modify the search functionality is to extend the search class. In practice, this means creating a new file in your /custom_includes folder and copying the existing functions from the /xlsws_includes/searchresults.php file you wish to modify. You then make changes to your copy. When properly set up per the directions below, the Web Store will use your new function instead of the system default when a shopper searches on your web site.
The advantage to extending the function this way instead of simply modifying the original file is future Web Store updates will not overwrite your custom function since the /custom_includes folder will never be touched during an upgrade.
Begin by creating a file called searchresults.php in the /custom_includes folder of your web store. This filename must be used because it will be a copy of an identically-named file in Web Store.
To get going, paste in the following starter text into your new file:
<?php
define('CUSTOM_STOP_XLSWS' , true);
include_once("xlsws_includes/searchresults.php");
class my_search extends xlsws_searchresult {
//override functions here
}
xlsws_searchresult::Run('my_search', templateNamed('index.tpl.php'));
?>
This text creates the framework of a custom override. The include_once() file references the original file we will be extending. We are creating a new class name called my_search that will contain any functions you are customizing.
Open the original /xlsws_includes/searchresults.php file and copy the functions you are modifying, pasting them in your custom file inside the class (where it says //override functions here).
A common function to copy and modify is the GetCriteriaCondition() function which is used to parse the search string and build the SQL Query using LIKE statements against various fields. The default function looks for the search string within the fields Code, Name, DescriptionShort, Description and the Web Keywords. (Note that "code" refers to Product Code, "Name" is the product card description, "Description" is the Web Long Description and DescriptionShort is the Web Short Description.)
You can add or remove lines in your copy to add or remove fields that are being used in the SQL Search. Also by default, the search string is treated as one string, so a shopper searching for "blue item" would match against "big blue item" but not "blue big item". A possible modification would be to parse the string by words and then loop through the criteria so that each word is being searched for separately. The QCodo document at http://examples.qcodo.com/examples/qcodo_query/qqcondition.php may be helpful for defining your custom statements.