/** * Get result data for the response * * @throws RuntimeException * @param Result $result * @return array */ public function parse($result) { $data = $result->getData(); /** * @var $query Query */ $query = $result->getQuery(); // create document instances $documentClass = $query->getOption('documentclass'); $classes = class_implements($documentClass); if (!in_array('Solarium\\QueryType\\Select\\Result\\DocumentInterface', $classes) && !in_array('Solarium\\QueryType\\Update\\Query\\Document\\DocumentInterface', $classes)) { throw new RuntimeException('The result document class must implement a document interface'); } $documents = array(); if (isset($data['response']['docs'])) { foreach ($data['response']['docs'] as $doc) { $fields = (array) $doc; $documents[] = new $documentClass($fields); } } // component results $components = array(); foreach ($query->getComponents() as $component) { $componentParser = $component->getResponseParser(); if ($componentParser) { $components[$component->getType()] = $componentParser->parse($query, $component, $data); } } if (isset($data['response']['numFound'])) { $numFound = $data['response']['numFound']; } else { $numFound = null; } return $this->addHeaderInfo($data, array('numfound' => $numFound, 'documents' => $documents, 'components' => $components)); }
/** * @param \Solarium\QueryType\Select\Result\Result $ergebnisse * @return array(); */ public static function ergebnisse2FeedData($ergebnisse) { $data = array(); $dokumente = $ergebnisse->getDocuments(); $highlighting = $ergebnisse->getHighlighting(); $purifier = new CHtmlPurifier(); $purifier->options = array('URI.AllowedSchemes' => array('http' => true, 'https' => true)); foreach ($dokumente as $dokument) { $model = Dokument::getDocumentBySolrId($dokument->id); $risitem = $model->getRISItem(); if (!$risitem) { continue; } $link = $risitem->getLink(); $highlightedDoc = $highlighting->getResult($dokument->id); $item = array("title" => $model->name . " (zu " . $risitem->getTypName() . " \"" . $risitem->getName() . "\"", "link" => $link, "content" => "", "dateCreated" => RISTools::date_iso2timestamp(str_replace("T", " ", str_replace("Z", "", $dokument->sort_datum))), "aenderung_guid" => $link); if ($highlightedDoc && count($highlightedDoc) > 0) { foreach ($highlightedDoc as $highlight) { $item["content"] .= $purifier->purify(implode(' (...) ', $highlight)) . '<br/>'; } } $data[] = $item; } return $data; }
/** * Fetch the next set of results * * @return void */ protected function fetchNext() { $this->query->setStart($this->start)->setRows($this->getPrefetch()); $this->result = $this->client->execute($this->query, $this->getOption('endpoint')); $this->documents = $this->result->getDocuments(); $this->start += $this->getPrefetch(); }
/** * @param RISSucheKrits $krits * @param \Solarium\QueryType\Select\Result\Result $ergebnisse * @return array */ protected function getJSGeodata($krits, $ergebnisse) { $geo = $krits->getGeoKrit(); /** @var RISSolrDocument[] $solr_dokumente */ $solr_dokumente = $ergebnisse->getDocuments(); $dokument_ids = []; foreach ($solr_dokumente as $dokument) { $x = explode(":", $dokument->id); $dokument_ids[] = IntVal($x[1]); } $geodata = []; if (count($dokument_ids) > 0) { $lat = FloatVal($geo["lat"]); $lng = FloatVal($geo["lng"]); $dist_field = "(((acos(sin(({$lat}*pi()/180)) * sin((lat*pi()/180))+cos(({$lat}*pi()/180)) * cos((lat*pi()/180)) * cos((({$lng}- lon)*pi()/180))))*180/pi())*60*1.1515*1.609344) <= " . FloatVal($geo["radius"] / 1000); $SQL = "select a.dokument_id, b.* FROM antraege_orte a JOIN orte_geo b ON a.ort_id = b.id WHERE a.dokument_id IN (" . implode(", ", $dokument_ids) . ") AND b.to_hide = 0 AND {$dist_field}"; $result = Yii::app()->db->createCommand($SQL)->queryAll(); foreach ($result as $geo) { /** @var Dokument $dokument */ $dokument = Dokument::model()->findByPk($geo["dokument_id"]); if ($dokument->antrag) { $link = $dokument->antrag->getLink(); $name = $dokument->antrag->getName(); } elseif ($dokument->termin) { $link = $dokument->termin->getLink(); $name = $dokument->termin->getName(); } else { $link = $name = ""; } if (strlen($name) > 150) { $name = mb_substr($name, 0, 148) . "..."; } if ($link != "") { $link = "<div class='antraglink'>" . CHtml::link($name, $link) . "</div>"; } $str = $link; $str .= "<div class='ort_dokument'>"; $str .= "<div class='ort'>" . CHtml::encode($geo["ort"]) . "</div>"; $str .= "<div class='dokument'>" . CHtml::link($dokument->name, $this->createUrl("index/dokument", ["id" => $dokument->id])) . "</div>"; $str .= "</div>"; $geodata[] = [FloatVal($geo["lat"]), FloatVal($geo["lon"]), $str]; } } return $geodata; }
/** * @see IteratorAggregate::getIterator */ public function getIterator() { return $this->result->getIterator(); }
/** * Lets modules alter the search results returned from a Solr search. * * @param \Drupal\search_api\Query\ResultSetInterface $results * The results array that will be returned for the search. * @param \Drupal\search_api\Query\QueryInterface $query * The SearchApiQueryInterface object representing the executed search query. * @param \Solarium\QueryType\Select\Result\Result $resultset * The Solarium result object. */ function hook_search_api_solr_search_results_alter(\Drupal\search_api\Query\ResultSetInterface $results, \Drupal\search_api\Query\QueryInterface $query, \Solarium\QueryType\Select\Result\Result $resultset) { $resultset_data = $resultset->getData(); if (isset($resultset_data['facet_counts']['facet_fields']['custom_field'])) { // Do something with $results. } }
/** * Extracts facets from a Solarium result set. * * @param \Drupal\search_api\Query\QueryInterface $query * The search query. * @param \Solarium\QueryType\Select\Result\Result $resultset * A Solarium select response object. * * @return array * An array describing facets that apply to the current results. */ protected function extractFacets(QueryInterface $query, Result $resultset) { $facets = array(); if (!$resultset->getFacetSet()) { return $facets; } $index = $query->getIndex(); $field_names = $this->getFieldNames($index); $fields = $index->getFields(); $extract_facets = $query->getOption('search_api_facets', array()); if ($facet_fields = $resultset->getFacetSet()->getFacets()) { foreach ($extract_facets as $delta => $info) { $field = $field_names[$info['field']]; if (!empty($facet_fields[$field])) { $min_count = $info['min_count']; $terms = $facet_fields[$field]->getValues(); if ($info['missing']) { // We have to correctly incorporate the "_empty_" term. // This will ensure that the term with the least results is dropped, // if the limit would be exceeded. if (isset($terms[''])) { if ($terms[''] < $min_count) { unset($terms['']); } else { arsort($terms); if ($info['limit'] > 0 && count($terms) > $info['limit']) { array_pop($terms); } } } } elseif (isset($terms[''])) { unset($terms['']); } $type = isset($fields[$info['field']]) ? $fields[$info['field']]->getType() : 'string'; foreach ($terms as $term => $count) { if ($count >= $min_count) { if ($term === '') { $term = '!'; } elseif ($type == 'boolean') { if ($term == 'true') { $term = '"1"'; } elseif ($term == 'false') { $term = '"0"'; } } elseif ($type == 'date') { $term = $term ? '"' . strtotime($term) . '"' : NULL; } else { $term = "\"{$term}\""; } if ($term) { $facets[$delta][] = array('filter' => $term, 'count' => $count); } } } if (empty($facets[$delta])) { unset($facets[$delta]); } } } } $result_data = $resultset->getData(); if (isset($result_data['facet_counts']['facet_queries'])) { if ($spatials = $query->getOption('search_api_location')) { foreach ($result_data['facet_counts']['facet_queries'] as $key => $count) { if (!preg_match('/^spatial-(.*)-(\\d+(?:\\.\\d+)?)$/', $key, $m)) { continue; } if (empty($extract_facets[$m[1]])) { continue; } $facet = $extract_facets[$m[1]]; if ($count >= $facet['min_count']) { $facets[$m[1]][] = array('filter' => "[* {$m[2]}]", 'count' => $count); } } } } return $facets; }
public function getIterator() { $this->execute(); return new \ArrayIterator($this->selectResult->getDocuments()); }