Esempio n. 1
0
 /**
  * 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;
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * @dataProvider dataProviderGetGroupedItemsIdsByEntity
  * @param $expected
  * @param $items
  */
 public function testGetGroupedItemsIdsByEntity($expected, $items)
 {
     $grouped_items = SearchApiEtHelper::getGroupedItemsIdsByEntity($items);
     $this->assertEquals($expected, $grouped_items);
 }
 /**
  * Filters the given Item IDs to include only the ones handled by the Index.
  *
  * @param SearchApiIndex $index
  *   The SearchAPI index to use
  * @param array $item_ids
  *   A list of trackable ItemID (in the form "{id}/{language}) to filter
  * @return array
  *   The filtered list of trackable ItemID
  */
 protected function filterTrackableIds(SearchApiIndex $index, $item_ids)
 {
     if (empty($item_ids)) {
         return array();
     }
     // Group the given ItemIds by their EntityId.
     $grouped_item_ids = SearchApiEtHelper::getGroupedItemsIdsByEntity($item_ids);
     if (empty($grouped_item_ids)) {
         return array();
     }
     // Generate the list of candidate ItemIDs from the current EntityIDs
     $trackable_item_ids = $this->getTrackableItemIds($index, array_keys($grouped_item_ids));
     // The $trackable_item_ids will contain all ItemIDs that should be indexed.
     // Additional translations, other than the one provided in $item_ids, will
     // be taken into account, to cover the case when a non-translatable field is
     // changed on one translation and such change must be reflected to all other
     // indexed translations.
     return $trackable_item_ids;
 }