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


Active Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm

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


Active Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm

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


Active Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Who is online

Users browsing this forum: No registered users and 4 guests