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 1/6] 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 bef33a022b1..9fb9aa8de51 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 @@ else $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)) From ea442d93519e09b43c9498c1defc38f4db7ad14b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 15 Mar 2013 15:37:11 +0100 Subject: [PATCH 2/6] Fixed use of deprecated data field --- htdocs/societe/societe.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/societe.php b/htdocs/societe/societe.php index 5792661dd5e..763274d2a79 100644 --- a/htdocs/societe/societe.php +++ b/htdocs/societe/societe.php @@ -99,7 +99,7 @@ if ($mode == 'search') if ($search_categ) $sql.= " AND s.rowid = cs.fk_societe"; // Join for the needed table to filter by categ if (! $user->rights->societe->lire || ! $user->rights->fournisseur->lire) { - if (! $user->rights->fournisseur->lire) $sql.=" AND s.fourn != 1"; + if (! $user->rights->fournisseur->lire) $sql.=" AND s.fournisseur != 1"; } // Insert sale filter if ($search_sale) From 639c033afbcb2765653a760ec076e40573438850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 15 Mar 2013 15:37:59 +0100 Subject: [PATCH 3/6] Added natural search to third parties --- htdocs/societe/societe.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/htdocs/societe/societe.php b/htdocs/societe/societe.php index 763274d2a79..26583442b2c 100644 --- a/htdocs/societe/societe.php +++ b/htdocs/societe/societe.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Marcos García + * 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 @@ -80,19 +81,25 @@ if ($mode == 'search') // We'll need this table joined to the select in order to filter by categ if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs"; $sql.= " WHERE s.entity IN (".getEntity('societe', 1).")"; - $sql.= " AND ("; - $sql.= " s.nom LIKE '%".$db->escape($socname)."%'"; - $sql.= " OR s.code_client LIKE '%".$db->escape($socname)."%'"; - $sql.= " OR s.email LIKE '%".$db->escape($socname)."%'"; - $sql.= " OR s.url LIKE '%".$db->escape($socname)."%'"; - $sql.= " OR s.siren LIKE '%".$db->escape($socname)."%'"; - if (!empty($conf->barcode->enabled)) - { - $sql.= "OR s.barcode LIKE '".$db->escape($socname)."'"; - } + // For natural search + $scrit = explode(' ', $socname); + foreach ($scrit as $crit) { + $sql.= " AND ("; + $sql.= " s.nom LIKE '%".$db->escape($crit)."%'"; + $sql.= " OR s.code_client LIKE '%".$db->escape($crit)."%'"; + $sql.= " OR s.email LIKE '%".$db->escape($crit)."%'"; + $sql.= " OR s.url LIKE '%".$db->escape($crit)."%'"; + $sql.= " OR s.siren LIKE '%".$db->escape($crit)."%'"; + + if (!empty($conf->barcode->enabled)) + { + $sql.= "OR s.barcode LIKE '".$db->escape($crit)."'"; + } + + $sql.= ")"; + } - $sql.= ")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale From 4bcf3b3c32c710bac48bf35b16e65b5180219f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 15 Mar 2013 15:44:23 +0100 Subject: [PATCH 4/6] Added natural search to contacts --- htdocs/contact/list.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 6d782c892d9..a6108ab9e8e 100755 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -3,6 +3,7 @@ * Copyright (C) 2003 Eric Seigne * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin + * 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 @@ -196,7 +197,11 @@ else if ($type == "p") // filtre sur type } if ($sall) { - $sql .= " AND (p.lastname LIKE '%".$db->escape($sall)."%' OR p.firstname LIKE '%".$db->escape($sall)."%' OR p.email LIKE '%".$db->escape($sall)."%')"; + // For natural search + $scrit = explode(' ', $sall); + foreach ($scrit as $crit) { + $sql .= " AND (p.lastname LIKE '%".$db->escape($crit)."%' OR p.firstname LIKE '%".$db->escape($crit)."%' OR p.email LIKE '%".$db->escape($crit)."%')"; + } } if (! empty($socid)) { From 656915b8a894f39a2ab853b9375ed0d2cbd57f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 15 Mar 2013 15:48:03 +0100 Subject: [PATCH 5/6] Added natural search to members --- htdocs/adherents/liste.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/htdocs/adherents/liste.php b/htdocs/adherents/liste.php index 8bab0cab35b..27ddd052225 100644 --- a/htdocs/adherents/liste.php +++ b/htdocs/adherents/liste.php @@ -2,6 +2,7 @@ /* Copyright (C) 2001-2003 Rodolphe Quiedeville * Copyright (C) 2002-2003 Jean-Louis Bergamo * Copyright (C) 2004-2012 Laurent Destailleur + * 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 @@ -101,11 +102,15 @@ if ($search_categ == -2) $sql.= " AND cm.fk_categorie IS NULL"; $sql.= " AND d.entity = ".$conf->entity; if ($sall) { - $sql.=" AND ("; - if (is_numeric($sall)) $sql.= "d.rowid = ".$sall." OR "; - $sql.=" d.firstname LIKE '%".$sall."%' OR d.lastname LIKE '%".$sall."%' OR d.societe LIKE '%".$sall."%'"; - $sql.=" OR d.email LIKE '%".$sall."%' OR d.login LIKE '%".$sall."%' OR d.address LIKE '%".$sall."%'"; - $sql.=" OR d.town LIKE '%".$sall."%' OR d.note LIKE '%".$sall."%')"; + // For natural search + $scrit = explode(' ', $sall); + foreach ($scrit as $crit) { + $sql.=" AND ("; + if (is_numeric($sall)) $sql.= "d.rowid = ".$sall." OR "; + $sql.=" d.firstname LIKE '%".$sall."%' OR d.lastname LIKE '%".$sall."%' OR d.societe LIKE '%".$sall."%'"; + $sql.=" OR d.email LIKE '%".$sall."%' OR d.login LIKE '%".$sall."%' OR d.address LIKE '%".$sall."%'"; + $sql.=" OR d.town LIKE '%".$sall."%' OR d.note LIKE '%".$sall."%')"; + } } if ($type > 0) { From 16efed11ca63a3605939ddd3e65d1c27ec557d32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Fri, 15 Mar 2013 16:05:49 +0100 Subject: [PATCH 6/6] Added natural search to product line search --- htdocs/core/class/html.form.class.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 784c8bc926f..941865da45a 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -13,6 +13,7 @@ * Copyright (C) 2010 Philippe Grand * Copyright (C) 2011 Herve Prot * Copyright (C) 2012 Marcos García + * 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 @@ -1223,9 +1224,13 @@ class Form } else { - $sql.=" AND (p.ref LIKE '%".$filterkey."%' OR p.label LIKE '%".$filterkey."%'"; - if (! empty($conf->global->MAIN_MULTILANGS)) $sql.=" OR pl.label LIKE '%".$filterkey."%'"; - $sql.=")"; + // For natural search + $scrit = explode(' ', $filterkey); + foreach ($scrit as $crit) { + $sql.=" AND (p.ref LIKE '%".$crit."%' OR p.label LIKE '%".$crit."%'"; + if (! empty($conf->global->MAIN_MULTILANGS)) $sql.=" OR pl.label LIKE '%".$crit."%'"; + $sql.=")"; + } } if (! empty($conf->barcode->enabled))