3 namespace Drupal\search_api_synonym\Plugin\search_api_synonym\export;
5 use Drupal\search_api_synonym\Export\ExportPluginBase;
6 use Drupal\search_api_synonym\Export\ExportPluginInterface;
9 * Provides a synonym export plugin for Apache Solr..
11 * @SearchApiSynonymExport(
13 * label = @Translation("Solr"),
14 * description = @Translation("Synonym export plugin for Apache Solr")
17 class Solr extends ExportPluginBase implements ExportPluginInterface {
22 public function getFormattedSynonyms(array $synonyms) {
26 $lines[] = "# Synonyms file for Apache Solr generated by Search API Synonym.";
27 $lines[] = "# See file https://www.drupal.org/project/search_api_synonym.";
31 // Generate a line for each synonym.
32 foreach ($synonyms as $synonym) {
33 $lines[] = $this->generateLine($synonym->word, $synonym->synonyms, $synonym->type);
36 return implode("\n", $lines);
40 * Generate a single synonyms line for the export file.
45 * @param string $synonyms
46 * The comma separated string with synonyms.
49 * Synonym (synonym) og Spelling error (spelling_error)
52 * Return the single line with synonyms and the corresponding word.
54 private function generateLine($word, $synonyms, $type) {
59 // We force using of equivalent mappings for type = synonym.
60 $line = "{$word}, {$synonyms}";
62 case 'spelling_error':
63 $line = "{$word} => {$synonyms}";