I want to adjust the search function in such a way that one has to enter an exact word / code which is processed in a sentence of the product e.g. if you fill in canon1 then "canon1 camera" is found, if they only fill in canon then it should not be found.
Now I have been working on this for a while, but I cannot really find how and where this data can be processed / modified
Gr. Jippe
Als het niet kan zoals het moet, moet het maar zoals het kan
If it cannot be done as it should, it should be done as it can
in catalog/model/catalog/product.php FIND: (2 locations)
==============================================
$implode[] = "pd.name LIKE '%" . $this->db->escape($word) . "%'";
==============
REPLACE WITH:
=============
$implode[] = "pd.name LIKE '%" . $this->db->escape($word) . " %'";
What it does is it will match exact words fallowed by space if you see the difference i have added _% (_ means space)
so it will work like this: if you search canon it will return nothing (because it will be looking for "canon " (with a spacee and later all other matching words with space
if you enter canon1 it will find your canon1 camera if you search just camera it will show also canon1 camera as it contains % in the front if you want to search just for first word canon1 and not allow it to be find by camera word remove first% from query:
$implode[] = "pd.name LIKE '" . $this->db->escape($word) . " %'";
Jippe wrote: ↑Fri Apr 12, 2019 4:28 pmGood morning all
I want to adjust the search function in such a way that one has to enter an exact word / code which is processed in a sentence of the product e.g. if you fill in canon1 then "canon1 camera" is found, if they only fill in canon then it should not be found.
Now I have been working on this for a while, but I cannot really find how and where this data can be processed / modified
Gr. Jippe
Opencart Expert | voldemaras@gmail.com
Skype - programanija | Gtalk - voldemaras@gmail.com
Extensions for Opencart @ https://www.opencartextensions.eu / or Opencart Marketplace
Need Custom Module? debug third party module or simply have any question related to Opencart? feel free to contact directly for a live chat session:) - INSTANT LIVE CHAT
$implode[] = "(
pd.name LIKE '" . $this->db->escape($word) . "S%' or
pd.name LIKE '%S" . $this->db->escape($word) . "' or
pd.name LIKE '%S" . $this->db->escape($word) . "S%' or
pd.name LIKE '%S" . $this->db->escape($word) . ",%' or
pd.name LIKE '" . $this->db->escape($word) . ",%' or
pd.name = '" . $this->db->escape($word) . "'
)";
S = space
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
$implode[] = "( pd.name regexp '[[:<:]]" . $this->db->escape($word) . "[[:>:]]')";
with a full text index on pd.name
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
I have now tried some things including $implode[] = "pd.name LIKE '%" . $this->db->escape($word) . "S%'";
It has the result that I am looking for, but 2 things are not working properly.
* space shows all products this may not happen.
* when entering a number such as 1 (product_id) the corresponding product is displayed.
I think I need a letter combination such as "FRL" for the search query but just don't know how
Als het niet kan zoals het moet, moet het maar zoals het kan
If it cannot be done as it should, it should be done as it can
Code: Select all
if (isset($this->request->get['search'])) {
$search = $this->request->get['search'];
} else {
$search = '';
}
to
Code: Select all
$search = '';
if (isset($this->request->get['search'])) {
// replace multiple spaces with one space
$this->request->get['search'] = trim(preg_replace('/\s+/', ' ', $this->request->get['search']));
if ($this->request->get['search'] != ' ') {
$search = $this->request->get['search'];
} else {
// space so no search
unset ($this->request->get['search']);
}
}
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
After some experimenting and combining code provided by letxobnav, I have almost found the solution.
Now I have seen that despite everything the "%" sign in the search engine shows all products.
I used a variant of "= trim(preg_replace('/\s+/', ' ', $this->" to remove the space, can I also supplement it with the "%" sign?
Als het niet kan zoals het moet, moet het maar zoals het kan
If it cannot be done as it should, it should be done as it can
and
that regex I provided replaces multiple spaces with one space, you would not want it to remove all spaces or you have no more word separation.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Please advise on my the following issue for an OC search for a technical shop.
Example: product name contains "Change" other product name contains "Exchange".
The search for "Change" returns first products with the name "Exchange" witch is not good in my case.
Code: Select all
$implode[] = "pd.name LIKE '%" . $this->db->escape($word) . "%'";
Thank You!
Reason: Added code tags.
Looks like this was resolved.. i have one question of my own if someone can help..
how can i make my default search to work in a way that it only search in the title with exact search instead of loose search.
i want the search to only look into titles and exactly what is typed.. for instance if someone searches for 'iphone 12' it should only show iphone 12 and not iphone 12 pro or max.
i hope someone can help me out here.
thanks.
Users browsing this forum: No registered users and 386 guests