Post by Jippe » Fri Apr 12, 2019 4:28 pm

Good 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

;D Als het niet kan zoals het moet, moet het maar zoals het kan ;D
:P If it cannot be done as it should, it should be done as it can :P


User avatar
Newbie

Posts

Joined
Fri Apr 12, 2019 3:32 pm

Post by D3MO » Fri Apr 12, 2019 8:01 pm

==============================================
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 pm
Good 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


User avatar
Active Member

Posts

Joined
Mon Apr 04, 2011 6:57 am

Post by letxobnav » Fri Apr 12, 2019 8:32 pm

you are forgetting some possibilities for exact word match:

$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.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by Jippe » Sun Apr 14, 2019 5:07 am

thanks for your reply.
I'm going to try this on Monday and let you know how it goes

;D Als het niet kan zoals het moet, moet het maar zoals het kan ;D
:P If it cannot be done as it should, it should be done as it can :P


User avatar
Newbie

Posts

Joined
Fri Apr 12, 2019 3:32 pm

Post by letxobnav » Sun Apr 14, 2019 8:33 am

you could also use:

$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.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by Jippe » Wed Apr 17, 2019 10:47 pm

good afternoon
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

;D Als het niet kan zoals het moet, moet het maar zoals het kan ;D
:P If it cannot be done as it should, it should be done as it can :P


User avatar
Newbie

Posts

Joined
Fri Apr 12, 2019 3:32 pm

Post by letxobnav » Wed Apr 17, 2019 11:53 pm

in catalog/controller/product/search.php you could change:

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']);
			}
		}
search does not look in product id's, it will only find 1 of you have that in your product 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.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by Jippe » Sat Apr 20, 2019 3:31 am

Good evening all
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?

;D Als het niet kan zoals het moet, moet het maar zoals het kan ;D
:P If it cannot be done as it should, it should be done as it can :P


User avatar
Newbie

Posts

Joined
Fri Apr 12, 2019 3:32 pm

Post by letxobnav » Sat Apr 20, 2019 10:33 am

the % sign is part of the constructed mysql "LIKE" query statement, not of your search term.

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.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by oliversuc » Thu Apr 30, 2020 6:51 pm

Hi all,

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) . "%'";
Is there a way to match this, while not limit all to the exact word?

Thank You!
Last edited by straightlight on Thu Apr 30, 2020 8:16 pm, edited 1 time in total.
Reason: Added code tags.

Newbie

Posts

Joined
Mon Nov 12, 2012 9:17 pm

Post by awaix » Thu Dec 03, 2020 9:35 pm

Hi,
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.

New member

Posts

Joined
Sat Apr 13, 2013 8:22 pm
Who is online

Users browsing this forum: No registered users and 386 guests