Jump to content
mantobani

Frontpage search with "-" minus in.

Recommended Posts

Hi friends,

First thanks to all fot the help you gave me.

 

Im not a programmer, only kind of advanced user.

 

I have a shop who some of the products have references like "s-01" or "T-01" this is with a "minus" character in the middle. This searches works well on back office, but in fron office it appears the code erases the minus and the first character "s" or "t", giving the search of the numbers only.

I tried to manage the search options, keywords weight, word lenght, re-build index. (no result)

I tried to edit classes/search.php to change some code that i think can delete the miinus character, but no results.

Tried to edit aliases, and rebuid (nothing happens)

 

I think is possible to add the backoffice search to the front. (I find an older threat with something from presta 1.4 but the code is significally different) 

 

In the code, the prestashop team let a note who says /* Copied from Drupal search module, except for \x{0}-\x{2f} that has been replaced by \x{0}-\x{2c}\x{2e}-\x{2f} in order to keep the char '-' */ 

 

I've searched in drupal and prestashop forums, i tried to put some unicode chars in the exceptions list. (no result)

 

Can someone add some light to this?

 

Sorry for my bad english. ;)

 

----

Config:

Linux #1 SMP Wed Feb 12 16:04:42 MSK 2014 x86_64
Apache
PHP: 5.3.3
512M
MySQL: 5.1.67 InnoDB
PrestaShop: 1.5.6.2

 

Share this post


Link to post
Share on other sites

Hi,

 

did you found solution for your problem? 

 

I have samoe problem, I need to to search with minus sign, for me in Prestashop 1.5.3.1 it i same result for example: "fx-10" and "fx 10", or "fx-------10", like there is no minus in search word.

 

Please if you have solution, or somebody, help!

 

Best regards, Igor

Share this post


Link to post
Share on other sites

Hi, I'm no expert on preg_replace, but I think this does it. (Not fully sure if I 'allow' too much now, though. See below)

 

