public function Solr::parseFile in Search API Synonym 8
Parse the import file.
Parameters
\Drupal\file\Entity\File $file: The temporary file object.
array $settings: Array with plugin settings.
Return value
string The parsed file content.
Overrides ImportPluginBase::parseFile
File
- src/
Plugin/ search_api_synonym/ import/ Solr.php, line 26
Class
- Solr
- Import of Solr synonyms.txt files.
Namespace
Drupal\search_api_synonym\Plugin\search_api_synonym\importCode
public function parseFile(File $file, array $settings = []) {
$data = [];
// Read file.
$rows = file($file
->getFileUri());
if (is_array($rows)) {
foreach ($rows as $row) {
$row = trim($row);
// Skip comment lines
if (empty($row) || substr($row, 0, 1) == '#') {
continue;
}
$parts = explode('=>', $row);
// Spelling error.
if (count($parts) == 2) {
$data[] = [
'word' => trim($parts[0]),
'synonym' => trim($parts['1']),
'type' => 'spelling_error',
];
}
else {
$data[] = [
'word' => trim(substr($row, 0, strpos($row, ','))),
'synonym' => trim(substr($row, strpos($row, ',') + 1)),
'type' => 'synonym',
];
}
}
}
return $data;
}