Skip to content

Commit

Permalink
Add Diacritics to analyzers WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung committed Jul 18, 2024
1 parent 7116e2d commit 4f27337
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions plugins/arSolrPlugin/lib/arSolrPlugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function loadDiacriticsMappings()
throw new sfException('You must create a diacritics_mapping.yml file.');
}

return sfYaml::load(array_shift($diacriticsFiles));
return $diacriticsFiles;
}

public function flush()
Expand Down Expand Up @@ -283,9 +283,6 @@ public static function makeHttpRequest($url, $method = 'GET', $body = null)
*/
protected function initialize()
{
if (sfConfig::get('app_diacritics')) {
$this->config['index']['configuration']['analysis']['char_filter']['diacritics_lowercase'] = $this->loadDiacriticsMappings();
}
$url = $this->solrBaseUrl.'/solr/admin/collections?action=LIST';
$response = arSolrPlugin::makeHttpRequest($url);

Expand Down Expand Up @@ -490,12 +487,9 @@ private function getFieldQuery($field, $type, $multiValue, $stored = true)
private function setAnalyzers()
{
foreach ($this->config['index']['configuration']['analysis']['analyzer'] as $key => $analyzer) {
$charFilters = [];
$filters = [];
if (sfConfig::get('app_diacritics')) {
$filters = array_push($filters, ['class' => 'diacritics_lowercase']);
}

$charFilters = [];
foreach ($this->config['index']['configuration']['analysis']['char_filter'] as $charFilter) {
array_push($charFilters, $charFilter);
}
Expand All @@ -504,6 +498,14 @@ private function setAnalyzers()
array_push($filters, $this->config['index']['configuration']['analysis']['filter'][$filter]);
}

if (sfConfig::get('app_diacritics')) {
$diacritics = $this->loadDiacriticsMappings();
array_push($charFilters, [
'class' => 'solr.MappingCharFilterFactory',
'mapping' => $diacritics[0],
]);
}

$query = ['replace-field-type' => [
'name' => $key,
'class' => 'solr.TextField',
Expand Down

0 comments on commit 4f27337

Please sign in to comment.