You are here:  » Make ean code search better


Make ean code search better

Submitted by IG on Fri, 2019-03-01 11:34 in

Hi David,

Thanks to your help all my products have now a 14-digit ean code, which is great for consistency and for mapping them.

However when I search for an ean code on my site it is not ideal as it only shows the searched product if the ean code is a 100% match.

Let's say a product has the following ean code 123456789123. In my database that will be 00123456789123. If I do a search for 12345678912 or 012345678912, there will be no result. Do you have any good advice how can I overcome this problem?

Kind regards,
IG

Submitted by support on Fri, 2019-03-01 11:57

Hi IG,

What you could do is check for a keyword being a) numeric and b) greater than or equal to 10 characters which is therefore unlikely to be anything other than a unique ID search and apply the same str_pad translation to the keyword.

To try this, edit search.php and look for the following code at line 262:

          $words = explode(" ",$parts[0]);

...and REPLACE with:

          $words = explode(" ",$parts[0]);
          foreach($words as $k => $word)
          {
            if (is_numeric($word) && (strlen($word)>=10))
            {
              $words[$k] = str_pad($word,14,"0",STR_PAD_LEFT);
            }
          }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Fri, 2019-03-01 12:25

Unfortunately, this doesn't work.

If I search for "00190198451330" the corresponding product is shown.

If I search for "0190198451330" or for "190198451330" there's no result.

Submitted by support on Fri, 2019-03-01 12:35

Hello IG,

Can you summarise the changes you have made to search.php to include ean in the search as that isn't the default behaviour, for example have you added a FULLTEXT index on (ean,name) etc?

(alternatively if you would like to email me your modified searcb.php I'll take a look for you...

Thanks,
David.
--
PriceTapestry.com

Submitted by IG on Fri, 2019-03-01 12:42

Hi David,

Yes, I have added a FULLTEXT index (ean,name) and I probably made some other changes that I can't remember. My search.php is on the way...

Kind regards,
IG

Submitted by Marcos on Fri, 2020-06-12 06:54

Hi David, I hope you are doing well.

Did you find the problem/solution? I'm having the same issue (it works if I search the 14 digits but I have 0 results if I remove any zeros on the left).

Thanks,
Marcos

Submitted by support on Fri, 2020-06-12 07:07

Hi Marcos,

Try the modification from this comment above - I just tested on a 12 digit number and the left zeros were added...

Cheers,
David.
--
PriceTapestry.com

Submitted by Marcos on Fri, 2020-06-12 17:55

Hi again,

That's weird, that's the code I'm testing and it doesn't work on my end:
- 14 digit query OK: {link saved}
- 13 or 12 digit query (removing the left 0s) not OK (not results found): {link saved}

I'm using the config_useFullText = TRUE. I tried it in false and in that case it doesn't work neither with nor without the 0s.

Do you have any idea why this should be happening?

Thank you in advance.

Best,
Marcos

Submitted by support on Sat, 2020-06-13 07:59

Hi Marco,

Ah my apologies, the modification was after the wrong instance of the replacement line (the same code occurs at line 262) - corrected above.

(and using $config_useFullText = TRUE)

Cheers,
David.
--
PriceTapestry.com

Submitted by Marcos on Sat, 2020-06-13 18:48

Thanks David, it works now!