I use 1.3.2 and for this example I have a product called:
"finger optical mouse",
when I search for "finger mouse" I dont get any results
("finger optical" and "optical mouse" return the results fine)
how can I widen the search to help people find items easily?
Thx
G
Reason: Topic moved
The Finnish OpenCart Forum
"Real programmers don't document. If it was hard to write, it should be hard to understand."
I can repeat the problom on the 1.4.0 demo on demo.opencart.com so I dont think I am the only one to have this "bug"..
for example, lets take this demo product : http://demo.opencart.com/index.php?rout ... duct_id=33
title :
Samsung SyncMaster 941BW
desc: Imagine the advantages of going big without slowing down. The big.......
either one of the following search do not end with any result (even in advanced search with "search in description" marked):
search 1: "samsung 941bw"
search2 : "samsung 941"
search 3 : going without"
any idea how to work this out?
thx
I tried this on my 1.4 site as well and it is a problem.
In order for the search to return results, the keywords have to be in sequence. If you have a site that sells square pegs and a user searches for:
blue square peg
then no problem. But if they search for:
blue peg
then no results.
I think that this is a big issue as it makes the search far less accurate and useful and will make it much more difficult for customers to find products.
Does anyone know how to modify the search code to correct this?
Thanks!
OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter
I disagree that correcting this would do anything to noticeably slow the search. Prestashop does not have this limitation and search is very fast. This is not a Prestshop endorsement, as I feel that overall, OpenCart is a better product. I do feel that it is an issue that needs to be addressed. Good search is extremely important to the success of any ecommerce site. Customers can't purchase what they can't find.
Comparing this to Google is a bit extreme, because, most ecommerce software does not have this limitation.
OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter
OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter
Find (in BOTH function getProductsByKeyword() & function getTotalProductsByKeyword())
Code: Select all
if (!$description) {
$sql .= " AND pd.name LIKE '%" . $this->db->escape($keyword) . "%'";
} else {
$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%')";
}
Code: Select all
$keywords = explode(' ', $keyword);
if (!$description) {
foreach($keywords as $keyword) {
$sql .= " AND pd.name LIKE '%" . $this->db->escape($keyword) . "%'";
}
} else {
foreach($keywords as $keyword) {
$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%')";
}
}
Request Reviews v1.0 released.
and if you change it just a bit to:
Code: Select all
$keywords = explode(' ', $keyword);
if (!$description) {
foreach($keywords as $keyword) {
$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%')";;
}
} else {
foreach($keywords as $keyword) {
$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR pd.description LIKE '%" . $this->db->escape($keyword) . "%')";
}
}
Request Reviews v1.0 released.
find getTotalProductsByKeyword
Code: Select all
$keywords = explode(' ', $keyword);
if (!$description) {
foreach($keywords as $keyword) {
$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%')";;
}
} else {
foreach($keywords as $keyword) {
$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%')";
}
}
Code: Select all
$keywords = explode(' ', $keyword);
if (!$description) {
foreach($keywords as $keyword) {
$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%')";;
}
} else {
foreach($keywords as $keyword) {
$sql .= " AND (pd.name LIKE '%" . $this->db->escape($keyword) . "%' OR p.model LIKE '%" . $this->db->escape($keyword) . "%')";
}
}
However, since I dont really know PHP I think I have some errors. Basically the checkbox is not functioning as it should. Is it possible to search the model and the description when the checkbox is checked? How would that code look?
edit catalog/model/product/product.php
find public function getTotalProductsByKeyword
replace the whole function:
Code: Select all
public function getTotalProductsByKeyword($keyword, $category_id = 0, $description = FALSE) {
if ($keyword) {
$sql = "SELECT COUNT(*) AS total 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) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'";
if (!$description) {
$sql .= " AND LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%'";
} else {
$sql .= " AND (LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%' OR LCASE(pd.description) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%')";
}
if ($category_id) {
$data = array();
$this->load->model('catalog/category');
$string = rtrim($this->getPath($category_id), ',');
foreach (explode(',', $string) as $category_id) {
$data[] = "category_id = '" . (int)$category_id . "'";
}
$sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")";
}
$sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id";
$query = $this->db->query($sql);
if ($query->num_rows) {
return $query->row['total'];
} else {
return 0;
}
} else {
return 0;
}
}
Code: Select all
public function getTotalProductsByKeyword($keyword, $category_id = 0, $description = FALSE, $start = 0, $limit = 2000) {
if ($keyword) {
$sql = "SELECT pd.name 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') . "'";
$keywords = explode(' ', $keyword);
if (!$description) {
foreach($keywords as $keyword) {
$sql .= " AND LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%' OR LCASE(p.model) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%' ";
}
} else {
foreach($keywords as $keyword) {
$sql .= " AND LCASE(pd.description) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%' ";
}
}
if ($category_id) {
$data = array();
$this->load->model('catalog/category');
$string = rtrim($this->getPath($category_id), ',');
foreach (explode(',', $string) as $category_id) {
$data[] = "category_id = '" . (int)$category_id . "'";
}
$sql .= " AND p.product_id IN (SELECT product_id FROM " . DB_PREFIX . "product_to_category WHERE " . implode(" OR ", $data) . ")";
}
$sql .= " AND p.status = '1' AND p.date_available <= NOW() GROUP BY p.product_id";
if ($start < 0) {
$start = 0;
}
$sql .= " LIMIT " . (int)$start . "," . (int)$limit;
$query = $this->db->query($sql);
if ($query->num_rows) {
return sizeof($query->rows);
} else {
return 0;
}
} else {
return 0;
}
}
replace:
Code: Select all
if (!$description) {
$sql .= " AND LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%'";
} else {
$sql .= " AND (LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%' OR LCASE(pd.description) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%')";
}
Code: Select all
$keywords = explode(' ', $keyword);
if (!$description) {
foreach($keywords as $keyword) {
$sql .= " AND LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%' OR LCASE(p.model) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%' ";
}
} else {
foreach($keywords as $keyword) {
$sql .= " AND LCASE(pd.description) LIKE '%" . $this->db->escape(strtolower($keyword)) . "%' ";
}
}
This excellent MOD no longer works with 1.4.9
I have tried to make it work, but keep getting SQL errors.
Any of you SQL/PHP gurus out there know how to fix it?

It makes the search function so much better when the search phrase does not have to be consecutive words.
Thank you!
Users browsing this forum: No registered users and 16 guests