1

I've a large table of products, and want to get related products based on a similarity of some kind - whether it is product code or title yet I am yet to decide.

What I want effectively is an output of the 4 most likely matches for a product based on title or code.

Example:

 Product Code   Related Products
 JC83022        JC83021, JC83020, JC83029, JC8300

So I would ideally like a field appended to the product table which does some kind of string matching and returns the codes for the 4 most likely matches.

My idea is that I can use a MySQL query to perform this, but looking around PHP may have some better functions - maybe I could have a function on the product page that returns the products with the nearer levenshein distance - it's just how to query that against a table of over 30,000 products.

Cheers in advance.

Daffy
  • 89
  • 1
  • 7
  • If you're doing string comparison, the [Lenvenshtein distance](http://stackoverflow.com/questions/634995/implementation-of-levenshtein-distance-for-mysql-fuzzy-search) algorithm might help. As it stands, however, your question is overly broad - narrow down the match criteria and list them in your question – Bojangles Jul 17 '13 at 09:22
  • Thanks for your comments I was worried it was overly broad - however having looked at the Levenshtein I'm not sure it will be able to help as I won't be passing a second string per se - I want it to search through the whole table (which I could technically pass as an array and probably break everything!). – Daffy Jul 17 '13 at 09:36
  • 1
    The most accurate way of finding 4 related product codes is to do it manually with another table. If you can match on something less ambiguous than a code (product title, description, properties, etc) then life becomes a lot easier. You can always cache the matches in a lookup table if performance is an issue – Bojangles Jul 17 '13 at 09:38

0 Answers0