In file: Classes/Search.php (make backup, and best to make an override class and override sanitize function (see dev guide on how to)

	public static function sanitize($string, $id_lang, $indexation = false, $iso_code = false)
	{
		$string = trim($string);
		if (empty($string))
			return '';

		$string = Tools::strtolower(strip_tags($string));
		$string = html_entity_decode($string, ENT_NOQUOTES, 'utf-8');

		$string = preg_replace('/(['.PREG_CLASS_NUMBERS.']+)['.PREG_CLASS_PUNCTUATION.']+(?=['.PREG_CLASS_NUMBERS.'])/u', '\1', $string);
		$string = preg_replace('/['.PREG_CLASS_SEARCH_EXCLUDE.']+/u', ' ', $string);

		if ($indexation)
//			$string = preg_replace('/[._-]+/', ' ', $string);
			$string = preg_replace('/[._]+/', ' ', $string);
		else
		{
			$string = preg_replace('/[._]+/', '', $string);
//			$string = ltrim(preg_replace('/([^ ])-/', '$1 ', ' '.$string));
			$string = preg_replace('/[._]+/', '', $string);
//			$string = preg_replace('/[^\s]-+/', '', $string);
		}

		$blacklist = Tools::strtolower(Configuration::get('PS_SEARCH_BLACKLIST', $id_lang));

As you can see, I commented-out three lines (with //  ), (and I added one line, see below)

 

The first commented-out line:

//            $string = preg_replace('/[._-]+/', ' ', $string);

 
I replaced (one line below it) with:
            $string = preg_replace('/[._]+/', ' ', $string);
 
As you can see, I only took out the minus sign here (red indicated in original line).

 

This makes that the minus sign will not be replaced with a space (so not creating two separate sub words), during reindexation.

 

The other commented-out lines are used when searching, not indexing.

These two lines, as far as I can see, searches for some (sub)string with a - (minus sign), and replaced with the (sub) string only. So I just took out these replacements to keep the minus signs intact.

(N.B. Not 100% sure I 'allow' too much because of this. Any preg_replace expert any comment??)

 

See sample here:

 

In a demo shop, I added a string to the short description of the "iPod nano" product: (go to product detail for full short description text):

 

    oopad-nonno 

 

http://ps1562.buymethai.com/en/   (N.B. link to temp testshop, may not work in future)

 

N.B. The general restriction in search isn't changed: you can only find words that START with the given string (like 'touc' (for touch) is found, but 'ouch' not, as the search string must start with the begin letter (t) to be found)

 

That said,

 

Try to play with it here in the sample shop. It seems that searching for:

oop

oopa

oopad

oopad-

oopad-n

oopad-no

oopad-non

oopad-nonn

oopad-nonno

and

oopad iPod      (two words, "start with", both exist in same product)

 

all works

 

not works:

oopadn              (no - sign, so not found)

oopadnonno      (no - sign, so not found)

nonno                (nonno isn't added separately, as the only word added to the index is oopad-nonno)

-nonno               (the word starts with oopad, -nonno isn't indexed separately)

 

etc. as the - sign is really part of the word, (and the word starts with oopad). (In database, there's only one index word "oopad-nonno", no variations, partial strings)

 

Hope this does the trick,

pascal.

  • Like 4

Share this post


Link to post
Share on other sites

PascalVG, you are the man, thank you very much!!!!

 

I was cheching about that field, but every tima I have problem in

"$string = ltrim(preg_replace('/([^ ])-/', '$1 ', ' '.$string));"

"$string = ltrim(preg_replace('/([^ ])/', '$1 ', ' '.$string));" - I just delete "-"

"$string = preg_replace('/[._]+/', '', $string);" - need to be like this

 

Thank you again, my problem is SOLVED!

Share this post


Link to post
Share on other sites

Thanks for the feedback.

Glad it worked for you :-)

 

I'll mark the topic as solved.

 

Happy selling,

Pascal

Share this post


Link to post
Share on other sites

PascalVG, you are the man, thank you very much!!!!

 

I was cheching about that field, but every tima I have problem in

"$string = ltrim(preg_replace('/([^ ])-/', '$1 ', ' '.$string));"

"$string = ltrim(preg_replace('/([^ ])/', '$1 ', ' '.$string));" - I just delete "-"

"$string = preg_replace('/[._]+/', '', $string);" - need to be like this

 

Thank you again, my problem is SOLVED!

Just what to know if rebuild index is required after making the change ?!

 

Thanks

Share this post


Link to post
Share on other sites

PascalVG, you are the man, thank you very much!!!!

 

I was cheching about that field, but every tima I have problem in

"$string = ltrim(preg_replace('/([^ ])-/', '$1 ', ' '.$string));"

"$string = ltrim(preg_replace('/([^ ])/', '$1 ', ' '.$string));" - I just delete "-"

"$string = preg_replace('/[._]+/', '', $string);" - need to be like this

 

Thank you again, my problem is SOLVED!

 

 

Hello, when i do this,  (PrestaShop™ 1.5.6.0)

my search doesn't work at all.

When i do any changes in search.php my seach doesn't work at all. 

What i should do ? 

maybe "Re-build the entire index"?

Pls help

Edited by ArturV (see edit history)

Share this post


Link to post
Share on other sites

Hello !

 

Thank you for the answer. I posted on a similar problem because I didn't find this thread before today https://www.prestashop.com/forums/topic/615102-searching-and-indexing-dashed-and-dotted-references/  and I kind of found the same solution but I need advice and a little bit more solution :

I have the same problem for the reference search but it includes dashes, dots and slashes so I changed a few things and I also thought of commenting as you did but if someone has the regex that does not exclude those signs...

Also, Prestashop won't index the references with only numbers and - / or . in between. It works when they are containing letters. Hence, I can't search for the numerical references. I can search for them and find the good results when when I'm putting them by hand on the sql tables search_index and search_word so I need a solution for Prestashop to index them with the other words.

Help please.

Edited by pranab13 (see edit history)

Share this post


Link to post
Share on other sites

Hello!,
I need help with search engine in Presta 1.7, I hope I will find a good soul to help me out.
When I want to search for example: VR-50HD, EVOLVE 50 and I type the exact same thing in the search engine, it is all perfect, same situation when I use space instead of dash (VR 50HD).
The problem occurs when phrases are without any punctuation marks like VR50HD, EVOLVE50. It's like product does not exist.


The use of the above modification does not repair.


Another problem I got is with the results of the search engine. When searching VR-50HD, engine will add a lot of products where "50" appears in the product or even the category.

Regards

Share this post


Link to post
Share on other sites
2 minutes ago, lukaszwojcik said:

Hello!,
I need help with search engine in Presta 1.7, I hope I will find a good soul to help me out.
When I want to search for example: VR-50HD, EVOLVE 50 and I type the exact same thing in the search engine, it is all perfect, same situation when I use space instead of dash (VR 50HD).
The problem occurs when phrases are without any punctuation marks like VR50HD, EVOLVE50. It's like product does not exist.


The use of the above modification does not repair.


Another problem I got is with the results of the search engine. When searching VR-50HD, engine will add a lot of products where "50" appears in the product or even the category.

Regards

 

Maybe you can solve it by adding the references without the dashes as product tags "VR50HD". I did that on the 1.6 so you can try on the 1.7. Then you put a high weight of search to the tags (if this still exists on the 1.7) on the search configuration admin page. 

Share this post


Link to post
Share on other sites
Adding tags for all combinations will be rather difficult, as there are already almost 350 products and ultimately there will be several thousand.

Share this post


Link to post
Share on other sites
2 hours ago, lukaszwojcik said:
Adding tags for all combinations will be rather difficult, as there are already almost 350 products and ultimately there will be several thousand.

Prestashop Search sucks, so if you are not attached to it I prefer searching for other solution. Payed or not. 

From free ones http://bradsearch.io is quite good, tested on Prestashop 1.6 maby works on 1.7 and for payed ones search on addons.

Share this post


Link to post
Share on other sites
On 09/05/2018 at 8:18 PM, lukaszwojcik said:
Adding tags for all combinations will be rather difficult, as there are already almost 350 products and ultimately there will be several thousand.

Yes I know that's no the best, this is at least a temporary thing. I have 8000 products but what I did is just a big excel file with a column for the references, and a column concatenated for the tags that contains the references with the dots or dashes and without (you do a big search and replace for the dashes and dots). Then I imported it.

Share this post


Link to post
Share on other sites

Hello, does anyone know how to apply this fix to Prestashop 1.7.4?

I'm having the same problem with - char, and I'm unable to fix it following PascalVG tip.

Share this post


Link to post
Share on other sites
10 hours ago, DARKF3D3 said:

Hello, does anyone know how to apply this fix to Prestashop 1.7.4?

I'm having the same problem with - char, and I'm unable to fix it following PascalVG tip.

See if my post can help you : https://www.prestashop.com/forums/topic/615102-searching-and-indexing-dashed-and-dotted-references/

It's for Prestashop 1.6.1.10 and I don't know if the class search.php is the same for the 1.7.4 but you can check.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More