With this modification, the search string is split into space- or comma- delimited substrings, and the search looks for anything containing all of the substrings. Enclosing a search string (or part of a search string) in single or double quotes treats that portion as its own substring. So, for example, if you search for chicken little it will return any item that contains both chicken and little, in any order, in any of the name, model, sku, or (optionally) description fields. If you search for "chicken little" (in quotes), it will return only items that contain the exact phrase (which is currently the default and only search action).
To enable more powerful searching:
Edit catalog/model/catalog/product.php
In the getProductsByKeyword and getTotalProductsByKeyword functions, replace the entire if ($keyword) {...} blocks (the originals are about 8 lines, I believe) with the following code:
Code: Select all
if ($keyword) {
$keywords = preg_split("/[\s,]*\\\"([^\\\"]+)\\\"[\s,]*|" . "[\s,]*'([^']+)'[\s,]*|" . "[\s,]+/", $keyword, 0, PREG_SPLIT_NO_EMPTY);
$sql = "SELECT *, pd.name AS name, p.image, m.name AS manufacturer, ss.name AS stock, (SELECT AVG(r.rating) FROM " . DB_PREFIX . "review r WHERE p.product_id = r.product_id GROUP BY r.product_id) AS rating FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) LEFT JOIN " . DB_PREFIX . "stock_status ss ON (p.stock_status_id = ss.stock_status_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "'";
if (!$description) {
foreach ( $keywords as $keywd => $kw ) {
$sql .= " AND (LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($kw)) . "%' OR LCASE(p.model) LIKE '%" . $this->db->escape(strtolower($kw)) . "%' OR LCASE(p.sku) LIKE '%" . $this->db->escape(strtolower($kw)) . "%')";
}
} else {
foreach ( $keywords as $keywd => $kw ) {
$sql .= " AND (LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($kw)) . "%' OR LCASE(pd.description) LIKE '%" . $this->db->escape(strtolower($kw)) . "%' OR LCASE(p.model) LIKE '%" . $this->db->escape(strtolower($kw)) . "%' OR LCASE(p.sku) LIKE '%" . $this->db->escape(strtolower($kw)) . "%')";
}
}