[Mapbender-commits] r10156 - trunk/mapbender/http/geoportal

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jun 19 06:17:59 PDT 2019


Author: armin11
Date: 2019-06-19 06:17:59 -0700 (Wed, 19 Jun 2019)
New Revision: 10156

Modified:
   trunk/mapbender/http/geoportal/mod_getCatalogueKeywordSuggestion.php
Log:
Fix for suggestion list

Modified: trunk/mapbender/http/geoportal/mod_getCatalogueKeywordSuggestion.php
===================================================================
--- trunk/mapbender/http/geoportal/mod_getCatalogueKeywordSuggestion.php	2019-06-19 09:21:57 UTC (rev 10155)
+++ trunk/mapbender/http/geoportal/mod_getCatalogueKeywordSuggestion.php	2019-06-19 13:17:59 UTC (rev 10156)
@@ -41,19 +41,41 @@
 	}
 }
 //do the sql select
-$sql = "SELECT keyword FROM keyword_search_view WHERE keyword_ts @@ to_tsquery('german', $1) || keyword_upper LIKE $2 ORDER BY keyword LIMIT $3";
+/*$sql = "SELECT keyword FROM keyword_search_view WHERE keyword_ts @@ to_tsquery('german', $1) || keyword_upper LIKE $2 ORDER BY keyword LIMIT $3";
 $t = array('s', 's', 'i');
-$normSearch = str_replace("ä","AE",strtoupper($searchText));
-$v = array($searchText, "%".$normSearch."%", $maxResults);
+//$normSearch = str_replace("ä","AE",strtoupper($searchText));*/
+
+$normSearch = str_replace('ß', 'SS', str_replace('Ü', 'UE', str_replace('Ä', 'AE', strtoupper(str_replace('Ö', 'OE', mb_strtoupper($searchText))))));
+
+$sql = "SELECT keyword FROM keyword_search_view WHERE keyword_upper LIKE $1 ORDER BY keyword LIMIT $2";
+$t = array('s', 'i');
+//$e = new mb_exception($normSearch);
+//$v = array($searchText, $normSearch."%", $maxResults);
+
+$v = array("%".$normSearch."%", $maxResults);
 $resultList = array();
 $res = db_prep_query($sql,$v,$t);
+
 header('Content-type: application/json; charset=utf-8');
 $i = 0;
 while($row = db_fetch_array($res)){
-	$resultList[$i]['keyword'] = $row['keyword'];
-	$resultList[$i]['keywordHigh'] = str_replace($searchText, "<b>".$searchText."</b>", $row['keyword']);
+	$resultList[$i]['keyword'] = trim($row['keyword']);
+	//find pos of searchText in keyword - lowercase
+	$posOfString = strpos(mb_strtolower($row['keyword']), mb_strtolower($searchText));
+
+	$lengthOfSearchtext = count($searchText);
+	$lengthOfKeyword = count($row['keyword']);
+	$resultList[$i]['keywordHigh'] = trim(substr($row['keyword'], 0, $posOfString)."<b>".substr($row['keyword'], $posOfString, $lengthOfSearchtext+1)."</b>".substr($row['keyword'], ($posOfString + $lengthOfSearchtext)));
+	//$resultList[$i]['keywordHigh'] = str_replace($searchText, "<b>".$searchText."</b>", $row['keyword']);
 	$i++;
 }
+//
+$ids = array_column($resultList, 'keyword');
+$ids = array_unique($ids);
+$resultList = array_filter($resultList, function ($key, $value) use ($ids) {
+    return in_array($value, array_keys($ids));
+}, ARRAY_FILTER_USE_BOTH);
+
 $result->results = $i;
 $timeEnd = microtime(1000000);
 $timeDiff = $timeEnd - $timeBegin;



More information about the Mapbender_commits mailing list