Jump to content

Problème de recherche de produit


Recommended Posts

Bonsoir à tous,

 

Je rencontre un problème relativement pénible dans la fonction recherche rapide de mon site de vente de maquettes. Pour une raison que j'ignore, le résultat de recherche n'est pas constant. Je m'explique.

 

Si je recherche un nom d'avion, exemple P-38, aucun résultat n'est listé. Or, j'ai bien des produits de ce type. Si je recherche Kitty Hawk, qui est une partie d'un nom d'avion, j'ai une liste d'avion du fabriquant Kitty Hawk, mais aucun des avions de ce noms. Enfin, troisième cas: si je cherche "Corsair", seul un article est listé, or je devrais avoir un retour de 37 produits!

 

J'ai fouillé dans les classes Product.php et Search.php. Ainsi, dans la fonction searchByName de Product.php, les % (wildcards) sont bien placés pour effectuer une recherche de type LIKE:

 

 
$sql = new DbQuery();
$sql->select('p.`id_product`, pl.`name`, p.`ean13`, p.`upc`, p.`active`, p.`reference`, m.`name` AS manufacturer_name, stock.`quantity`, product_shop.advanced_stock_management, p.`customizable`');
$sql->from('category_product', 'cp');
$sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
$sql->join(Shop::addSqlAssociation('product', 'p'));
$sql->leftJoin('product_lang', 'pl', '
p.`id_product` = pl.`id_product`
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl')
);
$sql->leftJoin('manufacturer', 'm', 'm.`id_manufacturer` = p.`id_manufacturer`');
 
$where = 'pl.`name` LIKE \'%'.pSQL($query).'%\'
OR p.`ean13` LIKE \'%'.pSQL($query).'%\'
OR p.`upc` LIKE \'%'.pSQL($query).'%\'
OR p.`reference` LIKE \'%'.pSQL($query).'%\'
OR p.`supplier_reference` LIKE \'%'.pSQL($query).'%\'
OR  p.`id_product` IN (SELECT id_product FROM '._DB_PREFIX_.'product_supplier sp WHERE `product_supplier_reference` LIKE \'%'.pSQL($query).'%\')';
$sql->groupBy('`id_product`');
$sql->orderBy('pl.`name` ASC');
 
Dans la fonction find de Search.php, pareil (mais je ne pense pas que c'est cette fonction qui est appelée):
 
if (!empty($word) && strlen($word) >= (int)Configuration::get('PS_SEARCH_MINWORDLEN'))
{
$word = str_replace('%', '\\%', $word);
$word = str_replace('_', '\\_', $word);
$intersect_array[] = 'SELECT si.id_product
FROM '._DB_PREFIX_.'search_word sw
LEFT JOIN '._DB_PREFIX_.'search_index si ON sw.id_word = si.id_word
WHERE sw.id_lang = '.(int)$id_lang.'
AND sw.id_shop = '.$context->shop->id.'
AND sw.word LIKE
'.($word[0] == '-'
? ' \'%'.pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)).'%\''
: '\'%'.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\''
);
 
if ($word[0] != '-')
$score_array[] = 'sw.word LIKE \'%'.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\'';
}
 
 
Bref, je ne bloque. Est-ce que quelqu'un a rencontré ce type de problème? Tous mes produits sont bien indexés via un cron quotidien et je tourne en version 1.6.0.8
 
Merci pour votre aide!
 
Ludo

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...