Projekt

Allgemein

Profil

GX-Abgewiesen #47184 » Flexsearch_Listing_Fix_Zwischenstand.patch

Moritz Bunjes, 27.06.2016 20:22

Unterschiede anzeigen:

src/system/classes/listing/ProductListingContentControl.inc.php (revision )
63 63
	protected $filter_price_max;
64 64
	protected $filter_price_min;
65 65
	protected $filter_selection_html;
66
	protected $flexsearch = false;
66 67
	protected $include_subcategories_for_search;
67 68
	protected $languages_id;
68 69
	protected $last_listing_sql;
......
210 211

  
211 212
			$coo_listing_split = new splitPageResults($this->sql_query, $this->page_number, $t_max_display_search_results, 'p.products_id');
212 213
			$t_products_array = array();
213

  
214
			
214
			if($coo_listing_split->number_of_rows > 0)
215
			$this->flexsearch = false;
216
			if(gm_get_conf('MODULE_CENTER_FLEXSEARCH_INSTALLED') == 1 
217
			   && $coo_listing_split->number_of_rows <= gm_get_conf('SEARCH_ACTIVATE_SUGGEST')
218
			)
215 219
			{
220
				$flexsearch_keywords = $this->isFlexSearch($this->search_keywords);
221
				if(count($flexsearch_keywords))
222
				{
223
					$this->flexsearch = true;
224
				}
225
			}
226
			
227
			if($coo_listing_split->number_of_rows > 0 || $this->flexsearch)
