Jump to content

How to index some fields of my products ?


WebDevAE

Recommended Posts

Hi !

 

I'd like to know how I can index some fields of my products.

I have created a field on the Back-Office (http://imgur.com/CKHbNJ6) to put some caracteristics.

Then, I showed those informations on the product page (http://imgur.com/RsASZP7).

 

But the Search module doesn't find those informations (http://imgur.com/PnDQjP4)...

 

So, how is it possible to search the text that is on the "Fiche technique" field ?

 

 

Thanks a lot !

 

 

Gregoire

Link to comment
Share on other sites

Thanks for your reply !

Here is the original code :

	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)
		$max_possibilities = $total_languages * count(Shop::getShops(true));
		$limit = max($max_possibilities, floor($limit / $max_possibilities) * $max_possibilities);

		$sql = 'SELECT p.id_product, pl.id_lang, pl.id_shop, l.iso_code';

		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, pa.reference AS pa_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;
					}

And here is my new code, with a new case :

	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)
		$max_possibilities = $total_languages * count(Shop::getShops(true));
		$limit = max($max_possibilities, floor($limit / $max_possibilities) * $max_possibilities);

		$sql = 'SELECT p.id_product, pl.id_lang, pl.id_shop, l.iso_code';

		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, pa.reference AS pa_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;
						case 'ficheTechnique':
							$sql .= ', pl.ficheTechnique';
						break;
					}

Is that ok, or i must do something else ?

I guess that I must modify the sql request below, but I don't know how to proceed.

		$sql .= ' FROM '._DB_PREFIX_.'product p
			LEFT JOIN '._DB_PREFIX_.'product_attribute pa
				ON pa.id_product = p.id_product
			LEFT JOIN '._DB_PREFIX_.'product_lang pl
				ON p.id_product = pl.id_product
			'.Shop::addSqlAssociation('product', 'p').'
			LEFT JOIN '._DB_PREFIX_.'category_lang cl
				ON (cl.id_category = product_shop.id_category_default AND pl.id_lang = cl.id_lang AND cl.id_shop = product_shop.id_shop)
			LEFT JOIN '._DB_PREFIX_.'manufacturer m
				ON m.id_manufacturer = p.id_manufacturer
			LEFT JOIN '._DB_PREFIX_.'lang l
				ON l.id_lang = pl.id_lang
			WHERE product_shop.indexed = 0
			AND product_shop.visibility IN ("both", "search")
			'.($id_product ? 'AND p.id_product = '.(int)$id_product : '').'
			AND product_shop.`active` = 1
			LIMIT '.(int)$limit;
		return Db::getInstance()->executeS($sql); 

Thanks !

Edited by Webmasterdom (see edit history)
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...