当前位置: 首页>>代码示例>>PHP>>正文


PHP Search::setProductsAsIndexed方法代码示例

本文整理汇总了PHP中Search::setProductsAsIndexed方法的典型用法代码示例。如果您正苦于以下问题:PHP Search::setProductsAsIndexed方法的具体用法?PHP Search::setProductsAsIndexed怎么用?PHP Search::setProductsAsIndexed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Search的用法示例。


在下文中一共展示了Search::setProductsAsIndexed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: indexation


//.........这里部分代码省略.........
            if (!isset($word_ids_by_word[$word_id['id_shop']][$word_id['id_lang']])) {
                $word_ids_by_word[$word_id['id_shop']][$word_id['id_lang']] = array();
            }
            $word_ids_by_word[$word_id['id_shop']][$word_id['id_lang']]['_' . $word_id['word']] = (int) $word_id['id_word'];
        }
        // Retrieve the number of languages
        $total_languages = count(Language::getLanguages(false));
        // Products are processed 50 by 50 in order to avoid overloading MySQL
        while (($products = Search::getProductsToIndex($total_languages, $id_product, 50)) && count($products) > 0) {
            $products_array = array();
            // Now each non-indexed product is processed one by one, langage by langage
            foreach ($products as $product) {
                $product['tags'] = Search::getTags($db, (int) $product['id_product'], (int) $product['id_lang']);
                $product['attributes'] = Search::getAttributes($db, (int) $product['id_product'], (int) $product['id_lang']);
                $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
                $product_array = array();
                foreach ($product as $key => $value) {
                    if (strncmp($key, 'id_', 3) && isset($weight_array[$key])) {
                        $words = explode(' ', Search::sanitize($value, (int) $product['id_lang'], true, $product['iso_code']));
                        foreach ($words as $word) {
                            if (!empty($word)) {
                                $word = Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH);
                                // Remove accents
                                $word = Tools::replaceAccentedChars($word);
                                if (!isset($product_array[$word])) {
                                    $product_array[$word] = 0;
                                }
                                $product_array[$word] += $weight_array[$key];
                            }
                        }
                    }
                }
                // If we find words that need to be indexed, they're added to the word table in the database
                if (count($product_array)) {
                    $query_array = $query_array2 = array();
                    foreach ($product_array as $word => $weight) {
                        if ($weight && !isset($word_ids_by_word['_' . $word])) {
                            $query_array[$word] = '(' . (int) $product['id_lang'] . ', ' . (int) $product['id_shop'] . ', \'' . pSQL($word) . '\')';
                            $query_array2[] = '\'' . pSQL($word) . '\'';
                            $word_ids_by_word[$product['id_shop']][$product['id_lang']]['_' . $word] = 0;
                        }
                    }
                    if ($query_array2) {
                        $existing_words = $db->executeS('
						SELECT DISTINCT word FROM ' . _DB_PREFIX_ . 'search_word
							WHERE word IN (' . implode(',', $query_array2) . ')
						AND id_lang = ' . (int) $product['id_lang'] . '
						AND id_shop = ' . (int) $product['id_shop']);
                        foreach ($existing_words as $data) {
                            unset($query_array[Tools::replaceAccentedChars($data['word'])]);
                        }
                    }
                    if (count($query_array)) {
                        // The words are inserted...
                        $db->execute('
						INSERT IGNORE INTO ' . _DB_PREFIX_ . 'search_word (id_lang, id_shop, word)
						VALUES ' . implode(',', $query_array));
                    }
                    if (count($query_array2)) {
                        // ...then their IDs are retrieved and added to the cache
                        $added_words = $db->executeS('
						SELECT sw.id_word, sw.word
						FROM ' . _DB_PREFIX_ . 'search_word sw
						WHERE sw.word IN (' . implode(',', $query_array2) . ')
						AND sw.id_lang = ' . (int) $product['id_lang'] . '
						AND sw.id_shop = ' . (int) $product['id_shop'] . '
						LIMIT ' . count($query_array2));
                        // replace accents from the retrieved words so that words without accents or with differents accents can still be linked
                        foreach ($added_words as $word_id) {
                            $word_ids_by_word[$product['id_shop']][$product['id_lang']]['_' . Tools::replaceAccentedChars($word_id['word'])] = (int) $word_id['id_word'];
                        }
                    }
                }
                foreach ($product_array as $word => $weight) {
                    if (!$weight) {
                        continue;
                    }
                    if (!isset($word_ids_by_word[$product['id_shop']][$product['id_lang']]['_' . $word])) {
                        continue;
                    }
                    if (!$word_ids_by_word[$product['id_shop']][$product['id_lang']]['_' . $word]) {
                        continue;
                    }
                    $query_array3[] = '(' . (int) $product['id_product'] . ',' . (int) $word_ids_by_word[$product['id_shop']][$product['id_lang']]['_' . $word] . ',' . (int) $weight . ')';
                    // Force save every 200 words in order to avoid overloading MySQL
                    if (++$count_words % 200 == 0) {
                        Search::saveIndex($query_array3);
                    }
                }
                if (!in_array($product['id_product'], $products_array)) {
                    $products_array[] = (int) $product['id_product'];
                }
            }
            Search::setProductsAsIndexed($products_array);
            // One last save is done at the end in order to save what's left
            Search::saveIndex($query_array3);
        }
        return true;
    }
开发者ID:rongandat,项目名称:vatfairfoot,代码行数:101,代码来源:Search.php

示例2: indexation


//.........这里部分代码省略.........
				WHERE product_shop.`visibility` IN ("both", "search")
				AND product_shop.`active` = 1
				AND ' . ($id_product ? 'p.`id_product` = ' . (int) $id_product : 'product_shop.`indexed` = 0'));
        }
        // Every fields are weighted according to the configuration in the backend
        $weight_array = array('pname' => Configuration::get('PS_SEARCH_WEIGHT_PNAME'), 'reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'pa_reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'supplier_reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'pa_supplier_reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'ean13' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'pa_ean13' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'upc' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'pa_upc' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'description_short' => Configuration::get('PS_SEARCH_WEIGHT_SHORTDESC'), 'description' => Configuration::get('PS_SEARCH_WEIGHT_DESC'), 'cname' => Configuration::get('PS_SEARCH_WEIGHT_CNAME'), 'mname' => Configuration::get('PS_SEARCH_WEIGHT_MNAME'), 'tags' => Configuration::get('PS_SEARCH_WEIGHT_TAG'), 'attributes' => Configuration::get('PS_SEARCH_WEIGHT_ATTRIBUTE'), 'features' => Configuration::get('PS_SEARCH_WEIGHT_FEATURE'));
        // Those are kind of global variables required to save the processed data in the database every X occurrences, in order to avoid overloading MySQL
        $count_words = 0;
        $query_array3 = array();
        // Retrieve the number of languages
        $total_languages = count(Language::getIDs(false));
        $sql_attribute = Search::getSQLProductAttributeFields($weight_array);
        // Products are processed 50 by 50 in order to avoid overloading MySQL
        while (($products = Search::getProductsToIndex($total_languages, $id_product, 50, $weight_array)) && count($products) > 0) {
            $products_array = array();
            // Now each non-indexed product is processed one by one, langage by langage
            foreach ($products as $product) {
                if ((int) $weight_array['tags']) {
                    $product['tags'] = Search::getTags($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']);
                }
                if ($sql_attribute) {
                    $attribute_fields = Search::getAttributesFields($db, (int) $product['id_product'], $sql_attribute);
                    if ($attribute_fields) {
                        $product['attributes_fields'] = $attribute_fields;
                    }
                }
                // 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();
                foreach ($product as $key => $value) {
                    if ($key == 'attributes_fields') {
                        foreach ($value as $pa_array) {
                            foreach ($pa_array as $pa_key => $pa_value) {
                                Search::fillProductArray($product_array, $weight_array, $pa_key, $pa_value, $product['id_lang'], $product['iso_code']);
                            }
                        }
                    } else {
                        Search::fillProductArray($product_array, $weight_array, $key, $value, $product['id_lang'], $product['iso_code']);
                    }
                }
                // If we find words that need to be indexed, they're added to the word table in the database
                if (is_array($product_array) && !empty($product_array)) {
                    $query_array = $query_array2 = array();
                    foreach ($product_array as $word => $weight) {
                        if ($weight) {
                            $query_array[$word] = '(' . (int) $product['id_lang'] . ', ' . (int) $product['id_shop'] . ', \'' . pSQL($word) . '\')';
                            $query_array2[] = '\'' . pSQL($word) . '\'';
                        }
                    }
                    if (is_array($query_array) && !empty($query_array)) {
                        // The words are inserted...
                        $db->execute('
						INSERT IGNORE INTO ' . _DB_PREFIX_ . 'search_word (id_lang, id_shop, word)
						VALUES ' . implode(',', $query_array), false);
                    }
                    $word_ids_by_word = array();
                    if (is_array($query_array2) && !empty($query_array2)) {
                        // ...then their IDs are retrieved
                        $added_words = $db->executeS('
						SELECT sw.id_word, sw.word
						FROM ' . _DB_PREFIX_ . 'search_word sw
						WHERE sw.word IN (' . implode(',', $query_array2) . ')
						AND sw.id_lang = ' . (int) $product['id_lang'] . '
						AND sw.id_shop = ' . (int) $product['id_shop'], true, false);
                        foreach ($added_words as $word_id) {
                            $word_ids_by_word['_' . $word_id['word']] = (int) $word_id['id_word'];
                        }
                    }
                }
                foreach ($product_array as $word => $weight) {
                    if (!$weight) {
                        continue;
                    }
                    if (!isset($word_ids_by_word['_' . $word])) {
                        continue;
                    }
                    $id_word = $word_ids_by_word['_' . $word];
                    if (!$id_word) {
                        continue;
                    }
                    $query_array3[] = '(' . (int) $product['id_product'] . ',' . (int) $id_word . ',' . (int) $weight . ')';
                    // Force save every 200 words in order to avoid overloading MySQL
                    if (++$count_words % 200 == 0) {
                        Search::saveIndex($query_array3);
                    }
                }
                $products_array[] = (int) $product['id_product'];
            }
            $products_array = array_unique($products_array);
            Search::setProductsAsIndexed($products_array);
            // One last save is done at the end in order to save what's left
            Search::saveIndex($query_array3);
        }
        return true;
    }
开发者ID:ortegon000,项目名称:tienda,代码行数:101,代码来源:Search.php

示例3: indexation


//.........这里部分代码省略.........
            }
            $wordIdsByWord[$wordId['id_lang']]['_' . $wordId['word']] = (int) $wordId['id_word'];
        }
        // Now each non-indexed product is processed one by one, langage by langage
        while ($product = $db->nextRow($products)) {
            $product['tags'] = Search::getTags($db, (int) $product['id_product'], (int) $product['id_lang']);
            $product['attributes'] = Search::getAttributes($db, (int) $product['id_product'], (int) $product['id_lang']);
            $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
            $pArray = array();
            foreach ($product as $key => $value) {
                if (strncmp($key, 'id_', 3)) {
                    $words = explode(' ', Search::sanitize($value, (int) $product['id_lang'], true));
                    foreach ($words as $word) {
                        if (!empty($word)) {
                            $word = Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH);
                            if (!isset($pArray[$word])) {
                                $pArray[$word] = 0;
                            }
                            $pArray[$word] += $weightArray[$key];
                        }
                    }
                }
            }
            // If we find words that need to be indexed, they're added to the word table in the database
            if (sizeof($pArray)) {
                $list = '';
                foreach ($pArray as $word => $weight) {
                    $list .= '\'' . $word . '\',';
                }
                $list = rtrim($list, ',');
                $queryArray = array();
                $queryArray2 = array();
                foreach ($pArray as $word => $weight) {
                    if ($weight and !isset($wordIdsByWord['_' . $word])) {
                        $queryArray[] = '(' . (int) $product['id_lang'] . ',\'' . pSQL($word) . '\')';
                        $queryArray2[] = '\'' . pSQL($word) . '\'';
                        $wordIdsByWord[$product['id_lang']]['_' . $word] = 0;
                    }
                }
                if (count($queryArray)) {
                    // The words are inserted...
                    $db->Execute('
					INSERT IGNORE INTO ' . _DB_PREFIX_ . 'search_word (id_lang, word)
					VALUES ' . implode(',', $queryArray));
                    // ...then their IDs are retrieved and added to the cache
                    $addedWords = $db->ExecuteS('
					SELECT sw.id_word, sw.word
					FROM ' . _DB_PREFIX_ . 'search_word sw
					WHERE sw.word IN (' . implode(',', $queryArray2) . ')
					AND sw.id_lang = ' . (int) $product['id_lang'] . '
					LIMIT ' . count($queryArray2));
                    foreach ($addedWords as $wordId) {
                        $wordIdsByWord[$product['id_lang']]['_' . $wordId['word']] = (int) $wordId['id_word'];
                    }
                }
            }
            foreach ($pArray as $word => $weight) {
                if (!$weight) {
                    continue;
                }
                if (!isset($wordIdsByWord[$product['id_lang']]['_' . $word])) {
                    continue;
                }
                if (!$wordIdsByWord[$product['id_lang']]['_' . $word]) {
                    continue;
                }
                $queryArray3[] = '(' . (int) $product['id_product'] . ',' . (int) $wordIdsByWord[$product['id_lang']]['_' . $word] . ',' . (int) $weight . ')';
                // Force save every 200 words in order to avoid overloading MySQL
                if (++$countWords % 200 == 0) {
                    Search::saveIndex($queryArray3);
                }
            }
            if (!in_array($product['id_product'], $productsArray)) {
                $productsArray[] = (int) $product['id_product'];
            }
            // Force save every 50 products in order to avoid overloading MySQL
            if (++$countProducts % 50 == 0) {
                Search::setProductsAsIndexed($productsArray);
            }
        }
        // One last save is done at the end in order to save what's left
        Search::saveIndex($queryArray3);
        Search::setProductsAsIndexed($productsArray);
        // If it has been deleted, the index is created again once the indexation is done
        if (!$dropIndex) {
            $dropIndex = true;
            $result = $db->ExecuteS('SHOW INDEX FROM `' . _DB_PREFIX_ . 'search_index`');
            foreach ($result as $row) {
                if (strtolower($row['Key_name']) == 'primary') {
                    $dropIndex = false;
                }
            }
        }
        if ($dropIndex) {
            $db->Execute('ALTER TABLE `' . _DB_PREFIX_ . 'search_index` ADD PRIMARY KEY (`id_word`, `id_product`)');
        }
        Configuration::updateValue('PS_NEED_REBUILD_INDEX', 0);
        return true;
    }
