setAdapter ( 'Solarium\Core\Client\Adapter\Http' ); // get a select query instance $query = $client->createSelect (); // set a query (all prices starting from 12) $searchterm = str_replace ( ")", "\)", str_replace ( ":", "\:", str_replace ( "(", "\(", str_replace ( " ", "\ ", $name ) ) ) ); $query->setQuery ( 'fullScientificName_nc:' . $searchterm . ' OR phylum:' . $searchterm); // set fields to fetch (this overrides the default setting 'all fields') $query->setFields ( array ( 'hierarchy,backbonefullname,backboneaccepted,backboneref,originalName,sampleType,preparationType' ) ); // this executes the query and returns the result $resultset = $client->select ( $query ); foreach ( $resultset as $document ) { try { $backbonefullname = $document->backbonefullname; $backbonefullname = str_ireplace ( " ", "", $backbonefullname ); $backbonefullname = str_ireplace ( ".", "", $backbonefullname ); $backbonefullname = str_ireplace ( "(", "", $backbonefullname ); $backbonefullname = str_ireplace ( ")", "", $backbonefullname ); $backboneaccepted = $document->backboneaccepted; $backboneaccepted = str_ireplace ( " ", "", $backboneaccepted ); $backboneaccepted = str_ireplace ( ".", "", $backboneaccepted ); $backboneaccepted = str_ireplace ( "(", "", $backboneaccepted ); $backboneaccepted = str_ireplace ( ")", "", $backboneaccepted ); $originalName = $document->originalName; $originalName = str_ireplace ( " ", "", $originalName ); $originalName = str_ireplace ( ".", "", $originalName ); $originalName = str_ireplace ( "(", "", $originalName ); $originalName = str_ireplace ( ")", "", $originalName ); if (! Yii::$app->params ['noBack']) if ($backboneaccepted !== $backbonefullname) { $accepted = $document->backbonefullname . " is " . $document->backboneaccepted . " according to " . $document->backboneref; return [ $document->hierarchy, $document->backboneaccepted, $accepted ]; } else if (! empty ( $backboneaccepted )) { if($document->sampletype == "environmental sample" || $document->preparationType == "eDNA") { $Backboneaccepted = $_GET['term']."*"; $Hierarchy = " Name '".$_GET['term']."' appears in environmental sample(s) or eDNA"; } else { $Hierarchy = $document->hierarchy; $Backboneaccepted = $document->backboneaccepted; } return [ $Hierarchy, $Backboneaccepted ]; } else { if($document->sampletype == "environmental sample" || $document->preparationType == "eDNA") { $backbonedefault = " Name '".$_GET['term']."' appears in environmental sample(s) or eDNA"; $name = $_GET['term']."*"; } else { $backbonedefault = "no backbone hit"; $name = $name; } return [ $backbonedefault, $name ]; } else { if ($backboneaccepted !== $backbonefullname) { $accepted = " is a synonym of " . $document->backboneaccepted . " according to " . $document->backboneref; return [ $document->hierarchy, $name, $accepted ]; } else if (! empty ( $backboneaccepted )) { $accepted = " is accepted according to " . $document->backboneref; return [ $document->hierarchy, $document->backboneaccepted, $accepted ]; } else return [ " ", $name, "was not found in The Backbone" ] ; } } catch ( Exception $e ) { return [ $document->hierarchy, $document->backboneaccepted ]; } return [ $document->hierarchy, $document->backboneaccepted ]; } return [ ]; } /** * this builds a query for an autosuggest field * it is used dynamically * (depending on the user input) * and runs the query and returns the result */ public static function newFacetsList($field, $filter, $filteropt) { // create a client instance $client = new Solarium\Client ( SOLRQueryManager::getConfigSearch() ); // set the adapter to http $client->setAdapter ( 'Solarium\Core\Client\Adapter\Http' ); // get a select query instance $query = $client->createSelect (); // get the facetset component $facetSet = $query->getFacetSet (); // set fields to fetch (this overrides the default setting 'all fields') $query->setFields ( array ( $field ) ); $facetSet->setLimit ( - 1 ); $facetSet->setMinCount ( 1 ); $facetSet->setSort ( "false" ); // set a query // $query->setQuery ( $field_suggest . ":" . $filter . "*" ); $suffix = ""; if($field=='sequenceaccessionIdentifier' || $field=='fullScientificName' || $field=='country' || $field=='sea' || $field=='continent' || $field=='ocean') { $suffix='_nc'; } elseif($field=='genusName') { $field = 'genus'; $suffix = '_nc'; } elseif($field=='speciesName') { $field = 'species'; $suffix = '_nc'; } else { $suffix =""; } //$suffix ="_nc"; if (isset ( $filteropt ) && ! empty ( $filteropt )) $query->setQuery ( $field . $suffix.":" . $filter . "*" .Yii::$app->params['thematicSOLRfilter']. $filteropt); else $query->setQuery ( $field . $suffix.":" . $filter . "*" .Yii::$app->params['thematicSOLRfilter'] ); $facet = $facetSet->createFacetMultiQuery ( $field . '2' ); $facet->createQuery ( $field, $field . $suffix.':' . $filter . '*' .Yii::$app->params['thematicSOLRfilter'] ); $facetSet->createFacetField ( $field )->setField ( $field ); // this executes the query and returns the result $resultset = $client->select ( $query ); $result = array (); // display facet query count $facet = $resultset->getFacetSet ()->getFacet ( $field ); $nbElts = 0; foreach ( $facet as $key => $count ) { if ($nbElts > 50) { ksort ( $result ); return $result; } if ($count > 0) { if ($field != "fullScientificName"){ // Yii::info("stripos " .stripos($key, $filter)); if( (stripos($key, $filter))!==false) $result [$key] = $count; } if ($field == "fullScientificName") { $tmp = FormSuggestionsQueryManager::getHierarchy ( $key ); $backboneaccepted = str_ireplace ( " ", "", $tmp [1] ); $backboneaccepted = str_ireplace ( ".", "", $backboneaccepted ); $backboneaccepted = str_ireplace ( "(", "", $backboneaccepted ); $backboneaccepted = str_ireplace ( ")", "", $backboneaccepted ); $n = str_ireplace ( " ", "", $key ); $n = str_ireplace ( ".", "", $n ); $n = str_ireplace ( "(", "", $n ); $n = str_ireplace ( ")", "", $n ); if ($backboneaccepted != $n) $key = $tmp [1]; $result [$key] = $count; $result ["hierarchy" . $key] = $tmp [0]; $nbElts ++; if (sizeof ( $tmp ) == 3) { $result ["reason" . $key] = $tmp [2]; $nbElts += 0.5; } // Yii::info ( "result [key]" . $key ); // Yii::info ( "result [hierarchy . key]" . $result ["hierarchy" . $key] ); // Yii::info ( "result [acceptedName . key]" . $result ["acceptedName" . $key] ); } } } ksort ( $result ); return $result; } } ?>