Commit fb4b8faf authored by Adam Bramley's avatar Adam Bramley Committed by Kim Pepper
Browse files

Issue #3271337 by acbramley, larowlan: Add native support for n-gram and edge n-gram

parent 9b8557e8
Loading
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -4,6 +4,10 @@ services:
    class: Drupal\search_api_opensearch\Connector\ConnectorPluginManager
    parent: default_plugin_manager

  plugin.manager.search_api_opensearch.analyser:
    class: Drupal\search_api_opensearch\Analyser\AnalyserManager
    parent: default_plugin_manager

  logger.channel.search_api_opensearch:
    parent: logger.channel_base
    arguments: [ 'search_api_opensearch' ]
@@ -54,3 +58,4 @@ services:
      - '@search_api.fields_helper'
      - '@search_api_opensearch.field_mapper'
      - '@logger.channel.search_api_opensearch'
      - '@plugin.manager.search_api_opensearch.analyser'
+86 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\search_api_opensearch\Analyser;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginBase;

/**
 * Defines a base class for analyser plugins.
 */
abstract class AnalyserBase extends PluginBase implements AnalyserInterface {

  /**
   * {@inheritdoc}
   */
  public function getLabel(): string {
    return $this->getPluginDefinition()['label'];
  }

  /**
   * {@inheritdoc}
   */
  public function getSettings(): array {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration(): array {
    return $this->configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration): self {
    $this->configuration = $configuration;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration(): array {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state): array {
    return [];
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state): void {
    // Nil op.
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state): void {
    // Nil op.
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginId(): string {
    return $this->pluginId;
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginDefinition(): array {
    return $this->pluginDefinition;
  }

}
 No newline at end of file
+33 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\search_api_opensearch\Analyser;

use Drupal\Component\Plugin\ConfigurableInterface;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Plugin\PluginFormInterface;
use OpenSearch\Client;

/**
 * Defines an interface for analyser plugins.
 */
interface AnalyserInterface extends PluginFormInterface, ConfigurableInterface, PluginInspectionInterface {

  /**
   * Gets the analyser label.
   *
   * @return string
   *   The label.
   */
  public function getLabel(): string;

  /**
   * Gets the analyser settings.
   *
   * @return array
   *   Analyser settings.
   */
  public function getSettings(): array;

}
 No newline at end of file
+34 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\search_api_opensearch\Analyser;

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\search_api_opensearch\Annotation\OpenSearchAnalyser;

/**
 * Defines a plugin manager for analyser plugins.
 */
final class AnalyserManager extends DefaultPluginManager {

  /**
   * Constructs a AnalyserManager object.
   *
   * @param \Traversable $namespaces
   *   An object that implements \Traversable which contains the root paths
   *   keyed by the corresponding namespace to look for plugin implementations.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
   *   Cache backend instance to use.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler to invoke the alter hook with.
   */
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
    $this->alterInfo('opensearch_analyser_info');
    $this->setCacheBackend($cache_backend, 'opensearch_analyser_plugins');

    parent::__construct('Plugin/OpenSearch/Analyser', $namespaces, $module_handler, AnalyserInterface::class, OpenSearchAnalyser::class);
  }
}
 No newline at end of file
+27 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\search_api_opensearch\Annotation;

use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;

/**
 * Defines an annotation for open search analyser plugins.
 *
 * @Annotation
 */
final class OpenSearchAnalyser extends Plugin {

  /**
   * Plugin ID.
   */
  public string $id;

  /**
   * Plugin label.
   */
  public string|Translation $label;

}
 No newline at end of file
Loading