开发者ID:priyankajsr19,项目名称:shalu,代码行数:101,代码来源:Search.php

示例4: indexation

    public static function indexation($full = false)
    {
        $db = Db::getInstance();
        if ($full) {
            $db->Execute('TRUNCATE ' . _DB_PREFIX_ . 'search_index');
            $db->Execute('TRUNCATE ' . _DB_PREFIX_ . 'search_word');
            $db->Execute('UPDATE ' . _DB_PREFIX_ . 'product SET indexed = 0');
        } else {
            $products = $db->ExecuteS('SELECT id_product FROM ' . _DB_PREFIX_ . 'product WHERE indexed = 0');
            $ids = array();
            if ($products) {
                foreach ($products as $product) {
                    $ids[] = (int) $product['id_product'];
                }
            }
            if (sizeof($ids)) {
                $db->Execute('DELETE FROM ' . _DB_PREFIX_ . 'search_index WHERE id_product IN (' . implode(',', $ids) . ')');
            }
        }
        $weightArray = array('pname' => Configuration::get('PS_SEARCH_WEIGHT_PNAME'), 'reference' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'ean13' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'upc' => Configuration::get('PS_SEARCH_WEIGHT_REF'), 'description_short' => Configuration::get('PS_SEARCH_WEIGHT_SHORTDESC'), 'description' => Configuration::get('PS_SEARCH_WEIGHT_DESC'), 'cname' => Configuration::get('PS_SEARCH_WEIGHT_CNAME'), 'mname' => Configuration::get('PS_SEARCH_WEIGHT_MNAME'), 'tags' => Configuration::get('PS_SEARCH_WEIGHT_TAG'), 'attributes' => Configuration::get('PS_SEARCH_WEIGHT_ATTRIBUTE'), 'features' => Configuration::get('PS_SEARCH_WEIGHT_FEATURE'));
        $products = $db->ExecuteS('
		SELECT p.id_product, pl.id_lang, pl.name pname, p.reference, p.ean13, p.upc, pl.description_short, pl.description, cl.name cname, m.name mname
		FROM ' . _DB_PREFIX_ . 'product p
		LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON p.id_product = pl.id_product
		LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = p.id_category_default AND pl.id_lang = cl.id_lang)
		LEFT JOIN ' . _DB_PREFIX_ . 'manufacturer m ON m.id_manufacturer = p.id_manufacturer
		WHERE p.indexed = 0', false);
        $countWords = 0;
        $countProducts = 0;
        $queryArray = array();
        $queryArray2 = array();
        $productsArray = array();
        while ($product = $db->nextRow($products)) {
            $product['tags'] = Search::getTags($db, (int) $product['id_product'], (int) $product['id_lang']);
            $product['attributes'] = Search::getAttributes($db, (int) $product['id_product'], (int) $product['id_lang']);
            $product['features'] = Search::getFeatures($db, (int) $product['id_product'], (int) $product['id_lang']);
            $pArray = array();
            foreach ($product as $key => $value) {
                if (strncmp($key, 'id_', 3)) {
                    $words = explode(' ', Search::sanitize($value, (int) $product['id_lang'], true));
                    foreach ($words as $word) {
                        if (!empty($word)) {
                            $word = Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH);
                            if (!isset($pArray[$word])) {
                                $pArray[$word] = $weightArray[$key];
                            } else {
                                $pArray[$word] += $weightArray[$key];
                            }
                        }
                    }
                }
            }
            foreach ($pArray as $word => $weight) {
                if (!$weight) {
                    continue;
                }
                $queryArray[] = '(' . (int) $product['id_lang'] . ',\'' . pSQL($word) . '\')';
                $queryArray2[] = '(' . (int) $product['id_product'] . ',(SELECT id_word FROM ' . _DB_PREFIX_ . 'search_word WHERE word = \'' . pSQL($word) . '\' AND id_lang = ' . (int) $product['id_lang'] . ' LIMIT 1),' . (int) $weight . ')';
                // Force save every 40 words in order to avoid overloading MySQL
                if (++$countWords % 40 == 0) {
                    Search::saveIndex($queryArray, $queryArray2);
                }
            }
            if (!in_array($product['id_product'], $productsArray)) {
                $productsArray[] = (int) $product['id_product'];
            }
            // Force save every 20 products in order to avoid overloading MySQL
            if (++$countProducts % 20 == 0) {
                Search::setProductsAsIndexed($productsArray);
                $productsArray = array();
            }
        }
        // One last save is done at the end in order to save what's left
        Search::saveIndex($queryArray, $queryArray2);
        Search::setProductsAsIndexed($productsArray);
        $db->Execute('DELETE FROM ' . _DB_PREFIX_ . 'search_word WHERE id_word NOT IN (SELECT id_word FROM ' . _DB_PREFIX_ . 'search_index)');
        return true;
    }
开发者ID:hecbuma,项目名称:quali-fisioterapia,代码行数:78,代码来源:Search.php


注:本文中的Search::setProductsAsIndexed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。