Solr.php in Search API Synonym 8
File
src/Plugin/search_api_synonym/export/Solr.php
View source
<?php
namespace Drupal\search_api_synonym\Plugin\search_api_synonym\export;
use Drupal\search_api_synonym\Export\ExportPluginBase;
use Drupal\search_api_synonym\Export\ExportPluginInterface;
class Solr extends ExportPluginBase implements ExportPluginInterface {
public function getFormattedSynonyms(array $synonyms) {
$lines = [];
$lines[] = "#";
$lines[] = "# Synonyms file for Apache Solr generated by Search API Synonym.";
$lines[] = "# See file https://www.drupal.org/project/search_api_synonym.";
$lines[] = "#";
$lines[] = "";
foreach ($synonyms as $synonym) {
$lines[] = $this
->generateLine($synonym->word, $synonym->synonyms, $synonym->type);
}
return implode("\n", $lines);
}
private function generateLine($word, $synonyms, $type) {
$line = '';
switch ($type) {
case 'synonym':
$line = "{$word}, {$synonyms}";
break;
case 'spelling_error':
$line = "{$word} => {$synonyms}";
break;
}
return $line;
}
}
Classes
Name |
Description |
Solr |
Provides a synonym export plugin for Apache Solr.. |