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 240:

        $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