[Mapbender-commits] r10040 - in trunk/mapbender/http: classes php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Jan 28 08:39:01 PST 2019
Author: armin11
Date: 2019-01-28 08:39:01 -0800 (Mon, 28 Jan 2019)
New Revision: 10040
Modified:
trunk/mapbender/http/classes/class_cswClient.php
trunk/mapbender/http/php/mod_callCswMetadata.php
Log:
More options for external csw search via json api
Modified: trunk/mapbender/http/classes/class_cswClient.php
===================================================================
--- trunk/mapbender/http/classes/class_cswClient.php 2019-01-23 12:47:43 UTC (rev 10039)
+++ trunk/mapbender/http/classes/class_cswClient.php 2019-01-28 16:39:01 UTC (rev 10040)
@@ -164,10 +164,21 @@
if ($additionalFilter !== false) {
$postRequest .= '<ogc:And>';
}
- $postRequest .= '<ogc:PropertyIsEqualTo>';
- $postRequest .= '<ogc:PropertyName>Type</ogc:PropertyName>';
- $postRequest .= '<ogc:Literal>'.$recordtype.'</ogc:Literal>';
- $postRequest .= '</ogc:PropertyIsEqualTo>';
+ if ($recordtype == 'spatialData') {
+ $postRequest .= '<ogc:Or>';
+ foreach (array('dataset','series','tile') as $spatiaDataRecordType) {
+ $postRequest .= '<ogc:PropertyIsEqualTo>';
+ $postRequest .= '<ogc:PropertyName>Type</ogc:PropertyName>';
+ $postRequest .= '<ogc:Literal>'.$spatiaDataRecordType.'</ogc:Literal>';
+ $postRequest .= '</ogc:PropertyIsEqualTo>';
+ }
+ $postRequest .= '</ogc:Or>';
+ } else {
+ $postRequest .= '<ogc:PropertyIsEqualTo>';
+ $postRequest .= '<ogc:PropertyName>Type</ogc:PropertyName>';
+ $postRequest .= '<ogc:Literal>'.$recordtype.'</ogc:Literal>';
+ $postRequest .= '</ogc:PropertyIsEqualTo>';
+ }
if ($additionalFilter !== false) {
$postRequest .= $additionalFilter;
}
@@ -209,10 +220,21 @@
if ($additionalFilter !== false) {
$postRequest .= '<ogc:And>';
}
- $postRequest .= '<ogc:PropertyIsEqualTo>';
- $postRequest .= ' <ogc:PropertyName>Type</ogc:PropertyName>';
- $postRequest .= '<ogc:Literal>'.$recordtype.'</ogc:Literal>';
- $postRequest .= '</ogc:PropertyIsEqualTo>';
+ if ($recordtype == 'spatialData') {
+ $postRequest .= '<ogc:Or>';
+ foreach (array('dataset','series','tile') as $spatiaDataRecordType) {
+ $postRequest .= '<ogc:PropertyIsEqualTo>';
+ $postRequest .= '<ogc:PropertyName>Type</ogc:PropertyName>';
+ $postRequest .= '<ogc:Literal>'.$spatiaDataRecordType.'</ogc:Literal>';
+ $postRequest .= '</ogc:PropertyIsEqualTo>';
+ }
+ $postRequest .= '</ogc:Or>';
+ } else {
+ $postRequest .= '<ogc:PropertyIsEqualTo>';
+ $postRequest .= '<ogc:PropertyName>Type</ogc:PropertyName>';
+ $postRequest .= '<ogc:Literal>'.$recordtype.'</ogc:Literal>';
+ $postRequest .= '</ogc:PropertyIsEqualTo>';
+ }
if ($additionalFilter !== false) {
$postRequest .= $additionalFilter;
}
@@ -237,6 +259,7 @@
} else {
$e = new mb_exception("classes/class_cswClient.php: Operation getrecordspaging needs more parameters!");
}
+$e = new mb_exception("postrequest: ".$postRequest);
break;
default:
break;
Modified: trunk/mapbender/http/php/mod_callCswMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_callCswMetadata.php 2019-01-23 12:47:43 UTC (rev 10039)
+++ trunk/mapbender/http/php/mod_callCswMetadata.php 2019-01-28 16:39:01 UTC (rev 10040)
@@ -27,9 +27,11 @@
$searchTypeBbox = "intersects"; //outside / inside
$languageCode = "de";
$outputFormat = 'json';
-//$searchResources = "dataset,service,application,other";
-//$searchResources = "dataset";
-$searchPages = "1";
+$dummySearchResources = "dataset,series,tile,service,application,nonGeographicDataset";
+//$dummySearchPages = "1,1,1,1,1,1";
+
+$searchResources = $dummySearchResources;
+$searchPages = $dummySearchPages;
// $resourceIds = NULL; //resourceIds is used to get a comma separated list with ids of the resources - layer - featuretypes - wmc
//it will be used to filter some results
$resultTarget = "web";
@@ -60,6 +62,7 @@
//list of possibly hierarchyLevels - iso 19115 MD_ScopeCode
$MD_ScopeCode = array("attribute","attributeType","collectionHardware","collectionSession","dataset","series","nonGeographicDataset","dimensionGroup","feature","featureType","propertyType","fieldSession","software","service","model","tile");
$MD_ScopeCode[] = "application";
+$MD_ScopeCode[] = "spatialData";
#
//control if some request variables are not set and set them explicit to NULL
$checkForNullRequests = array("registratingDepartments","isoCategories","inspireThemes","customCategories","regTimeBegin","regTimeEnd","timeBegin","timeEnd","searchBbox","searchTypeBbox","searchResources","orderBy","hostName","resourceIds","restrictToOpenData");
@@ -358,7 +361,7 @@
$testMatch = $_REQUEST["searchResources"];
#$pattern = '/^(19|20)[0-9]{2}[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$/';
$countSR = count(explode(',',$testMatch));
- if (!($countSR >= 1 && $countSR <= 5)){
+ if (!($countSR >= 1 && $countSR <= 6)){
//echo 'searchResources: <b>'.$testMatch.'</b> count of requested resources out of sync.<br/>';
echo 'Parameter <b>searchResources</b> count of requested resource types is more than 5.<br/>';
die();
@@ -446,13 +449,13 @@
if ($resultTarget == 'file' or $resultTarget == 'webclient') {
if (!isset($searchResources) OR ($searchResources == "")) {
- $searchResources = "dataset,service,application,other";
+ $searchResources = $dummySearchResources;
$resolveCoupledResources = true;
- $searchPages = "1,1,1,1";
+ $searchPages = $dummySearchPages;
}
}
-if (!isset($searchPages) OR ($searchPages == "")) {
+if (!isset($searchPages) OR ($searchPages == "") or count(explode(",",$searchPages)) !== count(explode(",",$searchResources))) {
for($i=0;$i<count(explode(",",$searchResources));$i++) {
$searchPages[$i] = 1;
}
@@ -473,17 +476,37 @@
//begin main program
//************************************************************************************
$queryString = $searchText;
-$queryStringParts = explode(" ",$queryString);
-$queryText = $queryStringParts[0];
-if ($queryText == '*') {
- $queryText = '';
+$searchTextArray = explode(",",$queryString);
+
+$queryText = $queryStringArray[0];
+
+//if ($queryText == '*') {
+// $queryText = '';
+//} else {
+
+if (count($searchTextArray) > 1) {
+ $fullTextFilter = "<ogc:And>";
+} else {
+ $fullTextFilter = "";
}
-//TODO query
-$fullTextFilter = '<ogc:PropertyIsLike wildCard="%" singleChar="_" escapeChar="">';
-$fullTextFilter .= '<ogc:PropertyName>AnyText</ogc:PropertyName>';
-$fullTextFilter .= '<ogc:Literal>%'.$queryText.'%</ogc:Literal>';
-$fullTextFilter .= '</ogc:PropertyIsLike>';
+foreach($searchTextArray as $queryString) {
+ $fullTextFilter .= '<ogc:PropertyIsLike wildCard="%" singleChar="_" escapeChar="">';
+ $fullTextFilter .= '<ogc:PropertyName>AnyText</ogc:PropertyName>';
+ $fullTextFilter .= '<ogc:Literal>%'.$queryString.'%</ogc:Literal>';
+ $fullTextFilter .= '</ogc:PropertyIsLike>';
+}
+if (count($searchTextArray) > 1) {
+ $fullTextFilter .= "</ogc:And>";
+}
+/*
+ $fullTextFilter .= '<ogc:PropertyIsLike wildCard="%" singleChar="_" escapeChar="">';
+ $fullTextFilter .= '<ogc:PropertyName>AnyText</ogc:PropertyName>';
+ $fullTextFilter .= '<ogc:Literal>%'.implode('%', $searchTextArray).'%</ogc:Literal>';
+ $fullTextFilter .= '</ogc:PropertyIsLike>';*/
+
+$e = new mb_exception("fulltextfilter: ".$fullTextFilter);
+//}
$existsSpatialFilter = false;
$searchBboxArray = explode(",", $searchBbox);
if ($searchBbox !== NULL) {
@@ -521,8 +544,8 @@
}
}
//combine filter
-if ($existsSpatialFilter == true){
- $additionalFilter = "<And>".$fullTextFilter.$spatialFilter."</And>";
+if ($existsSpatialFilter == true && $queryText !== ''){
+ $additionalFilter = "<ogc:And>".$fullTextFilter.$spatialFilter."</ogc:And>";
} else {
$additionalFilter = $fullTextFilter;
}
@@ -566,11 +589,187 @@
//log start time of distributed metadatdata search via csw interface
$searchCswStartTime = microtime_float();
+
+$resultObject = new stdClass;
+//define object for dynamic filtering - actually only for searchResources
+
+$queryJSON = new stdClass;
+$queryJSON->searchFilter = (object) array();
+$queryJSON->searchFilter->origURL = $searchURL;
+
+
+//define where to become the information from - this is relevant for the information which must be pulled out of the database
+$classificationElements = array();
+$classificationElements[0]['name'] = 'searchText';
+$classificationElements[1]['name'] = 'searchBbox';
+$classificationElements[2]['name'] = 'searchResources';
+
+$classificationElements[0]['source'] = '';
+$classificationElements[1]['source'] = '';
+$classificationElements[2]['source'] = '';
+
+$classificationElements[0]['list'] = true;
+$classificationElements[1]['list'] = false;
+$classificationElements[2]['list'] = true;
+
+switch($languageCode){
+ case 'de':
+ $classificationElements[0]['name2show'] = 'Suchbegriff(e):';
+ $classificationElements[1]['name2show'] = 'Räumliche Einschränkung:';
+ $classificationElements[2]['name2show'] = 'Art der Ressource:';
+
+ $resourceCategories['dataset'] = 'Datensätze';
+ $resourceCategories['spatialData'] = 'Geodaten';
+ $resourceCategories['series'] = 'Datensatzserien';
+ $resourceCategories['tile'] = 'Datensatzteile';
+ $resourceCategories['application'] = 'Anwendungen';
+ $resourceCategories['service'] = 'Dienste';
+ $resourceCategories['nonGeographicDataset'] = 'Daten ohne Raumbezug';
+
+ $orderByTitle['header'] = 'Sortierung nach:';
+ $orderByTitle['id'] = 'Identifizierungsnummer';
+ $orderByTitle['title'] = 'Alphabetisch';
+ $orderByTitle['rank'] = 'Nachfrage';
+ $orderByTitle['date'] = 'Letzte Änderung';
+
+ $maxResultsTitle['header'] = 'Treffer pro Seite:';
+
+
+ break;
+ case 'en':
+ $classificationElements[0]['name2show'] = 'Search Term(s):';
+ $classificationElements[1]['name2show'] = 'Spatial Filter:';
+ $classificationElements[2]['name2show'] = 'Kind of resource:';
+
+ $resourceCategories['dataset'] = 'Datasets';
+ $resourceCategories['spatialData'] = 'Spatial data';
+ $resourceCategories['series'] = 'Datasetseries';
+ $resourceCategories['tile'] = 'Datasetstiles';
+ $resourceCategories['application'] = 'Applications';
+ $resourceCategories['service'] = 'Services';
+ $resourceCategories['nonGeographicDataset'] = 'Data without spatial dimension';
+
+ $orderByTitle['header'] = 'Sort by:';
+ $orderByTitle['id'] = 'identification number';
+ $orderByTitle['title'] = 'alphabetically';
+ $orderByTitle['rank'] = 'demand';
+ $orderByTitle['date'] = 'last change';
+
+ $maxResultsTitle['header'] = 'Results per page:';
+
+ break;
+ case 'fr':
+ $classificationElements[0]['name2show'] = 'Mots clés:';
+ $classificationElements[1]['name2show'] = 'Requête spatiale:';
+ $classificationElements[2]['name2show'] = 'Art der Ressource:';
+
+ $resourceCategories['dataset'] = 'Datasets';
+ $resourceCategories['spatialData'] = 'Spatial data';
+ $resourceCategories['series'] = 'Datasetseries';
+ $resourceCategories['tile'] = 'Datasetstiles';
+ $resourceCategories['application'] = 'Applications';
+ $resourceCategories['service'] = 'Services';
+ $resourceCategories['nonGeographicDataset'] = 'Data without spatial dimension';
+
+ $orderByTitle['header'] = 'classé selon:';
+ $orderByTitle['id'] = 'numéro d\'identification';
+ $orderByTitle['title'] = 'par ordre alphabétique';
+ $orderByTitle['rank'] = 'vue';
+ $orderByTitle['date'] = 'mise à jour';
+
+ $maxResultsTitle['header'] = 'Résultat par page:';
+
+ break;
+ default:
+ $classificationElements[0]['name2show'] = 'Suchbegriff(e):';
+ $classificationElements[1]['name2show'] = 'Räumliche Einschränkung:';
+ $classificationElements[2]['name2show'] = 'Art der Ressource:';
+
+ $resourceCategories['dataset'] = 'Datasets';
+ $resourceCategories['spatialData'] = 'Spatial data';
+ $resourceCategories['series'] = 'Datasetseries';
+ $resourceCategories['tile'] = 'Datasetstiles';
+ $resourceCategories['application'] = 'Applications';
+ $resourceCategories['service'] = 'Services';
+ $resourceCategories['nonGeographicDataset'] = 'Data without spatial dimension';
+
+ $orderByTitle['header'] = 'Sortierung nach:';
+ $orderByTitle['id'] = 'ID';
+ $orderByTitle['title'] = 'Titel';
+ $orderByTitle['rank'] = 'Relevanz';
+ $orderByTitle['date'] = 'Letzte Änderung';
+
+ $maxResultsTitle['header'] = 'Results per page:';
+
+}
+
+//generate search filter file - if more categories are defined give
+//echo "<br> number of filter elements: ".count($classificationElements)."<br>";
+for($i=0; $i < count($classificationElements); $i++){
+ //echo "<br> filter for element: ".$classificationElements[$i]['name']."<br>";
+ //echo "<br> variable for element: ". (string)${$classificationElements[$i]['name']}."<br>";
+ if (isset(${$classificationElements[$i]['name']}) & ${$classificationElements[$i]['name']} !='' & ${$classificationElements[$i]['name']} != NULL) {
+ //echo "<br> found: ".$classificationElements[$i]['name']."<br>";
+ //pull register information out of database in arrays
+ $queryJSON->searchFilter->{$classificationElements[$i]['name']}->title = $classificationElements[$i]['name2show'];
+ //check if the filter has subfilters - if not delete the whole filter from query
+ if ($classificationElements[$i]['list'] == false) { //the object has no subsets - like bbox or time filters
+ $queryJSON->searchFilter->{$classificationElements[$i]['name']}->delLink = delTotalFromQuery($classificationElements[$i]['name'],$searchURL);
+ $queryJSON->searchFilter->{$classificationElements[$i]['name']}->item = array();
+ if ($classificationElements[$i]['name'] == 'searchBbox') {
+ $sBboxTitle = $searchTypeBbox." ".${$classificationElements[$i]['name']};
+ $queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[0]->title = $sBboxTitle;
+ }
+ else {
+ $queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[0]->title = ${$classificationElements[$i]['name']};
+ }
+ $queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[0]->delLink = delTotalFromQuery($classificationElements[$i]['name'],$searchURL);
+ } else {
+
+
+ //$e = new mb_exception('mod_callMetadata.php: $classificationElements[$i][name]: '.$classificationElements[$i]['name']);
+ //TODO delete all entries of this main category (not for searchText)
+
+ //$queryJSON->searchFilter->{$classificationElements[$i]['name']}->delLink = NULL;
+ $queryJSON->searchFilter->{$classificationElements[$i]['name']}->delLink = delTotalFromQuery($classificationElements[$i]['name'],$searchURL);
+ //$e = new mb_exception('mod_callMetadata.php: dellink: '.$queryJSON->searchFilter->{$classificationElements[$i]['name']}->delLink);
+
+ $queryJSON->searchFilter->{$classificationElements[$i]['name']}->item = array();
+
+ $queryArray = explode(',', ${$classificationElements[$i]['name']});
+
+ //loop for the subcategories
+ for($j=0; $j < count($queryArray); $j++){
+ //$e = new mb_exception('mod_callMetadata.php: queryArrayi: '.$queryArray[$j]);
+
+ if ($classificationElements[$i]['name'] != 'searchResources') {
+ $queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[$j]->title = $queryArray[$j];
+ } else {
+ $queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[$j]->title = $resourceCategories[$queryArray[$j]];
+ }
+
+ //generate links to disable filters on a simple way
+ if (($classificationElements[$i]['name'] === 'searchText' || $classificationElements[$i]['name'] === 'searchResources') & count(explode(',',${$classificationElements[$i]['name']})) === 1) {
+ //$queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[$j]->delLink = NULL;
+ $newSearchLink = delFromQuery($classificationElements[$i]['name'], $searchURL,$queryArray[$j],$queryArray,${$classificationElements[$i]['name']});
+ $newSearchLink = delTotalFromQuery('searchId',$newSearchLink);
+ $queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[$j]->delLink = $newSearchLink;
+ } else {
+ $newSearchLink = delFromQuery($classificationElements[$i]['name'], $searchURL,$queryArray[$j],$queryArray,${$classificationElements[$i]['name']});
+ $newSearchLink = delTotalFromQuery('searchId',$newSearchLink);
+ $queryJSON->searchFilter->{$classificationElements[$i]['name']}->item[$j]->delLink = $newSearchLink;
+ }
+ }
+ }
+ }
+}
+
//get the first page to also count the available records:
$i = 0;
-$resultObject = new stdClass;
foreach ($searchResourcesArray as $searchResource) {
+ //$queryJSON->searchFilter->classes[$i]->title = $resourceCategories[$searchResourcesArray[$i]];
+ //$queryJSON->searchFilter->classes[$i]->name = $searchResourcesArray[$i];
//echo $searchResource;
//for ($i = 0; $i < 1 ; $i++) {
@@ -675,6 +874,8 @@
}
$i++;
}
+//add filter object
+$resultObject->searchFilter = $queryJSON->searchFilter;
echo json_encode($resultObject);
//}
//************************************************************************************
@@ -682,6 +883,8 @@
//************************************************************************************
//function to delete one of the comma separated values from one get request
function delFromQuery($paramName,$queryString,$string,$queryArray,$queryList) {
+ global $dummySearchResources;
+ global $dummySearchPages;
//check if if count searchArray = 1
if (count($queryArray) == 1){
//remove request parameter from url by regexpr or replace
@@ -691,11 +894,12 @@
} else {
$str2exchange = "";
}
- if ($paramName == "searchResources") {
- $str2exchange = "searchResources=dataset,wms,wfs,wmc&";
+ /*if ($paramName == "searchResources") {
+ $str2exchange = "searchResources=".$dummySearchResources."&";
+
} else {
$str2exchange = "";
- }
+ }*/
$queryStringNew = str_replace($str2search, $str2exchange, $queryString);
$queryStringNew = str_replace("&&", "&", $queryStringNew);
} else {
@@ -719,6 +923,8 @@
//function to remove one complete get param out of the query
function delTotalFromQuery($paramName,$queryString) {
+ global $dummySearchResources;
+ global $dummySearchPages;
//echo $paramName ."<br>";
$queryString = "&".$queryString;
if ($paramName == "searchText") {
@@ -726,9 +932,9 @@
} else {
$str2exchange = "";
}
- if ($paramName == "searchResources") {
- $str2exchange = "searchResources=dataset,wms,wfs,wmc&";
- }
+ /*if ($paramName == "searchResources") {
+ $str2exchange = "searchResources=".$dummySearchResources."&";
+ } */
$queryStringNew = preg_replace('/\b'.$paramName.'\=[^&]*&?/',$str2exchange,$queryString); //TODO find empty get params
$queryStringNew = ltrim($queryStringNew,'&');
$queryStringNew = rtrim($queryStringNew,'&');
More information about the Mapbender_commits
mailing list