228
			{
216 229
				$t_category_data_array = $this->get_category_data_array();
217 230

  
218 231
				$t_category_name = $t_category_data_array['name'];
......
228 241
				$t_navigation_html = $coo_navigation_view->get_html();
229 242

  
230 243
				$t_rows_count = 0;
244
				if($this->flexsearch)
245
				{
246
					$t_rows = $flexsearch_keywords;
247
				}
248
				else
249
				{
231
				$t_query = $coo_listing_split->sql_query;
250
					$t_query  = $coo_listing_split->sql_query;
232
				$t_result = xtc_db_query($t_query);
251
					$t_result = xtc_db_query($t_query);
233

  
252
					$t_rows = array();
234
				while($t_product_array = xtc_db_fetch_array($t_result))
235
				{
253
					while($t_product_array = xtc_db_fetch_array($t_result))
254
					{
255
						$t_rows[] = $t_product_array;
256
					}
257
				}
258

  
259
				foreach($t_rows as $t_product_array)
260
				{
236 261
					$t_rows_count++;
237 262

  
238 263
					// check if product has properties
......
396 421
				$coo_product_listing_view->set_('navigation_html', $t_navigation_html);
397 422
				$coo_product_listing_view->set_('navigation_info_html', $coo_listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS));
398 423
				$coo_product_listing_view->set_('products_array', $t_products_array);
424
				
425
				if($this->flexsearch)
426
				{
427
					$coo_product_listing_view->set_('products_per_page', (int)gm_get_conf('SEARCH_MAX_PRODUCTS_SUGGEST'));
428
				}
429
				else
430
				{
399
				$coo_product_listing_view->set_('products_per_page', (int)MAX_DISPLAY_SEARCH_RESULTS);
431
					$coo_product_listing_view->set_('products_per_page', (int)MAX_DISPLAY_SEARCH_RESULTS);
432
				}
400

  
433
				
401 434
				if(isset($this->search_keywords))
402 435
				{
403 436
					$coo_product_listing_view->set_('search_keywords', $this->search_keywords);
......
2039 2072
	public function setProductListingTemplatePath($path)
2040 2073
	{
2041 2074
		$this->productListingTemplatePath = $path;
2075
	}
2076
	
2077
	
2078
	protected function isFlexSearch($c_needle)
2079
	{
2080
		$products_counter = array();
2081
		
2082
		//$SSML = gm_get_conf('SEARCH_SPLIT_MINIMUM_LENGTH');
2083
		$searchWeightSimiliarText = gm_get_conf('SEARCH_WEIGHT_SIMILAR_TEXT');
2084
		$searchWeightMetaphone    = gm_get_conf('SEARCH_WEIGHT_METAPHONE');
2085
		$searchWeightSoundex      = gm_get_conf('SEARCH_WEIGHT_SOUNDEX');
2086
		$searchWeightLevenshtein  = gm_get_conf('SEARCH_WEIGHT_LEVENSHTEIN');
2087
		// alle Produktnamen holen
2088
		$sql           = "SELECT p.products_id, pd.gm_search_keywords, pd.products_name
2089
				FROM " . TABLE_PRODUCTS . " AS p LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " AS pd ON (p.products_id = pd.products_id)
2090
				WHERE p.products_status = '1'
2091
				AND pd.language_id = '" . (int)$_SESSION['languages_id'] . "'";
2092
		$product_query = xtc_db_query($sql);
2093
		$max_count     = 0;
2094
		//$mysplitkeys = explode(' ', $c_needle);
2095
		$mysplitkeys = str_replace(" ", "", $c_needle);
2096
		while($product_array = xtc_db_fetch_array($product_query))
2097
		{
2098
			
2099
			$searchArray['products_id']['count'] = 0;
2100
			
2101
			$value   = $mysplitkeys;
2102
			$valuens = $product_array['gm_search_keywords'];
2103
			if(strlen($valuens) > $SSML && $valuens != '')
2104
			{
2105
				if(strtolower($valuens) == strtolower($value))
2106
				{
2107
					$searchArray['products_id']['count'] += 1;
2108
					$proderg['treffer'][$product_array['products_id']] = $searchArray['products_id']['count'];
2109
					if($proderg['ergebnis'][$product_array['products_id']] != '')
2110
					{
2111
						$proderg['ergebnis'][$product_array['products_id']] += 100;
2112
					}
2113
					else
2114
					{
2115
						$proderg['ergebnis'][$product_array['products_id']] = 100;
2116
					}
2117
					$proderg['products_id'][$product_array['products_id']] = $product_array['products_id'];
2118
				}
2119
				else
2120
				{
2121
					$sim      = 0;
2122
					$simcount = 0;
2123
					if($searchWeightSimiliarText != 0)
2124
					{
2125
						similar_text(strtolower($value), strtolower($valuens), $sim1);
2126
						if($sim1 > $searchWeightSimiliarText)
2127
						{ //$SWST
2128
							$sim      = $sim1;
2129
							$simcount = $simcount + 1;
2130
						}
2131
					}
2132
					if($searchWeightMetaphone != 0)
2133
					{
2134
						similar_text(metaphone(strtolower($valuens)), metaphone(strtolower($value)), $sim2);
2135
						if($sim2 > $searchWeightMetaphone)
2136
						{
2137
							$sim      = $sim + $sim2;
2138
							$simcount = $simcount + 1;
2139
						}
2140
					}
2141
					if($searchWeightSoundex != 0)
2142
					{
2143
						similar_text(soundex(strtolower($valuens)), soundex(strtolower($value)), $sim3);
2144
						if($sim3 > $searchWeightSoundex)
2145
						{
2146
							if($searchWeightSimiliarText != 0)
2147
							{
2148
								if($sim1 < $sim3)
2149
								{
2150
									$sim3 = $sim1;
2151
								}
2152
							}
2153
							$sim      = $sim + $sim3;
2154
							$simcount = $simcount + 1;
2155
						}
2156
					}
2157
					if($searchWeightLevenshtein != 0)
2158
					{
2159
						$sim7 = strlen($valuens) * strlen($value) / levenshtein(strtolower($value),
2160
						                                                        strtolower($valuens));
2161
						if($sim7 > $searchWeightLevenshtein)
2162
						{
2163
							$sim      = $sim + $sim7;
2164
							$simcount = $simcount + 1;
2165
						}
2166
					}
2167
					unset($ergebnis);
2168
					if($simcount > 0)
2169
					{
2170
						$ergebnis = $sim / $simcount;
2171
					}
2172
					
2173
					if(isset($ergebnis) && $ergebnis > 50)
2174
					{
2175
						$searchArray['products_id']['count'] = $searchArray['products_id']['count'] + $simcount;
2176
						
2177
						$proderg['treffer'][$product_array['products_id']] = $searchArray['products_id']['count'];
2178
						if($proderg['ergebnis'][$product_array['products_id']] != '')
2179
						{
2180
							$proderg['ergebnis'][$product_array['products_id']] = $proderg['ergebnis'][$product_array['products_id']]
2181
							                                                      + $ergebnis;
2182
						}
2183
						else
2184
						{
2185
							$proderg['ergebnis'][$product_array['products_id']] = $ergebnis;
2186
						}
2187
						$proderg['products_id'][$product_array['products_id']] = $product_array['products_id'];
2188
					}
2189
				}
2190
			}
2191
		}
2192
		if($proderg['treffer'] != '')
2193
		{
2194
			array_multisort($proderg['treffer'], SORT_NUMERIC, SORT_DESC, $proderg['ergebnis'], SORT_NUMERIC, SORT_DESC,
2195
			                $proderg['products_id'], SORT_NUMERIC, SORT_ASC);
2196
			
2197
			for($index = 0; $index < 150; $index++)
2198
			{
2199
				if(empty($proderg['products_id'][$index]) === false)
2200
				{
2201
					$topten['products_id'][$index] = $proderg['products_id'][$index];
2202
					$topten['treffer'][$index]     = $proderg['treffer'][$index];
2203
					$topten['ergebnis'][$index]    = $proderg['ergebnis'][$index];
2204
				}
2205
			}
2206
			
2207
			array_multisort($topten['ergebnis'], SORT_NUMERIC, SORT_DESC, $topten['treffer'], SORT_NUMERIC, SORT_DESC,
2208
			                $topten['products_id'], SORT_NUMERIC, SORT_ASC);
2209
			$counter = sizeof($module_content);
2210
			while($topten['products_id'][$counter] && $counter < gm_get_conf('SEARCH_MAX_PRODUCTS_SUGGEST'))
2211
			{
2212
				
2213
				$products_count_query       = xtc_db_query("SELECT p.*, pd.products_name FROM " . TABLE_PRODUCTS
2214
				                                           . " AS p LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " AS pd ON (p.products_id = pd.products_id)
2215
                                                WHERE p.products_status = '1'
2216
				                                        AND pd.language_id = '" . (int)$_SESSION['languages_id'] . "'"
2217
				                                           . $fsk_lock . $group_check . " 
2218
                                                AND p.products_id = " . (int)$topten['products_id'][$counter] . "  ");
2219
				$products_counter[$counter] = xtc_db_fetch_array($products_count_query);
2220
				
2221
				$counter++;
2222
			}
2223
		}
2224
		
2225
		return $products_counter;
2042 2226
	}
2043 2227
}
    (1-1/1)