From 86dab44c9892caf6274366579b528426d1f9425b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 15 Mar 2013 15:33:49 +0100 Subject: [PATCH] Added natural search to products --- htdocs/product/liste.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/htdocs/product/liste.php b/htdocs/product/liste.php index bef33a022b1c8..9fb9aa8de51a3 100644 --- a/htdocs/product/liste.php +++ b/htdocs/product/liste.php @@ -4,6 +4,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Marcos García * Copyright (C) 2013 Juanjo Menent + * Copyright (C) 2013 Raphaël Doursenaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -133,12 +134,16 @@ $sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')'; if ($sall) { - $sql.= " AND (p.ref LIKE '%".$db->escape($sall)."%' OR p.label LIKE '%".$db->escape($sall)."%' OR p.description LIKE '%".$db->escape($sall)."%' OR p.note LIKE '%".$db->escape($sall)."%'"; - if (! empty($conf->barcode->enabled)) - { - $sql.= " OR p.barcode LIKE '%".$db->escape($sall)."%'"; + // For natural search + $scrit = explode(' ', $sall); + foreach ($scrit as $crit) { + $sql.= " AND (p.ref LIKE '%".$db->escape($crit)."%' OR p.label LIKE '%".$db->escape($crit)."%' OR p.description LIKE '%".$db->escape($crit)."%' OR p.note LIKE '%".$db->escape($crit)."%'"; + if (! empty($conf->barcode->enabled)) + { + $sql.= " OR p.barcode LIKE '%".$db->escape($crit)."%'"; + } + $sql.= ')'; } - $sql.= ')'; } // if the type is not 1, we show all products (type = 0,2,3) if (dol_strlen($type))