Index: src/system/classes/listing/ProductListingContentControl.inc.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/system/classes/listing/ProductListingContentControl.inc.php	(revision 8facc5f81bff309abf833394892e03058d4cc2dc)
+++ src/system/classes/listing/ProductListingContentControl.inc.php	(revision )
@@ -63,6 +63,7 @@
 	protected $filter_price_max;
 	protected $filter_price_min;
 	protected $filter_selection_html;
+	protected $flexsearch = false;
 	protected $include_subcategories_for_search;
 	protected $languages_id;
 	protected $last_listing_sql;
@@ -210,9 +211,21 @@
 
 			$coo_listing_split = new splitPageResults($this->sql_query, $this->page_number, $t_max_display_search_results, 'p.products_id');
 			$t_products_array = array();
-
+			
-			if($coo_listing_split->number_of_rows > 0)
+			$this->flexsearch = false;
+			if(gm_get_conf('MODULE_CENTER_FLEXSEARCH_INSTALLED') == 1 
+			   && $coo_listing_split->number_of_rows <= gm_get_conf('SEARCH_ACTIVATE_SUGGEST')
+			)
 			{
+				$flexsearch_keywords = $this->isFlexSearch($this->search_keywords);
+				if(count($flexsearch_keywords))
+				{
+					$this->flexsearch = true;
+				}
+			}
+			
+			if($coo_listing_split->number_of_rows > 0 || $this->flexsearch)
+			{
 				$t_category_data_array = $this->get_category_data_array();
 
 				$t_category_name = $t_category_data_array['name'];
@@ -228,11 +241,23 @@
 				$t_navigation_html = $coo_navigation_view->get_html();
 
 				$t_rows_count = 0;
+				if($this->flexsearch)
+				{
+					$t_rows = $flexsearch_keywords;
+				}
+				else
+				{
-				$t_query = $coo_listing_split->sql_query;
+					$t_query  = $coo_listing_split->sql_query;
-				$t_result = xtc_db_query($t_query);
+					$t_result = xtc_db_query($t_query);
-
+					$t_rows = array();
-				while($t_product_array = xtc_db_fetch_array($t_result))
-				{
+					while($t_product_array = xtc_db_fetch_array($t_result))
+					{
+						$t_rows[] = $t_product_array;
+					}
+				}
+
+				foreach($t_rows as $t_product_array)
+				{
 					$t_rows_count++;
 
 					// check if product has properties
@@ -396,8 +421,16 @@
 				$coo_product_listing_view->set_('navigation_html', $t_navigation_html);
 				$coo_product_listing_view->set_('navigation_info_html', $coo_listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS));
 				$coo_product_listing_view->set_('products_array', $t_products_array);
+				
+				if($this->flexsearch)
+				{
+					$coo_product_listing_view->set_('products_per_page', (int)gm_get_conf('SEARCH_MAX_PRODUCTS_SUGGEST'));
+				}
+				else
+				{
-				$coo_product_listing_view->set_('products_per_page', (int)MAX_DISPLAY_SEARCH_RESULTS);
+					$coo_product_listing_view->set_('products_per_page', (int)MAX_DISPLAY_SEARCH_RESULTS);
+				}
-
+				
 				if(isset($this->search_keywords))
 				{
 					$coo_product_listing_view->set_('search_keywords', $this->search_keywords);
@@ -2039,5 +2072,156 @@
 	public function setProductListingTemplatePath($path)
 	{
 		$this->productListingTemplatePath = $path;
+	}
+	
+	
+	protected function isFlexSearch($c_needle)
+	{
+		$products_counter = array();
+		
+		//$SSML = gm_get_conf('SEARCH_SPLIT_MINIMUM_LENGTH');
+		$searchWeightSimiliarText = gm_get_conf('SEARCH_WEIGHT_SIMILAR_TEXT');
+		$searchWeightMetaphone    = gm_get_conf('SEARCH_WEIGHT_METAPHONE');
+		$searchWeightSoundex      = gm_get_conf('SEARCH_WEIGHT_SOUNDEX');
+		$searchWeightLevenshtein  = gm_get_conf('SEARCH_WEIGHT_LEVENSHTEIN');
+		// alle Produktnamen holen
+		$sql           = "SELECT p.products_id, pd.gm_search_keywords, pd.products_name
+				FROM " . TABLE_PRODUCTS . " AS p LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " AS pd ON (p.products_id = pd.products_id)
+				WHERE p.products_status = '1'
+				AND pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";
+		$product_query = xtc_db_query($sql);
+		$max_count     = 0;
+		//$mysplitkeys = explode(' ', $c_needle);
+		$mysplitkeys = str_replace(" ", "", $c_needle);
+		while($product_array = xtc_db_fetch_array($product_query))
+		{
+			
+			$searchArray['products_id']['count'] = 0;
+			
+			$value   = $mysplitkeys;
+			$valuens = $product_array['gm_search_keywords'];
+			if(strlen($valuens) > $SSML && $valuens != '')
+			{
+				if(strtolower($valuens) == strtolower($value))
+				{
+					$searchArray['products_id']['count'] += 1;
+					$proderg['treffer'][$product_array['products_id']] = $searchArray['products_id']['count'];
+					if($proderg['ergebnis'][$product_array['products_id']] != '')
+					{
+						$proderg['ergebnis'][$product_array['products_id']] += 100;
+					}
+					else
+					{
+						$proderg['ergebnis'][$product_array['products_id']] = 100;
+					}
+					$proderg['products_id'][$product_array['products_id']] = $product_array['products_id'];
+				}
+				else
+				{
+					$sim      = 0;
+					$simcount = 0;
+					if($searchWeightSimiliarText != 0)
+					{
+						similar_text(strtolower($value), strtolower($valuens), $sim1);
+						if($sim1 > $searchWeightSimiliarText)
+						{ //$SWST
+							$sim      = $sim1;
+							$simcount = $simcount + 1;
+						}
+					}
+					if($searchWeightMetaphone != 0)
+					{
+						similar_text(metaphone(strtolower($valuens)), metaphone(strtolower($value)), $sim2);
+						if($sim2 > $searchWeightMetaphone)
+						{
+							$sim      = $sim + $sim2;
+							$simcount = $simcount + 1;
+						}
+					}
+					if($searchWeightSoundex != 0)
+					{
+						similar_text(soundex(strtolower($valuens)), soundex(strtolower($value)), $sim3);
+						if($sim3 > $searchWeightSoundex)
+						{
+							if($searchWeightSimiliarText != 0)
+							{
+								if($sim1 < $sim3)
+								{
+									$sim3 = $sim1;
+								}
+							}
+							$sim      = $sim + $sim3;
+							$simcount = $simcount + 1;
+						}
+					}
+					if($searchWeightLevenshtein != 0)
+					{
+						$sim7 = strlen($valuens) * strlen($value) / levenshtein(strtolower($value),
+						                                                        strtolower($valuens));
+						if($sim7 > $searchWeightLevenshtein)
+						{
+							$sim      = $sim + $sim7;
+							$simcount = $simcount + 1;
+						}
+					}
+					unset($ergebnis);
+					if($simcount > 0)
+					{
+						$ergebnis = $sim / $simcount;
+					}
+					
+					if(isset($ergebnis) && $ergebnis > 50)
+					{
+						$searchArray['products_id']['count'] = $searchArray['products_id']['count'] + $simcount;
+						
+						$proderg['treffer'][$product_array['products_id']] = $searchArray['products_id']['count'];
+						if($proderg['ergebnis'][$product_array['products_id']] != '')
+						{
+							$proderg['ergebnis'][$product_array['products_id']] = $proderg['ergebnis'][$product_array['products_id']]
+							                                                      + $ergebnis;
+						}
+						else
+						{
+							$proderg['ergebnis'][$product_array['products_id']] = $ergebnis;
+						}
+						$proderg['products_id'][$product_array['products_id']] = $product_array['products_id'];
+					}
+				}
+			}
+		}
+		if($proderg['treffer'] != '')
+		{
+			array_multisort($proderg['treffer'], SORT_NUMERIC, SORT_DESC, $proderg['ergebnis'], SORT_NUMERIC, SORT_DESC,
+			                $proderg['products_id'], SORT_NUMERIC, SORT_ASC);
+			
+			for($index = 0; $index < 150; $index++)
+			{
+				if(empty($proderg['products_id'][$index]) === false)
+				{
+					$topten['products_id'][$index] = $proderg['products_id'][$index];
+					$topten['treffer'][$index]     = $proderg['treffer'][$index];
+					$topten['ergebnis'][$index]    = $proderg['ergebnis'][$index];
+				}
+			}
+			
+			array_multisort($topten['ergebnis'], SORT_NUMERIC, SORT_DESC, $topten['treffer'], SORT_NUMERIC, SORT_DESC,
+			                $topten['products_id'], SORT_NUMERIC, SORT_ASC);
+			$counter = sizeof($module_content);
+			while($topten['products_id'][$counter] && $counter < gm_get_conf('SEARCH_MAX_PRODUCTS_SUGGEST'))
+			{
+				
+				$products_count_query       = xtc_db_query("SELECT p.*, pd.products_name FROM " . TABLE_PRODUCTS
+				                                           . " AS p LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " AS pd ON (p.products_id = pd.products_id)
+                                                WHERE p.products_status = '1'
+				                                        AND pd.language_id = '" . (int)$_SESSION['languages_id'] . "'"
+				                                           . $fsk_lock . $group_check . " 
+                                                AND p.products_id = " . (int)$topten['products_id'][$counter] . "  ");
+				$products_counter[$counter] = xtc_db_fetch_array($products_count_query);
+				
+				$counter++;
+			}
+		}
+		
+		return $products_counter;
 	}
 }
\ No newline at end of file
