3 namespace Drupal\search\Plugin\views\field;
5 use Drupal\views\Plugin\views\field\NumericField;
6 use Drupal\views\ResultRow;
9 * Field handler for search score.
11 * @ingroup views_field_handlers
13 * @ViewsField("search_score")
15 class Score extends NumericField {
20 public function query() {
21 // Check to see if the search filter added 'score' to the table.
22 // Our filter stores it as $handler->search_score -- and we also
23 // need to check its relationship to make sure that we're using the same
24 // one or obviously this won't work.
25 foreach ($this->view->filter as $handler) {
26 if (isset($handler->search_score) && ($handler->relationship == $this->relationship)) {
27 $this->field_alias = $handler->search_score;
28 $this->tableAlias = $handler->tableAlias;
33 // Hide this field if no search filter is in place.
34 $this->options['exclude'] = TRUE;
40 public function render(ResultRow $values) {
41 // Only render if we exist.
42 if (isset($this->tableAlias)) {
43 return parent::render($values);