lebarront Posted February 9, 2012 Share Posted February 9, 2012 bonjours, dans prestashop, quand ont a plusieurs référence, plus de 300 000. Je vous donne un exemple si vous avez une série de réf :00023 puis 000231 puis 000234 etc... est que vous recherchez 0002 la recherche vous remonte tous ce qui commence par 0002 je cherche donc a modifier le code dans le fichier classes/search.php pour qu'il nous remonte uniquement le code entier "0002" j’espère que c'est assez claire,et désoler pour les fauts d’orthographe Link to comment Share on other sites More sharing options...
Johann Posted February 9, 2012 Share Posted February 9, 2012 Si tu utilises une version PS >= 1.4, tu peux utiliser l'overriding, c'est à dire créer une classe Search.php dans /overrides/classes qui va ressembler à ça, en ne contenant que la méthode modifiée pour avoir le comportement désiré : class Search extends SearchCore { public static function find($id_lang, $expr, $pageNumber = 1, $pageSize = 1, $orderBy = 'position', $orderWay = 'desc', $ajax = false, $useCookie = true) { global $cookie; $db = Db::getInstance(_PS_USE_SQL_SLAVE_); .......... (on recopie la totalite du code de la methode d'origine, en virant les '%' aux endroits qui vont bien : $intersectArray[] = 'SELECT 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.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] != '-') $scoreArray[] = 'sw.word LIKE \''.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\''; ..... } à la fin des 3 lignes concernées, on remplace le '%\'' par '\'' ça devrait marcher comme ça Link to comment Share on other sites More sharing options...
lebarront Posted February 9, 2012 Author Share Posted February 9, 2012 Merci pour votre reponse rapide j'ai un search.php dans override/classes voici son code <?php Class Search extends SearchCore { public static function find($id_lang, $expr, $pageNumber = 1, $pageSize = 1, $orderBy = 'position', $orderWay = 'desc', $ajax = false) { global $cookie; $db = Db::getInstance(); // TODO : smart page management if ($pageNumber < 1) $pageNumber = 1; if ($pageSize < 1) $pageSize = 1; if (!Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay)) die(Tools::displayError()); $whereArray = array(); $inArray = array(); $scoreArray = array(); $words = explode(' ', Search::sanitize($expr, $id_lang)); foreach ($words as $key => $word) if (!empty($word) AND strlen($word) != 1) { $word = str_replace('%', '\\%', $word); $word = str_replace('_', '\\_', $word); $inListResult = $db->ExecuteS(' SELECT DISTINCT `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` = '.intval($id_lang).' 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)).'%\'')); $inList=array(); foreach($inListResult as $result) { $inList[]=$result['id_product']; } if(count($inList)) $whereArray[] = ' p.id_product '.($word[0] == '-' ? 'NOT' : '').' IN ('.implode(',', $inList).')'; if ($word[0] != '-') $scoreArray[] = 'sw.word LIKE \'%'.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\''; } else unset($words[$key]); if (!sizeof($words)) return ($ajax ? array() : array('total' => 0, 'result' => array())); $score = ''; if (sizeof($scoreArray)) $score = ',( SELECT SUM(weight) FROM `'._DB_PREFIX_.'search_word` sw LEFT JOIN `'._DB_PREFIX_.'search_index` si ON sw.`id_word` = si.`id_word` WHERE sw.`id_lang` = '.intval($id_lang).' AND si.`id_product` = p.`id_product` AND ('.implode(' OR ', $scoreArray).') ) as position'; $eligibleProducts = $db->ExecuteS(' SELECT DISTINCT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg INNER JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_category` = cg.`id_category` INNER JOIN `'._DB_PREFIX_.'category` c ON cp.`id_category` = c.`id_category` INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product` WHERE c.`active` = 1 AND p.`active` = 1 AND cg.`id_group` '.(!$cookie->id_customer ? '= 1' : 'IN ( SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).' )').(count($whereArray)>0?' AND '.implode(' AND ', $whereArray):' AND p.id_product=0')); $productPool = ''; foreach ($eligibleProducts as $product) if (!empty($product['id_product'])) $productPool .= $product['id_product'].','; if (empty($productPool)) return ($ajax ? array() : array('total' => 0, 'result' => array())); $productPool = ((strpos($productPool, ',') === false) ? (' = '.(int)$productPool.' ') : (' IN ('.rtrim($productPool, ',').') ')); if ($ajax) { if (!$result = $db->ExecuteS(' SELECT DISTINCT p.`id_product`, pl.`name` as pname, cl.`name` AS cname, cl.`link_rewrite` as crewrite, pl.`link_rewrite` as prewrite '.$score.' FROM `'._DB_PREFIX_.'product` p INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).') INNER JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.intval($id_lang).') WHERE p.`id_product` '.$productPool.' ORDER BY position DESC LIMIT 10 ')) return false; foreach ($result AS &$row) $row['cname'] = Category::hideCategoryPosition($row['cname']); return $result; } $queryResults = ' SELECT SQL_CALC_FOUND_ROWS p.*, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`, pa.`id_product_attribute`, tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name '.$score.', DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 new FROM '._DB_PREFIX_.'product p INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)Country::getDefaultCountryId().' AND tr.`id_state` = 0) LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') WHERE p.`id_product` '.$productPool.' '.($orderBy ? 'ORDER BY '.$orderBy : '').($orderWay ? ' '.$orderWay : '').' LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize; $result = $db->ExecuteS($queryResults); $total = $db->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'product p INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)Country::getDefaultCountryId().' AND tr.`id_state` = 0) LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') WHERE p.`id_product` '.$productPool); return array('total' => $total,'result' => Product::getProductsProperties($id_lang, $result)); } } ?> Link to comment Share on other sites More sharing options...
lebarront Posted February 9, 2012 Author Share Posted February 9, 2012 que doit je changer dans ce code pour avoir la recherche d'un mot exacte merci pour tous Link to comment Share on other sites More sharing options...
lebarront Posted February 9, 2012 Author Share Posted February 9, 2012 je revient car j'ai reussit grace a votre metode johann par contre si la fin du code est 0002 il va me remonter aussi 2150002 voici mon code <?php Class Search extends SearchCore { public static function find($id_lang, $expr, $pageNumber = 1, $pageSize = 1, $orderBy = 'position', $orderWay = 'desc', $ajax = false) { global $cookie; $db = Db::getInstance(); // TODO : smart page management if ($pageNumber < 1) $pageNumber = 1; if ($pageSize < 1) $pageSize = 1; if (!Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay)) die(Tools::displayError()); $whereArray = array(); $inArray = array(); $scoreArray = array(); $words = explode(' ', Search::sanitize($expr, $id_lang)); foreach ($words as $key => $word) if (!empty($word) AND strlen($word) != 1) { $word = str_replace('%', '\\%', $word); $word = str_replace('_', '\\_', $word); $inListResult = $db->ExecuteS(' SELECT DISTINCT `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` = '.intval($id_lang).' 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)).'\'')); $inList=array(); foreach($inListResult as $result) { $inList[]=$result['id_product']; } if(count($inList)) $whereArray[] = ' p.id_product '.($word[0] == '-' ? 'NOT' : '').' IN ('.implode(',', $inList).')'; if ($word[0] != '-') $scoreArray[] = 'sw.word LIKE \'%'.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'\''; } else unset($words[$key]); if (!sizeof($words)) return ($ajax ? array() : array('total' => 0, 'result' => array())); $score = ''; if (sizeof($scoreArray)) $score = ',( SELECT SUM(weight) FROM `'._DB_PREFIX_.'search_word` sw LEFT JOIN `'._DB_PREFIX_.'search_index` si ON sw.`id_word` = si.`id_word` WHERE sw.`id_lang` = '.intval($id_lang).' AND si.`id_product` = p.`id_product` AND ('.implode(' OR ', $scoreArray).') ) as position'; $eligibleProducts = $db->ExecuteS(' SELECT DISTINCT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg INNER JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_category` = cg.`id_category` INNER JOIN `'._DB_PREFIX_.'category` c ON cp.`id_category` = c.`id_category` INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product` WHERE c.`active` = 1 AND p.`active` = 1 AND cg.`id_group` '.(!$cookie->id_customer ? '= 1' : 'IN ( SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).' )').(count($whereArray)>0?' AND '.implode(' AND ', $whereArray):' AND p.id_product=0')); $productPool = ''; foreach ($eligibleProducts as $product) if (!empty($product['id_product'])) $productPool .= $product['id_product'].','; if (empty($productPool)) return ($ajax ? array() : array('total' => 0, 'result' => array())); $productPool = ((strpos($productPool, ',') === false) ? (' = '.(int)$productPool.' ') : (' IN ('.rtrim($productPool, ',').') ')); if ($ajax) { if (!$result = $db->ExecuteS(' SELECT DISTINCT p.`id_product`, pl.`name` as pname, cl.`name` AS cname, cl.`link_rewrite` as crewrite, pl.`link_rewrite` as prewrite '.$score.' FROM `'._DB_PREFIX_.'product` p INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).') INNER JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.intval($id_lang).') WHERE p.`id_product` '.$productPool.' ORDER BY position DESC LIMIT 10 ')) return false; foreach ($result AS &$row) $row['cname'] = Category::hideCategoryPosition($row['cname']); return $result; } $queryResults = ' SELECT SQL_CALC_FOUND_ROWS p.*, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`, pa.`id_product_attribute`, tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name '.$score.', DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 new FROM '._DB_PREFIX_.'product p INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)Country::getDefaultCountryId().' AND tr.`id_state` = 0) LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') WHERE p.`id_product` '.$productPool.' '.($orderBy ? 'ORDER BY '.$orderBy : '').($orderWay ? ' '.$orderWay : '').' LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize; $result = $db->ExecuteS($queryResults); $total = $db->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'product p INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)Country::getDefaultCountryId().' AND tr.`id_state` = 0) LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') WHERE p.`id_product` '.$productPool); return array('total' => $total,'result' => Product::getProductsProperties($id_lang, $result)); } } ?> Link to comment Share on other sites More sharing options...
lebarront Posted February 9, 2012 Author Share Posted February 9, 2012 je récapitule avant de poster sur ce forum est avoir la réponse de Johann quand je tape dans la recherche 0002 sa me remonte tous les produits commençant contenant et finissant par 0002 remonte j'ai donc remplacer les trois ligne \% par \ du coup quand je cherche 0002 je remonte que ce qui fini par 0002 que puis changer d'autre Johann svp Link to comment Share on other sites More sharing options...
lebarront Posted February 9, 2012 Author Share Posted February 9, 2012 je vient de trouver je vous met le code pour une recherche exacte <?php Class Search extends SearchCore { public static function find($id_lang, $expr, $pageNumber = 1, $pageSize = 1, $orderBy = 'position', $orderWay = 'desc', $ajax = false) { global $cookie; $db = Db::getInstance(); // TODO : smart page management if ($pageNumber < 1) $pageNumber = 1; if ($pageSize < 1) $pageSize = 1; if (!Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay)) die(Tools::displayError()); $whereArray = array(); $inArray = array(); $scoreArray = array(); $words = explode(' ', Search::sanitize($expr, $id_lang)); foreach ($words as $key => $word) if (!empty($word) AND strlen($word) != 1) { $word = str_replace('%', '\\%', $word); $word = str_replace('_', '\\_', $word); $inListResult = $db->ExecuteS(' SELECT DISTINCT `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` = '.intval($id_lang).' 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)).'\'')); $inList=array(); foreach($inListResult as $result) { $inList[]=$result['id_product']; } if(count($inList)) $whereArray[] = ' p.id_product '.($word[0] == '-' ? 'NOT' : '').' IN ('.implode(',', $inList).')'; if ($word[0] != '-') $scoreArray[] = 'sw.word LIKE \''.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'\''; } else unset($words[$key]); if (!sizeof($words)) return ($ajax ? array() : array('total' => 0, 'result' => array())); $score = ''; if (sizeof($scoreArray)) $score = ',( SELECT SUM(weight) FROM `'._DB_PREFIX_.'search_word` sw LEFT JOIN `'._DB_PREFIX_.'search_index` si ON sw.`id_word` = si.`id_word` WHERE sw.`id_lang` = '.intval($id_lang).' AND si.`id_product` = p.`id_product` AND ('.implode(' OR ', $scoreArray).') ) as position'; $eligibleProducts = $db->ExecuteS(' SELECT DISTINCT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg INNER JOIN `'._DB_PREFIX_.'category_product` cp ON cp.`id_category` = cg.`id_category` INNER JOIN `'._DB_PREFIX_.'category` c ON cp.`id_category` = c.`id_category` INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product` WHERE c.`active` = 1 AND p.`active` = 1 AND cg.`id_group` '.(!$cookie->id_customer ? '= 1' : 'IN ( SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).' )').(count($whereArray)>0?' AND '.implode(' AND ', $whereArray):' AND p.id_product=0')); $productPool = ''; foreach ($eligibleProducts as $product) if (!empty($product['id_product'])) $productPool .= $product['id_product'].','; if (empty($productPool)) return ($ajax ? array() : array('total' => 0, 'result' => array())); $productPool = ((strpos($productPool, ',') === false) ? (' = '.(int)$productPool.' ') : (' IN ('.rtrim($productPool, ',').') ')); if ($ajax) { if (!$result = $db->ExecuteS(' SELECT DISTINCT p.`id_product`, pl.`name` as pname, cl.`name` AS cname, cl.`link_rewrite` as crewrite, pl.`link_rewrite` as prewrite '.$score.' FROM `'._DB_PREFIX_.'product` p INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).') INNER JOIN `'._DB_PREFIX_.'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = '.intval($id_lang).') WHERE p.`id_product` '.$productPool.' ORDER BY position DESC LIMIT 10 ')) return false; foreach ($result AS &$row) $row['cname'] = Category::hideCategoryPosition($row['cname']); return $result; } $queryResults = ' SELECT SQL_CALC_FOUND_ROWS p.*, pl.`description_short`, pl.`available_now`, pl.`available_later`, pl.`link_rewrite`, pl.`name`, pa.`id_product_attribute`, tax.`rate`, i.`id_image`, il.`legend`, m.`name` manufacturer_name '.$score.', DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 new FROM '._DB_PREFIX_.'product p INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)Country::getDefaultCountryId().' AND tr.`id_state` = 0) LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') WHERE p.`id_product` '.$productPool.' '.($orderBy ? 'ORDER BY '.$orderBy : '').($orderWay ? ' '.$orderWay : '').' LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize; $result = $db->ExecuteS($queryResults); $total = $db->getValue('SELECT COUNT(*) FROM '._DB_PREFIX_.'product p INNER JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (p.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = '.(int)Country::getDefaultCountryId().' AND tr.`id_state` = 0) LEFT JOIN `'._DB_PREFIX_.'tax` tax ON (tax.`id_tax` = tr.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND default_on = 1) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer` LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') WHERE p.`id_product` '.$productPool); return array('total' => $total,'result' => Product::getProductsProperties($id_lang, $result)); } } ?> Link to comment Share on other sites More sharing options...
lebarront Posted February 9, 2012 Author Share Posted February 9, 2012 johann il me manque une chose pour que ce soit parfait je veut quand tapant 2108 ou 21 08 je trouve mon produit est ce possible?? Link to comment Share on other sites More sharing options...
Johann Posted February 9, 2012 Share Posted February 9, 2012 peut être que c'est possible (à tester) sans modif, simplement en tapant dans la zone de recherche 21?08 ou 21*08 dans la recherche SQL , le ? est remplacé par n'importe quel caractère (ou pas de caractère) Link to comment Share on other sites More sharing options...
lebarront Posted February 9, 2012 Author Share Posted February 9, 2012 ont peut pas faire une modification en mettant ? a la place de % Link to comment Share on other sites More sharing options...
IED Factory Posted September 26, 2017 Share Posted September 26, 2017 Bonjour, vos modif fonctionnent avec un 1.6.1 ? Link to comment Share on other sites More sharing options...
IED Factory Posted September 26, 2017 Share Posted September 26, 2017 Solution pour PS 1.6.1 dans le dossier override/classes créer un fichier Search.php avec ce code : <?php class Search extends SearchCore { public static function sanitize($string, $id_lang, $indexation = false, $iso_code = false) { $string = trim($string); if (empty($string)) { return ''; } $string = Tools::strtolower(strip_tags($string)); $string = html_entity_decode($string, ENT_NOQUOTES, 'utf-8'); $string = preg_replace('/(['.PREG_CLASS_NUMBERS.']+)['.PREG_CLASS_PUNCTUATION.']+(?=['.PREG_CLASS_NUMBERS.'])/u', '\1', $string); $string = preg_replace('/['.PREG_CLASS_SEARCH_EXCLUDE.']+/u', ' ', $string); if ($indexation) { //$string = preg_replace('/[._-]+/', ' ', $string); $string = preg_replace('/[._]+/', ' ', $string); } else { $words = explode(' ', $string); $processed_words = array(); // search for aliases for each word of the query foreach ($words as $word) { $alias = new Alias(null, $word); if (Validate::isLoadedObject($alias)) { $processed_words[] = $alias->search; } else { $processed_words[] = $word; } } $string = implode(' ', $processed_words); $string = preg_replace('/[._]+/', '', $string); //$string = ltrim(preg_replace('/([^ ])-/', '$1 ', ' '.$string)); $string = preg_replace('/[._]+/', '', $string); //$string = preg_replace('/[^\s]-+/', '', $string); } $blacklist = Tools::strtolower(Configuration::get('PS_SEARCH_BLACKLIST', $id_lang)); if (!empty($blacklist)) { $string = preg_replace('/(?<=\s)('.$blacklist.')(?=\s)/Su', '', $string); $string = preg_replace('/^('.$blacklist.')(?=\s)/Su', '', $string); $string = preg_replace('/(?<=\s)('.$blacklist.')$/Su', '', $string); $string = preg_replace('/^('.$blacklist.')$/Su', '', $string); } // If the language is constituted with symbol and there is no "words", then split every chars if (in_array($iso_code, array('zh', 'tw', 'ja')) && function_exists('mb_strlen')) { // Cut symbols from letters $symbols = ''; $letters = ''; foreach (explode(' ', $string) as $mb_word) { if (strlen(Tools::replaceAccentedChars($mb_word)) == mb_strlen(Tools::replaceAccentedChars($mb_word))) { $letters .= $mb_word.' '; } else { $symbols .= $mb_word.' '; } } if (preg_match_all('/./u', $symbols, $matches)) { $symbols = implode(' ', $matches[0]); } $string = $letters.$symbols; } elseif ($indexation) { $minWordLen = (int)Configuration::get('PS_SEARCH_MINWORDLEN'); if ($minWordLen > 1) { $minWordLen -= 1; $string = preg_replace('/(?<=\s)[^\s]{1,'.$minWordLen.'}(?=\s)/Su', ' ', $string); $string = preg_replace('/^[^\s]{1,'.$minWordLen.'}(?=\s)/Su', '', $string); $string = preg_replace('/(?<=\s)[^\s]{1,'.$minWordLen.'}$/Su', '', $string); $string = preg_replace('/^[^\s]{1,'.$minWordLen.'}$/Su', '', $string); } } $string = Tools::replaceAccentedChars(trim(preg_replace('/\s+/', ' ', $string))); return $string; } } Link to comment Share on other sites More sharing options...
DavidCKW Posted October 24, 2018 Share Posted October 24, 2018 Bonjour, Je viens de tester votre code qui fonctionne bien pour les mots seuls. Par contre j'ai un problème si je recherche des références. En effet, je voudrais pouvoir trouver mes produits par référence qui possèdent le caractère - au milieu. Par exemple xx-xxxx. Or si je tape la référence ainsi, je n'ai aucun résultats (alors que j'en avais trop avec la recherche d'origine). Je suppose que dans votre code il y a un nettoyage qui supprime les - Pourriez-vous svp proposer une adaptation pour que les tirets soient acceptés dans le mot recherché svp ? Merci d'avance. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now