diff --git a/search_api.views.inc b/search_api.views.inc index dabe135..de6fa43 100644 --- a/search_api.views.inc +++ b/search_api.views.inc @@ -6,9 +6,7 @@ */ use Drupal\search_api\Entity\Index; -use Drupal\search_api\Utility; -use Drupal\Component\Utility\NestedArray; -use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\search_api\IndexInterface; /** * Implements hook_views_data(). @@ -99,7 +97,15 @@ function search_api_views_plugins_row_alter(array &$plugins) { $plugins['search_api']['base'] = $bases; } -function _search_api_views_data_special_fields(&$table, $index) { +/** + * Define the special fields for this index. + * + * @param array $table + * An array describing the fields. + * @param \Drupal\search_api\IndexInterface $index + * The index we're adding fields for. + */ +function _search_api_views_data_special_fields(&$table, IndexInterface $index) { // Add handlers for special fields. $table['search_api_id']['title'] = t('Search API ID'); $table['search_api_id']['help'] = t("The entity's encoded Search API ID"); @@ -137,8 +143,15 @@ function _search_api_views_data_special_fields(&$table, $index) { $table['search_api_more_like_this']['argument']['id'] = 'search_api_more_like_this'; } - -function _search_api_views_data_searchapi_fields(&$table, $index) { +/** + * Add the fields for this index as views fields. + * + * @param $table + * An array describing the fields. + * @param \Drupal\search_api\IndexInterface $index + * The index we're adding fields for. + */ +function _search_api_views_data_searchapi_fields(&$table, IndexInterface $index) { foreach ($index->getFields() as $field_id => $field) { // Fields specifically // @@ -151,10 +164,6 @@ function _search_api_views_data_searchapi_fields(&$table, $index) { $type = 'integer'; $id = 'numeric'; break; - case 'string': - $type = ''; - $id = 'standard'; - break; case 'text': $type = ''; $id = 'markup'; @@ -164,6 +173,11 @@ function _search_api_views_data_searchapi_fields(&$table, $index) { $type = ''; $id = 'date'; break; + case 'string': + default: + $type = ''; + $id = 'standard'; + break; } // @todo diff --git a/src/Plugin/views/query/SearchApiEntityQuery.php b/src/Plugin/views/query/SearchApiEntityQuery.php index f7ce161..08087f3 100644 --- a/src/Plugin/views/query/SearchApiEntityQuery.php +++ b/src/Plugin/views/query/SearchApiEntityQuery.php @@ -7,7 +7,7 @@ namespace Drupal\search_api\Plugin\views\query; -use Drupal\Core\Entity\EntityTypeManager; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\search_api\Entity\Index; use Drupal\views\ViewExecutable; @@ -28,7 +28,7 @@ class SearchApiEntityQuery extends SearchApiQuery { /** * {@inheritdoc} */ - public static function getIndexFromTable($table, EntityTypeManager $entity_type_manager = NULL) { + public static function getIndexFromTable($table, EntityTypeManagerInterface $entity_type_manager = NULL) { if (substr($table, 0, 24) == 'search_api_index_entity_') { $index_id = substr($table, 27); if ($entity_type_manager) { diff --git a/src/Plugin/views/query/SearchApiQuery.php b/src/Plugin/views/query/SearchApiQuery.php index d837cd1..070f92c 100644 --- a/src/Plugin/views/query/SearchApiQuery.php +++ b/src/Plugin/views/query/SearchApiQuery.php @@ -9,7 +9,7 @@ namespace Drupal\search_api\Plugin\views\query; use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; -use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\search_api\Entity\Index; @@ -112,13 +112,13 @@ class SearchApiQuery extends QueryPluginBase { * * @param string $table * The Views base table ID. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_type_manager + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * (optional) The entity manager to use. * * @return \Drupal\search_api\IndexInterface|null * The requested search index, or NULL if it could not be found and loaded. */ - public static function getIndexFromTable($table, EntityManagerInterface $entity_type_manager = NULL) { + public static function getIndexFromTable($table, EntityTypeManagerInterface $entity_type_manager = NULL) { if (substr($table, 0, 17) == 'search_api_index_') { $index_id = substr($table, 17); if ($entity_type_manager) { @@ -164,8 +164,8 @@ class SearchApiQuery extends QueryPluginBase { // It's assumed by fields. Most important is that it indexes. // Is is used elsewhere? public function addField($table, $field, $alias = '', $params = array()) { - // Is there some reason to be called with an alias, would then - // need to store it? + // Is there some reason to be called with an alias, would then need to store + // it? $this->fields[$field] = TRUE; return $alias ? $alias : $field; } @@ -390,7 +390,6 @@ class SearchApiQuery extends QueryPluginBase { if ($results->getResultItems()) { $this->addResults($results->getResultItems(), $view); } - $view->execute_time = microtime(TRUE) - $start; // Trigger pager postExecute(). @@ -493,6 +492,15 @@ class SearchApiQuery extends QueryPluginBase { $this->tags[] = $tag; } + /** + * Makes sure that the results are loaded as entities. + * + * @param array $results + * An array of results. + * @param \Drupal\views\ViewExecutable $view + * The view where these results are shown. + * @param array $entity_information + */ protected function loadResultEntities(&$results, ViewExecutable $view, $entity_information) { // List entities types to load from the relationships on the view. $entities_to_load = []; @@ -509,6 +517,16 @@ class SearchApiQuery extends QueryPluginBase { } } + /** + * Load the result entity. + * + * @param array $results + * An array of results. + * @param $result + * One item out of the results set. + * @param $relationships + * @param $entities_to_load + */ private function loadResultEntity(&$results, $result, $relationships, $entities_to_load) { $item = $this->index->loadItem($result->search_api_id); if ($item) {