/** * Helper function for adding results to a view in the format expected by the * view. * * Overrides SearchApiViewsQuery::addResults(), as it does not handle * multilingual search item IDs (like 'fr_13') properly. * * @see SearchApiViewsQuery::addResults() */ protected function addResults(array $results, $view) { // Start with standard way of adding results to the view. parent::addResults($results, $view); // For multilingual indexes, update entity IDs in $view->result array // and remove language code from them, so that they contain real entity IDs // stored as integers. $controller = search_api_get_datasource_controller($this->index->item_type); if ($controller instanceof SearchApiEtDatasourceController) { foreach ($view->result as $delta => $result) { if (SearchApiEtHelper::isValidItemId($result->entity)) { $entity_id = SearchApiEtHelper::splitItemId($result->entity, SearchApiEtHelper::ITEM_ID_ENTITY_ID); $view->result[$delta]->entity = (int) $entity_id; } } } }
/** * @dataProvider dataProviderIsValidItemId * @param $expected * @param $value */ public function testIsValidItemId($expected, $value) { $this->assertEquals($expected, SearchApiEtHelper::isValidItemId($value)); }
/** * Helper function to return the list of ItemIDs, fiven * @param \SearchApiIndex $index * @param $mixed_ids * @return array */ protected function getTrackableItemIdsFromMixedSource(SearchApiIndex $index, $mixed_ids) { // Check if we get Entity IDs or Item IDs. $first_item_id = reset($mixed_ids); $is_valid_item_id = SearchApiEtHelper::isValidItemId($first_item_id); if (!$is_valid_item_id) { $entity_id = $first_item_id; $ids = $this->getTrackableItemIds($index, $entity_id); } else { // Filter the item_ids that need to be tracked by this index. $ids = $this->filterTrackableIds($index, $mixed_ids); } return $ids; }