You are here

class SearchApiSubscriber in Search API Solr 4.x

Search API events subscriber.

Hierarchy

  • class \Drupal\search_api_solr\EventSubscriber\SearchApiSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of SearchApiSubscriber

1 string reference to 'SearchApiSubscriber'
search_api_solr.services.yml in ./search_api_solr.services.yml
search_api_solr.services.yml
1 service uses SearchApiSubscriber
search_api_solr.search_api_subscriber in ./search_api_solr.services.yml
Drupal\search_api_solr\EventSubscriber\SearchApiSubscriber

File

src/EventSubscriber/SearchApiSubscriber.php, line 11

Namespace

Drupal\search_api_solr\EventSubscriber
View source
class SearchApiSubscriber implements EventSubscriberInterface {

  /**
   * Adds the mapping to treat some Solr special fields as fulltext in views.
   *
   * @param \Drupal\search_api\Event\MappingViewsFieldHandlersEvent $event
   *   The Search API event.
   */
  public function onMappingViewsFieldHandlers($event) {
    $mapping =& $event
      ->getFieldHandlerMapping();
    $mapping['solr_text_omit_norms'] = $mapping['solr_text_suggester'] = $mapping['solr_text_unstemmed'] = $mapping['solr_text_wstoken'] = [
      'argument' => [
        'id' => 'search_api',
      ],
      'filter' => [
        'id' => 'search_api_fulltext',
      ],
      'sort' => [
        'id' => 'search_api',
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {

    // Workaround to avoid a fatal error during site install in some cases.
    // @see https://www.drupal.org/project/facets/issues/3199156
    if (!class_exists('\\Drupal\\search_api\\Event\\SearchApiEvents', TRUE)) {
      return [];
    }
    return [
      SearchApiEvents::MAPPING_VIEWS_FIELD_HANDLERS => 'onMappingViewsFieldHandlers',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SearchApiSubscriber::getSubscribedEvents public static function
SearchApiSubscriber::onMappingViewsFieldHandlers public function Adds the mapping to treat some Solr special fields as fulltext in views.