getSelectionListNonChosen () or $value == '0') { if ($value == "---" or $value == '0') { // Gabis Version return false; } else { return $field . ":\"" . $value . "\""; } break; // fields with that come as a pair and provide a range for the value case 'latitudeFrom' : // TODO this has to go to form validation!!! return SOLRQueryManager::handleCoordinates ( $filters ); break; case 'latitudeTo' : // TODO this has to go to form validation!!! return SOLRQueryManager::handleCoordinates ( $filters ); break; case 'longitudeFrom' : // TODO this has to go to form validation!!! return SOLRQueryManager::handleCoordinates ( $filters ); break; case 'longitudeTo' : // TODO this has to go to form validation!!! return SOLRQueryManager::handleCoordinates ( $filters ); break; case 'collectionYearFrom' : // TODO this has to go to form validation!!! return SOLRQueryManager::handleYear ( $filters ); break; // collection year case 'collectionYearTo' : // TODO this has to go to form validation!!! return SOLRQueryManager::handleYear ( $filters ); break; default : // this should never happen return $field . ":" . $value; break; } } // return $query[$field]; } static function handleCoordinates($filters) { $latf = NULL; $latt = NULL; $longf = NULL; $longt = NULL; if (isset ( $filters ['latitudeTo'] )) $latt = str_replace ( ",", ".", $filters ['latitudeTo'] ); if (isset ( $filters ['latitudeFrom'] )) $latf = str_replace ( ",", ".", $filters ['latitudeFrom'] ); if (isset ( $filters ['longitudeFrom'] )) $longf = str_replace ( ",", ".", $filters ['longitudeFrom'] ); if (isset ( $filters ['longitudeTo'] )) $longt = str_replace ( ",", ".", $filters ['longitudeTo'] ); if ($latf == NULL && $latt == NULL) { $latf = - 90; $latt = 90; } elseif ($latf == NULL && $latt != NULL) { $latf = $latt - 0.10; $latf = - 90; } elseif ($latf != NULL && $latt == NULL) { $latt = $latf + 0.10; $latt = 90; } if ($longf == NULL && $longt == NULL) { $longf = - 180; $longt = 180; } elseif ($longf == NULL && $longt != NULL) { $longf = $longt - 0.10; $longf = - 180; } elseif ($longf != NULL && $longt == NULL) { $longt = $longf + 0.10; $longt = 180; } return "coordinates:[" . $latf . "," . $longf . " TO " . $latt . "," . $longt . "]"; } static function handleYear($filters) { $yearf = 0; $yeart = date ( 'Y' ); if (isset ( $filters ['collectionYearFrom'] )) $yearf = str_replace ( ",", ".", $filters ['collectionYearFrom'] ); if (isset ( $filters ['collectionYearTo'] )) $yeart = str_replace ( ",", ".", $filters ['collectionYearTo'] ); return "gatheringyear:[" . $yearf . " TO " . $yeart . "]"; } public static $client; /** * this fun creates an index query for the search request * * @param unknown $model * @param unknown $selectionLists * @param number $pageSize * @return SolrQuery - if any value in the form was set, else return false */ public static function createSearchQuery($config) { // create a client instance SOLRQueryManager::$client = new Solarium\Client ( $config ); // set the adapter to http SOLRQueryManager::$client->setAdapter ( 'Solarium\Core\Client\Adapter\Http' ); SOLRQueryManager::$client->getPlugin ( 'postbigrequest' ); // get a select query instance $query = SOLRQueryManager::$client->createSelect (); return $query; } public static function fillAndExecuteQuery($query, $queryString, $fq, $filters, $details) { Yii::info ( "fillAndExecuteQuery " . $queryString . " and fq: " . $fq ); // foreach ( $filters as $k => $v ) // Yii::info ( "fillAndExecuteQuery request param " . $k . ", " . $v ); $query->setQuery ( $queryString ); // Note: SOLR starts counting with row 0, page 2 needs to start with row 50 not 51! if (isset ( $_GET ['page'] )) { $query->setStart ( Yii::$app->params ['listPerPage'] * ($_GET ['page'] - 1) ); } else { $query->setStart ( 0 ); } $query->setRows ( Yii::$app->params ['maxLines'] ); $filterq = [ ]; if (isset ( $filters )) { if (sizeof ( $filters ) == 0) $query->createFilterQuery ( 'myfilter' )->setQuery ( $fq ); else foreach ( $filters as $key => $value ) { // Yii::info ( "hop " . $key . "---" . $value ); $value = str_replace ( " ", "\ ", $value ); $value = str_replace ( "(", "\(", $value ); $value = str_replace ( ")", "\)", $value ); $value = str_replace ( ":", "\:", $value ); $filterq [] = SOLRQueryManager::getPartialQuery ( $key, $value, $filters, $details ); Yii::info ( "filterquery " . implode(" GLUE ",$filterq )); // } } } if (isset ( $filterq )) { if (is_array ( $fq )) { $query->createFilterQuery ( 'myfilter_' )->setQuery ( $fq [0] . implode ( " AND ", $filterq ) ); if (sizeof ( $fq ) > 1) { for($i = 1; $i < sizeof ( $fq ); $i ++) $query->createFilterQuery ( 'myfilter' . $i . '_' )->setQuery ( $fq [$i] ); } } else $query->createFilterQuery ( 'myfilter_' )->setQuery ( $fq . implode ( " AND ", $filterq ) ); } $debug = $query->getDebug (); Yii::info ( 'Go query '); // try { $resultset = SOLRQueryManager::$client->select ( $query ); $debugResult = $resultset->getDebug (); Yii::info ( 'Querystring: ' . $debugResult->getQueryString () ); Yii::info ( 'Parsed query: ' . $debugResult->getParsedQuery () ); Yii::info ( 'Query parser: ' . $debugResult->getQueryParser ()); Yii::info ( 'Other query: ' . $debugResult->getOtherQuery () ); // } catch ( Solarium\Exception\UnexpectedValueException $e ) { // $resultset = SOLRQueryManager::$client->select ( $query ); // } return $resultset; } public static function browseQuery($query, $queryString, $fqs, $page, $facetNames) { Yii::info ( "browseQuery " . $queryString ); $query->setQuery ( $queryString ); // Note: SOLR starts counting with row 0, page 2 needs to start with row 50 not 51! if ($page) { $query->setStart ( $page - 1 )->setRows ( Yii::$app->params ['listPerPage'] ); } else { $query->setStart ( 0 )->setRows ( Yii::$app->params ['listPerPage'] ); } $facetSet = $query->getFacetSet (); $facetSet->setLimit ( - 1 ); $facetSet->setMinCount ( 1 ); $facetSet->setSort ( "false" ); $filtering = $fqs; $i = 0; if (sizeof ( $fqs ) > 0) { foreach ( $fqs as $fq ) { $query->createFilterQuery ( 'myfilter' . $i )->setQuery ( $fq ); foreach ( $facetNames as $fname ) if (sizeof ( explode ( $fname, $fq, - 1 ) ) > 0) { $facetSet->createFacetQuery ( $fname . $i )->setQuery ( $filtering [$i] ); } $i ++; } } else { $fq = "*:*"; $query->createFilterQuery ( 'myfilter' )->setQuery ( $fq ); } // create a facet field instance and set options foreach ( $facetNames as $fname ) $facetSet->createFacetField ( $fname )->setField ( $fname ); $resultset = SOLRQueryManager::$client->select ( $query ); return $resultset; } public static function apiQuery($query, $queryString, $fqs, $facetNames, $outputfields) { Yii::info ( "apiQuery " . $queryString . " " . implode ( " -- ", $facetNames ) ); $query->setQuery ( $queryString ); $query->setStart ( 0 ); $query->setFields ( [ $outputfields ] ); $facetSet = $query->getFacetSet (); $facetSet->setLimit ( - 1 ); $facetSet->setMinCount ( 1 ); $facetSet->setSort ( "false" ); $filtering = $fqs; // MARHCE PAS // foreach ( $facetNames as $fname ) // $facetSet->createFacetField ( $fname )->setField ( $fname ); $query->createFilterQuery ( 'myfilter' )->setQuery ( $fqs ); // create a facet field instance and set options foreach ( $facetNames as $fname ) $facetSet->createFacetField ( $fname )->setField ( $fname ); $resultset = SOLRQueryManager::$client->select ( $query ); return $resultset; } public static function treeQuery($query, $queryString, $fname) { // Yii::info ( "treeQuery " . $queryString ); $query->setQuery ( $queryString ); $query->setStart ( 0 )->setRows ( Yii::$app->params ['listPerPage'] ); $facetSet = $query->getFacetSet (); $facetSet->setLimit ( - 1 ); $facetSet->setMinCount ( 1 ); $facetSet->setSort ( "false" ); $fq = "*:*"; $query->createFilterQuery ( 'myfilter' )->setQuery ( $fq ); // create a facet field instance and set options $facetSet->createFacetField ( $fname )->setField ( $fname ); $resultset = SOLRQueryManager::$client->select ( $query ); return $resultset; } public static function loanQuery($query, $queryString, $fqs) { $query->setQuery ( $queryString ); // print ($queryString); // Note: SOLR starts counting with row 0, page 2 needs to start with row 50 not 51! if (isset ( $_GET ['page'] )) { $query->setStart ( Yii::$app->params ['listPerPage'] * ($_GET ['page'] - 1) ); } else { $query->setStart ( 0 ); } $query->setRows ( Yii::$app->params ['maxLines'] ); // generate query string: $string = 'tripleidstoreid:(' . implode ( $fqs, ' OR ' ) . ')'; $query->createFilterQuery ( 'filter1' )->setQuery ( 'tripleidstoreid:(' . implode ( $fqs, ' OR ' ) . ')' ); // anf\FChrungszeichen! // $debug = $query->getDebug (); $resultset = SOLRQueryManager::$client->select ( $query ); // $debugResult = $resultset->getDebug (); // Yii::info ( 'Querystring: ' . $debugResult->getParsedQuery () ); // Yii::info ( 'NumFound: ' . $resultset->getNumFound () ); return $resultset; } /** * * @param SolrQuery $criteria * @return SolrObject */ public static function getConfigDetails() { $config = array ( 'endpoint' => array ( 'bgbm-web01' => array ( 'host' => Yii::$app->params ['solrhost'], 'port' => 8080, 'path' => Yii::$app->params ['solrdetails'] ) ) ); return $config; } public static function getConfigSearch() { $config = array ( 'endpoint' => array ( 'bgbm-web01' => array ( 'host' => Yii::$app->params ['solrhost'], 'port' => 8080, 'path' => Yii::$app->params ['solrsearch'] ) ) ); return $config; } public static function getConfigPreview() { $config = array ( 'endpoint' => array ( 'bgbm-web01' => array ( 'host' => Yii::$app->params ['solrhost'], 'port' => 8080, 'path' => Yii::$app->params ['solrpreview'] ) ) ); return $config; } public static function getConfigStats() { $config = array ( 'endpoint' => array ( 'bgbm-web01' => array ( 'host' => Yii::$app->params ['solrhost'], 'port' => 8080, 'path' => Yii::$app->params ['solrstats'] ) ) ); return $config; } public static function getConfigBackbone() { $config = array ( 'endpoint' => array ( 'bgbm-web01' => array ( 'host' => Yii::$app->params ['solrhost'], 'port' => 8080, 'path' => '/solr/backbone' ) ) ); return $config; } public static function getConfigColTree() { $config = array ( 'endpoint' => array ( 'bgbm-web01' => array ( 'host' => Yii::$app->params ['solrhost'], 'port' => 8080, 'path' => '/solr/colTree' ) ) ); return $config; } public static function getConfigWebsites() { $config = array ( 'endpoint' => array ( 'bgbm-web01' => array ( 'host' => Yii::$app->params ['solrhost'], 'port' => 8080, 'path' => Yii::$app->params ['solrwebsites'] ) ) ); return $config; } } ?>