I'm trying to implement a super simple proof of concept for pulling in non-drupal stored content into search api via Solr. The plugin is super simple:
<?php namespace Drupal\sla_indexing\Plugin\search_api\datasource; use Drupal\search_api\Datasource\DatasourcePluginBase; use Drupal\search_api\Item\Item; use Drupal\search_api\Item\ItemInterface; use Drupal\search_api\Item\Field; use Drupal\Core\TypedData\DataDefinition; /** * @SearchApiDatasource( * id = "test_external_datasource", * label = @Translation("Test External Datasource"), * description = @Translation("A test datasource for indexing non-Drupal content."), * ) */ class TestExternalDatasource extends DatasourcePluginBase { /** * {@inheritdoc} */ public function getItemIds($page = NULL) { \Drupal::logger('test_external_datasource')->debug('getitemids - @page', ['@page'=> print_r($page, TRUE) ]); // Hardcoded dummy IDs $all_ids = ['chainsaw_ferret_1', 'chainsaw_ferret_2']; // Only return on page 0 for proof-of-concept if ($page === 0 || $page === NULL) { return $all_ids; } return []; } public function getTotalItemsCount() { return 2; // Hardcoded to the two dummy records } /** * {@inheritdoc} */ public function getItemId($item) { \Drupal::logger('test_external_datasource')->debug('getItemId called for item: @item', ['@item' => print_r($item, TRUE)]); if (is_object($item) && method_exists($item, 'getId')) { return $item->getId(); } return $item; } /** * {@inheritdoc} */ public function getItem($item_id) { \Drupal::logger('test_external_datasource')->debug('getItem called for @id', ['@id' => $item_id]); $item = new Item($this->getPluginId(), $item_id); $label = ($item_id === 'chainsaw_ferret_1') ? 'Chainsaw Ferret Alpha: The legend begins' : 'Chainsaw Ferret Beta: The sequel nobody asked for'; $description = 'This is a dummy external record about chainsaw-wielding ferrets.'; $item->setField('label', Field::createByDatasource($this->getPluginId(), 'label')->addValue($label)); $item->setField('description', Field::createByDatasource($this->getPluginId(), 'description')->addValue($description)); return $item; } /** * {@inheritdoc} */ public function getPropertyDefinitions(ItemInterface $item = NULL) { return [ 'label' => DataDefinition::create('string')->setLabel(t('Label')), 'description' => DataDefinition::create('string')->setLabel(t('Description')), ]; } } All it should be doing is adding two items to the index. That's it. But when I turn the plug in on, it seems to get caught in an endless loop. Checking my logs, I see that the logger in getItemIds is getting called multiple times, and that the pager is continually incrementing. It got up to getitemids - 178289 before I shut it off. That's way more content than is on this test site. I'm not sure how to stop it. I tried making sure the getItemIds returns a null set so maybe the search API dosn't think there's more content and keeps trying to track it. I also tried implementing getTotalItemCount to make sure it stops after two itmes. Nothing seems to work, and I can't figure out how get it to stop looping.
print_r?