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]; // 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 simpleQuery($query, $queryString, $fq) { $query->setQuery ( $queryString ); $query->createFilterQuery ( 'myfilter' )->setQuery ( $fq ); $resultset = SOLRQueryManager::$client->select ( $query ); return $resultset; } 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 ); } if(Yii::$app->user->isGuest && Yii::$app->params ['maxLinesGuest']) $query->setRows ( Yii::$app->params ['maxLinesGuest'] ); else $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 ); if($key != "locality" && $key != "collectors" && $key != "collectornumber" && $key != "sequenceaccessionIdentifier" && $key != "fullScientificName" && $key != "country" && $key != "sea" && $key != "continent" && $key != "ocean" && $key != "geneticlocus") { $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(",",$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 (); try { $resultset = SOLRQueryManager::$client->select ( $query ); } catch ( Solarium\Exception\UnexpectedValueException $e ) { $resultset = SOLRQueryManager::$client->select ( $query ); } // $debugResult = $resultset->getDebug (); // Yii::info ( 'Querystring: ' . $debugResult->getParsedQuery () ); // Yii::info ( 'NumFound: ' . $resultset->getNumFound () ); 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'] ); } $i = 0; if (sizeof ( $fqs ) > 0) { foreach ( $fqs as $fq ) { $query->addFilterQuery($fq); // $query->createFilterQuery ( 'fq' . $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 ( 'fq' )->setQuery ( $fq ); } $facetSet = $query->getFacetSet (); $facetSet->setLimit ( - 1 ); $facetSet->setMinCount ( 1 ); $facetSet->setSort ( "false" ); $filtering = $fqs; // create a facet field instance and set options foreach ( $facetNames as $fname ) { $facetSet->createFacetField ( array('field' => $fname, 'key' => $fname, 'exclude'=>$fname) ); } $request = SOLRQueryManager::$client->createRequest($query); // you can now use the request object for getting an uri (ie. to use in you own code) // or you could modify the request object Yii::info('SOLR Request URI: ' . urldecode($request->getUri())); $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 ( 'scheme' => Yii::$app->params['solrServerScheme'], 'host' => Yii::$app->params ['solrhost'], 'port' => Yii::$app->params['solrServerPort'], 'path' => Yii::$app->params ['solrdetails'] ) ) ); return $config; } public static function getConfigSearch() { $config = array ( 'endpoint' => array ( 'bgbm-web01' => array ( 'scheme' => Yii::$app->params['solrServerScheme'], 'host' => Yii::$app->params ['solrhost'], 'port' => Yii::$app->params['solrServerPort'], 'path' => Yii::$app->params ['solrsearch'] ) ) ); return $config; } public static function getConfigPreview() { $config = array ( 'endpoint' => array ( 'bgbm-web01' => array ( 'scheme' => Yii::$app->params['solrServerScheme'], 'host' => Yii::$app->params ['solrhost'], 'port' => Yii::$app->params['solrServerPort'], 'path' => Yii::$app->params ['solrpreview'] ) ) ); return $config; } public static function getConfigBackbone() { $config = array ( 'endpoint' => array ( 'bgbm-web01' => array ( 'scheme' => Yii::$app->params['solrServerScheme'], 'host' => Yii::$app->params ['solrhost'], 'port' => Yii::$app->params['solrServerPort'], 'path' => '/solr/backbone' ) ) ); return $config; } public static function getConfigColTree() { $config = array ( 'endpoint' => array ( 'bgbm-web01' => array ( 'scheme' => Yii::$app->params['solrColTreeServerScheme'], 'host' => Yii::$app->params ['solrColTreeHost'], 'port' => Yii::$app->params['solrColTreeServerPort'], 'path' => Yii::$app->params['solrColTreePath'] // 'scheme' => Yii::$app->params['solrServerScheme'], // 'host' => Yii::$app->params ['solrhost'], // 'port' => Yii::$app->params['solrServerPort'], // 'path' => '/solr/colTree' ) ) ); return $config; } public static function getConfigWebsites() { $config = array ( 'endpoint' => array ( 'bgbm-web01' => array ( 'scheme' => Yii::$app->params['solrServerScheme'], 'host' => Yii::$app->params ['solrhost'], 'port' => Yii::$app->params['solrServerPort'], 'path' => Yii::$app->params ['solrwebsites'] ) ) ); return $config; } public static function getConfigAlfresco() { $config = array ( 'endpoint' => array ( 'alfresco' => array ( 'scheme' => Yii::$app->params['solrAlfrescoServerScheme'], 'host' => Yii::$app->params ['solrAfrescoHost'], 'path' => Yii::$app->params ['solrAlfresco'], 'port' => Yii::$app->params ['solrAlfrescoPort'], 'username' => Yii::$app->params ['solrAlfrescoUsername'], 'password' => Yii::$app->params ['solrAlfrescoPassword'], ) ) ); return $config; } public function performSearchnew($filters, $model, $primaryObject) { var_dump($filters); } public function performSearch($filters, $model, $primaryObject) { //Yii::info ( "actionperformSearch" ); // we get all the lists for the drop-down lists in the form -- why?? $model->collectDropDownAttributesLists ( $model ); $submitURL = $model->createUrl ( [ 'search/create' ], $filters ); // validate user input if ($model->validate ()) { $config = SOLRQueryManager::getConfigSearch (); $query = SOLRQueryManager::createSearchQuery ( $config ); $fq = ""; $q = [ ]; $filterInstitution = false; $filterVouchercol = false; foreach ( $filters as $key => $value ) { $value = str_replace ( " ", "\ ", $value ); $value = str_replace ( "(", "\(", $value ); $value = str_replace ( ")", "\)", $value ); $value = str_replace ( ":", "\:", $value ); //unklar, was das hier ist if ($key == "institution") { $q [] = SOLRQueryManager::getPartialQuery ( $key, $value, $filters, False ); $filterInstitution = true; } if ($key == "voucherCol") { $q [] = SOLRQueryManager::getPartialQuery ( $key, $value, $filters, False ); $filterVouchercol = true; } } //if (! $filterInstitution && ! $filterVouchercol) $q = [ "*:*".Yii::$app->params['thematicSOLRfilter'] ]; $raw_response = SOLRQueryManager::fillAndExecuteQuery ( $query, implode ( " AND ", $q ), $fq, $filters, False ); if(Yii::$app->params['siteName'] == 'evoboga' && Yii::$app->user->isGuest) { $CustomizedFacets = SOLRQueryManager::CustomizedFacetsListView($query, $config, $q, $fq); } else { $CustomizedFacets = ""; } $backboneaccepted = ""; $backbonefullname = ""; // foreach($raw_response as $backbonedisplay) // { $backboneaccepted = $backbonedisplay->backboneaccepted; // $backbonefullname = $backbonedisplay->backbonefullname; } $q[]="isLowest:1"; $query2 = SOLRQueryManager::createSearchQuery ( $config ); $raw_responseCounts = SOLRQueryManager::fillAndExecuteQuery ( $query2, implode ( " AND ", $q ), $fq, $filters, False ); $tripleidstoreids=[]; foreach($raw_response as $document){ $tripleidstoreids = array_merge($tripleidstoreids, $document->lowestTripleIDs); } $tripleidstoreids=array_unique($tripleidstoreids); $config = SOLRQueryManager::getConfigPreview(); $query = SOLRQueryManager::createSearchQuery ( $config ); //$q = "tripleidstoreid:(".implode(" OR ", $tripleidstoreids).")"; if(sizeof($tripleidstoreids)>0){ $q = "tripleidstoreid:(".implode(" OR ", $tripleidstoreids).")"; } else $q=""; //echo $q; $raw_response = SOLRQueryManager::fillAndExecuteQuery ( $query, $q , $fq, [], False ); $doc = $raw_response->getDocuments (); $numFoundTotal = $raw_responseCounts->getNumFound (); $numFound = $raw_response->getNumFound (); $ids = [ ]; foreach ( $raw_response as $id ) { $ids [] = $id->tripleidstoreid; } // Repeat query because Solr won't permit queries with more OR clauses, didn't find a better solution :( // Executed in batches of 200 $SOLR_QUERY_CONSTANT = 200; $shoppingArray = [ ]; if(! Yii::$app->user->isGuest && Yii::$app->params ['shopping'] = true){ for($i = 0; $i < ceil ( count ( $ids ) / $SOLR_QUERY_CONSTANT ); $i ++) { $config = SOLRQueryManager::getConfigDetails (); $query1 = SOLRQueryManager::createSearchQuery ( $config ); $loanStatus = SOLRQueryManager::loanQuery ( $query1, "*:*", array_slice ( $ids, $i * $SOLR_QUERY_CONSTANT, $SOLR_QUERY_CONSTANT ) ); foreach ( $loanStatus as $l ) { $shoppingArray [$l->tripleidstoreid] = $l; } } } $shopM = new CartForm (); if (Yii::$app->params ['useLogin'] && ! Yii::$app->user->isGuest) { $shoppingCart = sizeof ( DBInterface::getShoppingCart ( Yii::$app->user->identity->id ) ); } else { $shoppingCart = ''; } $multiUnitsM = new MultiunitsForm (); $multiUnitsCart = Yii::$app->session['listView']; if (Yii::$app->params['logUsageStats']) { // Logging Usage Statistics $piwikSiteID = Yii::$app->params['piwikSiteID']; $fullUrl = addslashes(str_replace("www.","" , urldecode(Yii::$app->request->HostName.Yii::$app->request->baseUrl."/".Yii::$app->request->pathInfo."?".Yii::$app->request->queryString))); $queryString = addslashes(urldecode(Yii::$app->request->queryString)); $serverTime = date('Y-m-d h:i:s'); $actionresult = "INSERT INTO log_action_visitor (server_time, url, hash, piwiksiteid, query_terms, hits) VALUES ('$serverTime','$fullUrl', CRC32('$fullUrl'), $piwikSiteID, '$queryString', $numFoundTotal)"; Yii::$app->usageStats->createCommand($actionresult)->execute(); $idaction = Yii::$app->usageStats->getLastInsertID(); foreach ($doc as $actiondetails) { $actionrecords = "INSERT IGNORE INTO log_action_records (unitID, collectionCode, institutionCode, guid, institution) VALUES ('$actiondetails->unitID', '$actiondetails->collectioncode', '$actiondetails->institutioncode', '$actiondetails->guid', '$actiondetails->institution')"; Yii::$app->usageStats->createCommand($actionrecords)->execute(); $recordids = "SELECT idrecord FROM log_action_records WHERE unitID='$actiondetails->unitID' AND collectionCode = '$actiondetails->collectioncode'"; $getRecordIDs = Yii::$app->usageStats->createCommand($recordids)->queryAll(); $idrecord = $getRecordIDs[0]['idrecord']; $actiondetail = "INSERT INTO log_actionrecords_visitor (idaction, idrecord) VALUES ($idaction, $idrecord)"; Yii::$app->usageStats->createCommand($actiondetail)->execute(); } } return array ( "model" => $model, 'response' => $doc, 'backboneaccepted' => $backboneaccepted, 'backbonefullname' => $backbonefullname, 'keyForLink' => $model->key_link, 'recordFilters' => $model->recordFilters, 'item_count' => $numFound, 'item_count_total' => $numFoundTotal, 'selectionLists' => $model->_selectionlists, 'submitURL' => $model->submitURL, 'filters' => $filters, 'shopping' => $shoppingArray, 'shopM' => $shopM, 'shoppingCart' => $shoppingCart, 'multiUnitsCart'=>$multiUnitsCart, 'multiUnitsM'=>$multiUnitsM, 'facetNumbers'=>$CustomizedFacets, 'primaryObject' => $primaryObject ) ; } else { $errors = $model->errors; return array ( "model" => $model, "filters" => $filters, "errors" => $errors ); } } public function CustomizedFacetsListView($query, $config, $q, $fq) { $facetnames = []; $facetnames = ['originalCanonicalName']; $facetnames [] = 'rank'; $facetnames [] = 'institution'; $facetnames [] = 'ipen'; $facetnames [] = 'hasImage'; $raw_responseFacet = SOLRQueryManager::apiQuery ( $query, implode ( " AND ", $q ), $fq, $facetnames, "[]" ); $facetScientificNames = $raw_responseFacet->getFacetSet ()->getFacet ( "originalCanonicalName" ); $content_array = array ( "name" => array (), "namerank" => array (), "nbInstitution" => array (), "nbRecords" => array (), "nbIpen" => array (), 'nbImage' => array () ); $countScientificName = count($facetScientificNames); //for($i = 0, $count = count($facetScientificNames); $i < 100; $i++) { foreach($facetScientificNames as $name => $count) { $configFacet = SOLRQueryManager::getConfigSearch (); $queryFacet = SOLRQueryManager::createSearchQuery ( $configFacet ); $fqFacet = "*:*"; $qFacet = 'originalCanonicalName:"'.$name.'" AND accessionStatus:C'; $raw_responseFacet2 = SOLRQueryManager::apiQuery ( $queryFacet, $qFacet, $fqFacet, $facetnames, "[]" ); $rankValue = ""; $nb1 = ""; $nb2 = ""; $nb3 = ""; if(null != ($raw_responseFacet2->getFacetSet ()->getFacet ( "institution" ))) { $f1 = $raw_responseFacet2->getFacetSet ()->getFacet ( "institution" ); $nb1 = 0; foreach ( $f1 as $ff ) { $nb1 += 1; } $facetNumbers ['nbInstitution'] = $nb1; } else {$nb1 = ""; } $facetNumbers ['nbRecords'] = $count; $facetNumbers ['name'] = $name; //var_dump($raw_responseFacet2->getFacetSet ()->getFacet ( "hasImage" ))."
"; if(($raw_responseFacet2->getFacetSet ()->getFacet ( "hasImage" )) != null) { $f3 = $raw_responseFacet2->getFacetSet ()->getFacet ( "hasImage" ); $test[] = $f3; if(array_key_exists('1', $test)) { $nb3 = "Yes"; } else {$nb3 = "No"; } $facetNumbers ['nbImage'] = $nb3; } if(null != ($raw_responseFacet2->getFacetSet ()->getFacet ( "ipen" ))) { $f2 = $raw_responseFacet2->getFacetSet ()->getFacet ( "ipen" ); $nb2 = 0; foreach ( $f2 as $ff ) { $nb2 += 1; } $facetNumbers ['nbIpen'] = $nb2; } else { $nb2 = ""; } if(null !== ($raw_responseFacet2->getFacetSet ()->getFacet ( "rank" ))) { $f3 = $raw_responseFacet2->getFacetSet ()->getFacet ( "rank" ); foreach ($f3 as $keyRank => $countrank) { $rankValue = $keyRank; $facetNumbers ['rank'] = $rankValue; } } else { $rankValue = ""; } array_push($content_array['name'],$name); array_push($content_array['namerank'],$rankValue); array_push($content_array['nbInstitution'],$nb1); array_push($content_array['nbRecords'],$count); array_push($content_array['nbIpen'],$nb2); array_push($content_array['nbImage'],$nb3); } return $content_array; } } ?>