diff --git a/geolocation.module b/geolocation.module
index ed3d316..d21d66c 100644
--- a/geolocation.module
+++ b/geolocation.module
@@ -12,11 +12,20 @@ use Drupal\Core\Routing\RouteMatchInterface;
  */
 function geolocation_help($route_name, RouteMatchInterface $route_match) {
   switch ($route_name) {
-    case 'help.page.geolocation':
-      $output = '';
-      $output .= '<h3>' . t('About') . '</h3>';
-      $output .= '<p>' . t('The Geolocation module allows you to create fields that contain geographical locations. See the <a href="!field">Field module help</a> and the <a href="!field_ui">Field UI help</a> pages for general information on fields and how to create and manage them.', array('!field' => \Drupal::url('help.page', array('name' => 'field')), '!field_ui' => \Drupal::url('help.page', array('name' => 'field_ui')))) . '</p>';
+    case 'help.page.geolocation' :
+      $output = '<h3>' . t('About') . '</h3>';
+      $output .= '<p>'
+        . t('The Geolocation module allows you to create fields that contain geographical locations.
+          See the <a href="!field">Field module help</a> and the <a href="!field_ui">Field UI help</a>
+          pages for general information on fields and how to create and manage them.',
+          [
+            '!field' => \Drupal::url('help.page', ['name' => 'field']),
+            '!field_ui' => \Drupal::url('help.page', ['name' => 'field_ui'])
+          ]
+        )
+        . '</p>';
       return $output;
+      break;
   }
 }
 
