[*] BO : Merge of https://github.com/PrestaShop/PrestaShop/pull/636
This commit is contained in:
1 parent
be91ec02f2
commit
f6fed64472
2 files changed
+47
-12
No files matched your search
+45
-11
@@ -394,16 +394,47 @@ class SearchCore
|
|||||||
return $features;
|
return $features;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function getProductsToIndex($total_languages, $id_product = false, $limit = 50)
|
protected static function getProductsToIndex($total_languages, $id_product = false, $limit = 50, $weight_array = array())
|
||||||
{
|
{
|
||||||
// Adjust the limit to get only "whole" products, in every languages (and at least one)
|
// Adjust the limit to get only "whole" products, in every languages (and at least one)
|
||||||
$max_possibilities = $total_languages * count(Shop::getShops(true));
|
$max_possibilities = $total_languages * count(Shop::getShops(true));
|
||||||
$limit = max($max_possibilities, floor($limit / $max_possibilities) * $max_possibilities);
|
$limit = max($max_possibilities, floor($limit / $max_possibilities) * $max_possibilities);
|
||||||
|
|
||||||
return Db::getInstance()->executeS('
|
$sql = 'SELECT p.id_product, pl.id_lang, pl.id_shop, pl.name pname, p.reference, p.ean13, p.upc,
|
||||||
SELECT p.id_product, pl.id_lang, pl.id_shop, pl.name pname, p.reference, p.ean13, p.upc,
|
pl.description_short, pl.description, cl.name cname, m.name mname, l.iso_code';
|
||||||
pl.description_short, pl.description, cl.name cname, m.name mname, l.iso_code
|
|
||||||
FROM '._DB_PREFIX_.'product p
|
if (is_array($weight_array))
|
||||||
|
foreach($weight_array as $key => $weight)
|
||||||
|
if ((int)$weight)
|
||||||
|
switch($key)
|
||||||
|
{
|
||||||
|
case 'pname':
|
||||||
|
$sql .= ', pl.name pname';
|
||||||
|
break;
|
||||||
|
case 'reference':
|
||||||
|
$sql .= ', p.reference';
|
||||||
|
break;
|
||||||
|
case 'ean13':
|
||||||
|
$sql .= ', p.ean13';
|
||||||
|
break;
|
||||||
|
case 'upc':
|
||||||
|
$sql .= ', p.upc';
|
||||||
|
break;
|
||||||
|
case 'description_short':
|
||||||
|
$sql .= ', pl.description_short';
|
||||||
|
break;
|
||||||
|
case 'description':
|
||||||
|
$sql .= ', pl.description';
|
||||||
|
break;
|
||||||
|
case 'cname':
|
||||||
|
$sql .= ', cl.name cname';
|
||||||
|
break;
|
||||||
|
case 'mname':
|
||||||
|
$sql .= ', m.name mname';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= ' FROM '._DB_PREFIX_.'product p
|
||||||
LEFT JOIN '._DB_PREFIX_.'product_lang pl
|
LEFT JOIN '._DB_PREFIX_.'product_lang pl
|
||||||
ON p.id_product = pl.id_product
|
ON p.id_product = pl.id_product
|
||||||
'.Shop::addSqlAssociation('product', 'p').'
|
'.Shop::addSqlAssociation('product', 'p').'
|
||||||
@@ -416,8 +447,8 @@ class SearchCore
|
|||||||
WHERE product_shop.indexed = 0
|
WHERE product_shop.indexed = 0
|
||||||
AND product_shop.visibility IN ("both", "search")
|
AND product_shop.visibility IN ("both", "search")
|
||||||
'.($id_product ? 'AND p.id_product = '.(int)$id_product : '').'
|
'.($id_product ? 'AND p.id_product = '.(int)$id_product : '').'
|
||||||
LIMIT '.(int)$limit
|
LIMIT '.(int)$limit;
|
||||||
);
|
return Db::getInstance()->executeS($sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function indexation($full = false, $id_product = false)
|
public static function indexation($full = false, $id_product = false)
|
||||||
@@ -490,15 +521,18 @@ class SearchCore
|
|||||||
$total_languages = count(Language::getLanguages(false));
|
$total_languages = count(Language::getLanguages(false));
|
||||||
|
|
||||||
// Products are processed 50 by 50 in order to avoid overloading MySQL
|
// Products are processed 50 by 50 in order to avoid overloading MySQL
|
||||||
while (($products = Search::getProductsToIndex($total_languages, $id_product, 50)) && (count($products) > 0))
|
while (($products = Search::getProductsToIndex($total_languages, $id_product, 50, $weight_array)) && (count($products) > 0))
|
||||||
{
|
{
|
||||||
$products_array = array();
|
$products_array = array();
|
||||||
// Now each non-indexed product is processed one by one, langage by langage
|
// Now each non-indexed product is processed one by one, langage by langage
|
||||||
foreach ($products as $product)
|
foreach ($products as $product)
|
||||||
{
|
{
|
||||||
$product['tags'] = Search::getTags($db, (int)$product['id_product'], (int)$product['id_lang']);
|
if ((int)$weight_array['tags'])
|
||||||
$product['attributes'] = Search::getAttributes($db, (int)$product['id_product'], (int)$product['id_lang']);
|
$product['tags'] = Search::getTags($db, (int)$product['id_product'], (int)$product['id_lang']);
|
||||||
$product['features'] = Search::getFeatures($db, (int)$product['id_product'], (int)$product['id_lang']);
|
if ((int)$weight_array['attributes'])
|
||||||
|
$product['attributes'] = Search::getAttributes($db, (int)$product['id_product'], (int)$product['id_lang']);
|
||||||
|
if ((int)$weight_array['features'])
|
||||||
|
$product['features'] = Search::getFeatures($db, (int)$product['id_product'], (int)$product['id_lang']);
|
||||||
|
|
||||||
// Data must be cleaned of html, bad characters, spaces and anything, then if the resulting words are long enough, they're added to the array
|
// Data must be cleaned of html, bad characters, spaces and anything, then if the resulting words are long enough, they're added to the array
|
||||||
$product_array = array();
|
$product_array = array();
|
||||||
|
|||||||
@@ -130,7 +130,8 @@ class AdminSearchConfControllerCore extends AdminController
|
|||||||
'info' =>
|
'info' =>
|
||||||
$this->l('The "weight" represents its importance and relevance for the ranking of the products when completing a new search.').'<br />
|
$this->l('The "weight" represents its importance and relevance for the ranking of the products when completing a new search.').'<br />
|
||||||
'.$this->l('A word with a weight of eight will have four times more value than a word with a weight of two.').'<br /><br />
|
'.$this->l('A word with a weight of eight will have four times more value than a word with a weight of two.').'<br /><br />
|
||||||
'.$this->l('We advise you to set a greater weight for words which appear in the name or reference of a product. This will allow the search results to be as precise and relevant as possible.'),
|
'.$this->l('We advise you to set a greater weight for words which appear in the name or reference of a product. This will allow the search results to be as precise and relevant as possible.').'<br /><br />
|
||||||
|
'.$this->l('Setting a weight to 0 will exclude that field from search index. Re-build of the entire index is required when changing to or from 0'),
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'PS_SEARCH_WEIGHT_PNAME' => array(
|
'PS_SEARCH_WEIGHT_PNAME' => array(
|
||||||
'title' => $this->l('Product name weight'),
|
'title' => $this->l('Product name weight'),
|
||||||
|
|||||||
Reference in new issue
Block a user