Merge pull request #748 from GPCsolutions/naturalsearch

Natural search
This commit is contained in:
Laurent Destailleur 2013-03-16 07:38:55 -07:00
commit fcef334122
5 changed files with 53 additions and 26 deletions

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org> * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2013 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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; $sql.= " AND d.entity = ".$conf->entity;
if ($sall) if ($sall)
{ {
$sql.=" AND ("; // For natural search
if (is_numeric($sall)) $sql.= "d.rowid = ".$sall." OR "; $scrit = explode(' ', $sall);
$sql.=" d.firstname LIKE '%".$sall."%' OR d.lastname LIKE '%".$sall."%' OR d.societe LIKE '%".$sall."%'"; foreach ($scrit as $crit) {
$sql.=" OR d.email LIKE '%".$sall."%' OR d.login LIKE '%".$sall."%' OR d.address LIKE '%".$sall."%'"; $sql.=" AND (";
$sql.=" OR d.town LIKE '%".$sall."%' OR d.note LIKE '%".$sall."%')"; 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) if ($type > 0)
{ {

View File

@ -3,6 +3,7 @@
* Copyright (C) 2003 Eric Seigne <erics@rycks.com> * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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) 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)) if (! empty($socid))
{ {

View File

@ -13,6 +13,7 @@
* Copyright (C) 2010 Philippe Grand <philippe.grand@atoo-net.com> * Copyright (C) 2010 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2011 Herve Prot <herve.prot@symeos.com> * Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2013 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -1223,9 +1224,13 @@ class Form
} }
else else
{ {
$sql.=" AND (p.ref LIKE '%".$filterkey."%' OR p.label LIKE '%".$filterkey."%'"; // For natural search
if (! empty($conf->global->MAIN_MULTILANGS)) $sql.=" OR pl.label LIKE '%".$filterkey."%'"; $scrit = explode(' ', $filterkey);
$sql.=")"; 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)) if (! empty($conf->barcode->enabled))

View File

@ -4,6 +4,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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).')'; $sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')';
if ($sall) 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)."%'"; // For natural search
if (! empty($conf->barcode->enabled)) $scrit = explode(' ', $sall);
{ foreach ($scrit as $crit) {
$sql.= " OR p.barcode LIKE '%".$db->escape($sall)."%'"; $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 the type is not 1, we show all products (type = 0,2,3)
if (dol_strlen($type)) if (dol_strlen($type))

View File

@ -3,6 +3,7 @@
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2012 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2013 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -80,26 +81,32 @@ if ($mode == 'search')
// We'll need this table joined to the select in order to filter by categ // 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"; if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs";
$sql.= " WHERE s.entity IN (".getEntity('societe', 1).")"; $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)) // For natural search
{ $scrit = explode(' ', $socname);
$sql.= "OR s.barcode LIKE '".$db->escape($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 (!$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 ($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 if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
if ($search_categ) $sql.= " AND s.rowid = cs.fk_societe"; // Join for the needed table to filter by categ 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->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 // Insert sale filter
if ($search_sale) if ($search_sale)