@@ -24,10 +33,13 @@ function geolocation_help($route_name, RouteMatchInterface $route_match) {
  * Implements hook_theme().
  */
 function geolocation_theme() {
-  return array(
-    'geolocation_latlng_formatter' => array(
-      'variables' => array('lat' => NULL, 'lng' => NULL),
+  return [
+    'geolocation_latlng_formatter' => [
+      'variables' => [
+        'lat' => NULL,
+        'lng' => NULL
+      ],
       'template' => 'geolocation-latlng-formatter',
-    ),
-  );
+    ]
+  ];
 }
diff --git a/geolocation.services.yml b/geolocation.services.yml
new file mode 100644
index 0000000..d3fbbc8
--- /dev/null
+++ b/geolocation.services.yml
@@ -0,0 +1,5 @@
+services:
+  geolocation.core:
+    class: Drupal\geolocation\GeolocationCore
+    arguments: ["@module_handler", "@entity.manager"]
+
diff --git a/geolocation.views.inc b/geolocation.views.inc
new file mode 100644
index 0000000..ec60306
--- /dev/null
+++ b/geolocation.views.inc
@@ -0,0 +1,19 @@
+<?php
+/**
+ * @file
+ *   Provide views data for geolocation.module.
+ */
+use Drupal\field\FieldStorageConfigInterface;
+
+/**
+ * Implements hook_field_views_data().
+ *
+ * Views integration for taxonomy_term_reference fields. Adds a term relationship to the default
+ * field data.
+ *
+ * @see field_views_field_default_views_data()
+ */
+function geolocation_field_views_data(FieldStorageConfigInterface $field_storage) {
+  // User the geofield service to get the views data.
+  return \Drupal::service('geolocation.core')->getViewsFieldData($field_storage);
+}
diff --git a/src/GeolocationCore.php b/src/GeolocationCore.php
new file mode 100644
index 0000000..f2d4f75
--- /dev/null
+++ b/src/GeolocationCore.php
@@ -0,0 +1,173 @@
+<?php
+
+/**
+ * @file
+ * Contains Drupal\geolocation\GeolocationCore.
+ */
+
+namespace Drupal\geolocation;
+
+use Drupal\Core\Extension\ModuleHandler;
+use Drupal\Core\Entity\EntityManager;
+use Drupal\field\FieldStorageConfigInterface;
+
+/**
+ * Class GeolocationCore.
+ *
+ * @package Drupal\geolocation
+ */
+class GeolocationCore {
+
+  /**
+   * Drupal\Core\Extension\ModuleHandler definition.
+   *
+   * @var \Drupal\Core\Extension\ModuleHandler
+   */
+  protected $module_handler;
+
+  /**
+   * Drupal\Core\Entity\EntityManager definition.
+   *
+   * @var \Drupal\Core\Entity\EntityManager
+   */
+  protected $entity_manager;
+
+  /**
+   * Constructor.
+   */
+  public function __construct(ModuleHandler $module_handler, EntityManager $entity_manager) {
+    $this->module_handler = $module_handler;
+    $this->entity_manager = $entity_manager;
+  }
+
+  public function getViewsFieldData(FieldStorageConfigInterface $field_storage) {
+
+    // Make sure views.views.inc is loaded.
+    module_load_include('inc', 'views', 'views.views');
+
+    // Get the default data from the views module.
+    $data = views_field_default_views_data($field_storage);
+
+    // Loop through all of the results and set our overrides.
+    foreach ($data as $table_name => $table_data) {
+      foreach ($table_data as $field_name => $field_data) {
+        // only modify fields.
+        if ($field_name != 'delta') {
+          if (isset($field_data['field'])) {
+            // Use our own field handler.
+            $data[$table_name][$field_name]['field']['id'] = 'geolocation_field';
+          }
+          if (isset($field_data['filter'])) {
+            // The default filters aren't useful at all so remove them.
+            unset($data[$table_name][$field_name]['filter']);
+          }
+          if (isset($field_data['argument'])) {
+            // The default arguments aren't useful at all so remove them.
+            unset($data[$table_name][$field_name]['argument']);
+          }
+          if (isset($field_data['sort'])) {
+            // The default arguments aren't useful at all so remove them.
+            unset($data[$table_name][$field_name]['sort']);
+          }
+        }
+      }
+
+      $args = ['@field_name' => $field_storage->getName()];
+
+      $data[$table_name][$args['@field_name'] . '_proximity'] = [
+        'group' => 'Content',
+        'title' => t('Proximity (@field_name)', $args),
+        'title short' => $table_data[$args['@field_name']]['title short'] . t(":proximity"),
+        'help' => $table_data[$args['@field_name']]['help'],
+        'argument' => [
+          'id' => 'geolocation_argument_proximity',
+          'table' => $table_name,
+          'entity_type' => $field_storage->get('entity_type'),
+          'field_name' => $args['@field_name'].'_proximity',
+          'label' => t('Distance to !field_name', $args),
+          'empty field name' => '- No value -',
+          'additional fields' => [
+            $args['@field_name'].'_lat',
+            $args['@field_name'].'_lng',
+            $args['@field_name'].'_lat_sin',
+            $args['@field_name'].'_lat_cos',
+            $args['@field_name'].'_lng_rad',
+          ],
+        ],
+        'filter' => [
+          'id' => 'geolocation_filter_proximity',
+          'table' => $table_name,
+          'entity_type' => $field_storage->get('entity_type'),
+          'field_name' => $args['@field_name'].'_proximity',
+          'label' => t('Distance to !field_name', $args),
+          'allow empty' => TRUE,
+          'additional fields' => [
+            $args['@field_name'].'_lat',
+            $args['@field_name'].'_lng',
+            $args['@field_name'].'_lat_sin',
+            $args['@field_name'].'_lat_cos',
+            $args['@field_name'].'_lng_rad',
+          ],
+        ],
+        'field' => [
+          'table' => $table_name,
+          'id' => 'geolocation_field_proximity',
+          'field_name' => $args['@field_name'].'_proximity',
+          'entity_type' => $field_storage->get('entity_type'),
+          'real field' => $args['@field_name'].'_proximity',
+          'additional fields' => [
+            $args['@field_name'].'_lat',
+            $args['@field_name'].'_lng',
+            $args['@field_name'].'_lat_sin',
+            $args['@field_name'].'_lat_cos',
+            $args['@field_name'].'_lng_rad',
+          ],
+          'entity_tables' => $table_data[$args['@field_name']]['field']['entity_tables'],
+          'element type' => 'div',
+          'is revision' => $table_data[$args['@field_name']]['field']['is revision'],
+          'click sortable' => TRUE,
+        ],
+      ];
+    }
+
+    return $data;
+  }
+
+  /**
+   * Gets the query fragment for adding a proximity field to a query.
+   *
+   * @param $table_name
+   * @param $field_id
+   * @param $filter_lat
+   * @param $filter_lng
+   * @return string
+   */
+  public function getQueryFragment($table_name, $field_id, $filter_lat, $filter_lng) {
+
+    // Define the field names.
+    $field_latsin = "{$table_name}.{$field_id}_lat_sin";
+    $field_latcos = "{$table_name}.{$field_id}_lat_cos";
+    $field_lng    = "{$table_name}.{$field_id}_lng_rad";
+
+    // Pre-calculate filter values.
+    $filter_latcos = cos(deg2rad($filter_lat));
+    $filter_latsin = sin(deg2rad($filter_lat));
+    $filter_lng    = deg2rad($filter_lng);
+
+    // Keep it simple. We don't need high accuracy here.
+    $earth_radius = 6371;
+
+    return "(
+      ACOS(
+        $filter_latcos
+        * $field_latcos
+        * COS( $filter_lng - $field_lng  )
+        +
+        $filter_latsin
+        * $field_latsin
+      ) * $earth_radius
+    )";
+
+  }
+
+}
diff --git a/src/Plugin/views/argument/Proximity.php b/src/Plugin/views/argument/Proximity.php
new file mode 100644
index 0000000..81a855c
--- /dev/null
+++ b/src/Plugin/views/argument/Proximity.php
@@ -0,0 +1,94 @@
+<?php
+
+/**
+ * @file
+ *   Definition of Drupal\search\Plugin\views\argument\Proximity.
+ */
+
+namespace Drupal\geolocation\Plugin\views\argument;
+
+use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
+use Drupal\Core\Routing\RouteMatchInterface;
+use Drupal\geolocation\GeolocationCore;
+use Drupal\views\Plugin\views\argument\Formula;
+use Drupal\views\Plugin\views\query\Sql;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Argument handler for geolocation proximity.
+ *
+ * @ingroup views_argument_handlers
+ *
+ * @ViewsArgument("geolocation_argument_proximity")
+ */
+class Proximity extends Formula implements ContainerFactoryPluginInterface {
+
+  var $formula = '';
+
+  /**
+   * The route match.
+   *
+   * @var \Drupal\Core\Routing\RouteMatchInterface
+   */
+  protected $routeMatch;
+
+  /**
+   * Constructs a new Date instance.
+   *
+   * @param array $configuration
+   *   A configuration array containing information about the plugin instance.
+   * @param string $plugin_id
+   *   The plugin_id for the plugin instance.
+   * @param mixed $plugin_definition
+   *   The plugin implementation definition.
+   *
+   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
+   *   The route match.
+   */
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition);
+
+    $this->routeMatch = $route_match;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+    return new static(
+      $configuration,
+      $plugin_id,
+      $plugin_definition,
+      $container->get('current_route_match')
+    );
+  }
+//
+//  /**
+//   * Build the query based upon the formula
+//   */
+//  public function query($group_by = FALSE) {
+//    $this->ensureMyTable();
+//    // Now that our table is secure, get our formula.
+//    $placeholder = $this->placeholder();
+//
+//    $placeholders = array(
+//      $placeholder => $this->argument,
+//    );
+//    /** @var Sql $query */
+//    $query = $this->query;
+//    $query->addWhereExpression(0, $this->getFormula(), $placeholders);
+//  }
+//
+//  /**
+//   * @inheritdoc
+//   */
+//  public function getFormula() {
+//    /** @var GeolocationCore $geo_core */
+//    $geo_core = \Drupal::service('geolocation.core');
+////    $this->query->addWhereExpression($geo_core->generateQueryFragment($this->argument));
+//
+////    $this->query->addWhere(0, "$this->tableAlias.$this->realField", $this->argument);
+//    $formula = $geo_core->generateQueryFragment()str_replace('***table***', $this->tableAlias, $this->formula);
+//    return $formula;
+//  }
+}
diff --git a/src/Plugin/views/field/Geolocation.php b/src/Plugin/views/field/Geolocation.php
new file mode 100644
index 0000000..e52f37a
--- /dev/null
+++ b/src/Plugin/views/field/Geolocation.php
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * @file
+ *   Definition of Drupal\geolocation\Plugin\views\Geolocation.
+ */
+
+namespace Drupal\geolocation\Plugin\views\field;
+
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\views\Plugin\views\field\Field;
+use Drupal\views\ResultRow;
+
+/**
+ * Field handler for geolocaiton field.
+ *
+ * @ingroup views_field_handlers
+ *
+ * @todo Rename the extended class https://www.drupal.org/node/2408667
+ *
+ * @ViewsField("geolocation_field")
+ */
+class Geolocation extends Field {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function getFieldStorageDefinition() {
+    return parent::getFieldStorageDefinition();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+    parent::buildOptionsForm($form, $form_state);
+  }
+}
diff --git a/src/Plugin/views/field/Proximity.php b/src/Plugin/views/field/Proximity.php
new file mode 100644
index 0000000..cfe4a52
--- /dev/null
+++ b/src/Plugin/views/field/Proximity.php
@@ -0,0 +1,130 @@
+<?php
+
+/**
+ * @file
+ *   Definition of Drupal\geolocation\Plugin\views\Proximity.
+ */
+
+namespace Drupal\geolocation\Plugin\views\field;
+
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\views\Plugin\views\field\NumericField;
+
+/**
+ * Field handler for geolocaiton field.
+ *
+ * @ingroup views_field_handlers
+ *
+ * @ViewsField("geolocation_field_proximity")
+ */
+class Proximity extends NumericField {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function getFieldStorageDefinition() {
+    return parent::getFieldStorageDefinition();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+    // Add a start point selector.
+    // Add the proximity field group.
+    $form['proximity_group'] = [
+      '#type' => 'fieldset',
+      '#title' => t('Proximity Settings'),
+    ];
+    // Add the source selector.
+    $form['proximity_group']['source'] = [
+      '#type' => 'select',
+      '#title' => t('Select the source type.'),
+      '#description' => t('To calculate proximity we need a starting point to compare the field value to. Select where to get the start location.'),
+      '#options' => [
+        'direct_input' => t('Direct Input'),
+        'filter' => t('Filter Settings'),
+      ],
+    ];
+    // Add the Lat/Lng field group for direct input.
+//    $form['proximity_group']['lat_lng'] = [
+//      '#type' => 'fieldset',
+//      '#title' => t('Direct Input'),
+//      '#states' => [
+//
+//      ],
+//    ];
+    // Add the Latitude field for direct input.
+    $form['proximity_group']['lat'] = [
+      '#type' => 'textfield',
+      '#title' => t('Latitude'),
+      '#empty_value' => '',
+      '#default_value' => '',
+      '#maxlength' => 255,
+      '#description' => t('Latitude'),
+      '#states' => [
+        'visible' => [
+          'select[name="options[proximity_group][source]"]' => ['value' => 'direct_input'],
+        ],
+      ],
+    ];
+    // Add the Latitude field for direct input.
+    $form['proximity_group']['lng'] = [
+      '#type' => 'textfield',
+      '#title' => t('Longitude'),
+      '#empty_value' => '',
+      '#default_value' => '',
+      '#maxlength' => 255,
+      '#description' => t('Longitude'),
+      '#states' => [
+        'visible' => [
+          'select[name="options[proximity_group][source]"]' => ['value' => 'direct_input'],
+        ],
+      ],
+    ];
+    $valid_filters = [];
+
+    $handlers = $this->view->getHandlers('filter', $this->view->current_display);
+    // Check for valid filters.
+    foreach ($this->view->getHandlers('filter', $this->view->current_display) as $delta => $filter) {
+      if ($filter['plugin_id'] === 'geolocation_filter_proximity') {
+        $valid_filters[$delta] = $filter['id'];
+      }
+    }
+    // Add the Filter selector.
+    $form['proximity_group']['filter_selector'] = empty($valid_filters)
+      ? ['#markup' => t('There are no proximity filters available in this display.')]
+      : [
+        '#type' => 'select',
+        '#title' => t('Select filter.'),
+        '#description' => t('Select the filter to use as the starting point for calculating proximity.'),
+        '#options' => $valid_filters,
+        '#states' => [
+          'visible' => [
+            'select[name="options[proximity_group][source]"]' => ['value' => 'filter'],
+          ],
+        ],
+      ];
+
+    // Add the Drupal\views\Plugin\views\field\Numeric settings to the form.
+    parent::buildOptionsForm($form, $form_state);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function query() {
+    return NULL;
+    $this->ensureMyTable();
+    // Add the field.
+    $params = $this->options['group_type'] != 'group' ? array('function' => $this->options['group_type']) : array();
+    $this->field_alias = $this->query->addField(NULL, $this->realField, NULL, $params);
+
+    // Figure out the starting point.
+
+    // Add the query expression.
+
+//    $this->addAdditionalFields();
+  }
+
+}
diff --git a/src/Plugin/views/filter/Proximity.php b/src/Plugin/views/filter/Proximity.php
new file mode 100644
index 0000000..e2320c4
--- /dev/null
+++ b/src/Plugin/views/filter/Proximity.php
@@ -0,0 +1,194 @@
+<?php
+
+/**
+ * @file
+ *   Definition of Drupal\search\Plugin\views\filter\Search.
+ */
+
+namespace Drupal\geolocation\Plugin\views\filter;
+
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
+use Drupal\geolocation\GeolocationCore;
+use Drupal\views\Plugin\views\display\DisplayPluginBase;
+use Drupal\views\Plugin\views\filter\NumericFilter;
+use Drupal\views\Plugin\views\query\Sql;
+use Drupal\views\ViewExecutable;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Filter handler for search keywords.
+ *
+ * @ingroup views_filter_handlers
+ *
+ * @ViewsFilter("geolocation_filter_proximity")
+ */
+class Proximity extends NumericFilter implements ContainerFactoryPluginInterface {
+
+  /**
+   * The field alias.
+   *
+   * @var string
+   */
+  protected $field_alias;
+
+  /**
+   * The geolocaiton core service.
+   *
+   * @var \Drupal\geolocation\GeolocationCore
+   */
+  protected $geolocation_core;
+
+  /**
+   * Constructs a new Date instance.
+   *
+   * @param array $configuration
+   *   A configuration array containing information about the plugin instance.
+   * @param string $plugin_id
+   *   The plugin_id for the plugin instance.
+   * @param mixed $plugin_definition
+   *   The plugin implementation definition.
+   *
+   * @param \Drupal\geolocation\GeolocationCore
+   *   The geolocation core helper.
+   */
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, GeolocationCore $geolocation_core) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition);
+
+    $this->geolocation_core = $geolocation_core;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+    return new static(
+      $configuration,
+      $plugin_id,
+      $plugin_definition,
+      $container->get('geolocation.core')
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
+    parent::init($view, $display, $options);
+
+    // Set the field alias.
+    $this->field_alias = $this->options['id'] . '_filter';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function defineOptions() {
+    $options = parent::defineOptions();
+
+    // value is already set up properly, we're just adding our new field to it.
+    $options['value']['contains']['lat']['default'] = '';
+    $options['value']['contains']['lng']['default'] = '';
+
+    return $options;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function valueForm(&$form, FormStateInterface $form_state) {
+    $form['value']['lat'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Latitude'),
+      '#default_value' => !empty($this->value['lat']) ? $this->value['lat'] : '',
+    ];
+    $form['value']['lng'] = [
+      '#type' => 'textfield',
+      '#title' => $this->t('Longitude'),
+      '#default_value' => !empty($this->value['lng']) ? $this->value['lng'] : '',
+    ];
+    parent::valueForm($form, $form_state);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function query() {
+    /** @var Sql $query */
+    $query = $this->query;
+    $table_name = $this->ensureMyTable();
+    $field_id = str_replace('_proximity', '', $this->realField);
+    $lat = $this->value['lat'];
+    $lgn = $this->value['lng'];
+
+    $expression = $this->geolocation_core->getQueryFragment($table_name, $field_id, $lat, $lgn);
+
+    // We use having to be able to reuse the query on field handlers
+    $query->addField(NULL, $expression, $this->field_alias);
+
+    $info = $this->operators();
+    $placeholder = $this->placeholder();
+    if (!empty($info[$this->operator]['method'])) {
+      $this->{$info[$this->operator]['method']}($placeholder, $expression);
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function opBetween($placeholder, $expression) {
+    if ($this->operator == 'between') {
+      $this->query->addWhereExpression($this->options['group'], "{$expression} BETWEEN {$placeholder}_min AND {$placeholder}_max",
+        [
+          $placeholder . '_min' => $this->value['min'],
+          $placeholder . '_max' => $this->value['max']
+        ]
+      );
+    }
+    else {
+      $this->query->addWhereExpression($this->options['group'], "{$expression} <= {$placeholder}_min OR {$field} >= {$placeholder}_max",
+        [
+          $placeholder . '_min' => $this->value['min'],
+          $placeholder . '_max' => $this->value['max']
+        ]
+      );
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function opSimple($placeholder, $expression) {
+    $this->query->addWhereExpression($this->options['group'], "{$expression} {$this->operator} {$placeholder}",
+      [
+        $placeholder => $this->value['value']
+      ]
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function opEmpty($placeholder, $expression) {
+    if ($this->operator == 'empty') {
+      $operator = "IS NULL";
+    }
+    else {
+      $operator = "IS NOT NULL";
+    }
+
+    $this->query->addWhereExpression($this->options['group'], "{$expression} {$operator}");
+  }
+
+  /**
+   * @inheritdoc
+   */
+  protected function opRegex($placeholder, $expression) {
+    $this->query->addWhereExpression($this->options['group'], "{$expression} 'REGEXP' {$placeholder}",
+      [
+        $placeholder => $this->value['value']
+      ]
+    );
+  }
+
+}
diff --git a/src/Plugin/views/sort/Geolocation.php b/src/Plugin/views/sort/Geolocation.php
new file mode 100644
index 0000000..898108b
--- /dev/null
+++ b/src/Plugin/views/sort/Geolocation.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\search\Plugin\views\sort\Score.
+ */
+
+namespace Drupal\search\Plugin\views\sort;
+
+use Drupal\views\Plugin\views\sort\SortPluginBase;
+
+/**
+ * Sort handler for sorting by search score.
+ *
+ * @ingroup views_sort_handlers
+ *
+ * @ViewsSort("search_score")
+ */
+class Score extends SortPluginBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function query() {
+    // Check to see if the search filter/argument added 'score' to the table.
+    // Our filter stores it as $handler->search_score -- and we also
+    // need to check its relationship to make sure that we're using the same
+    // one or obviously this won't work.
+    foreach (array('filter', 'argument') as $type) {
+      foreach ($this->view->{$type} as $handler) {
+        if (isset($handler->search_score) && $handler->relationship == $this->relationship) {
+          $this->query->addOrderBy(NULL, NULL, $this->options['order'], $handler->search_score);
+          $this->tableAlias = $handler->tableAlias;
+          return;
+        }
+      }
+    }
+
+    // Do nothing if there is no filter/argument in place. There is no way
+    // to sort on scores.
+  }
+
+}
