Skip to content

Commit

Permalink
Update autoComplete
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung committed Jul 8, 2024
1 parent f8aaf91 commit b108777
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions plugins/arSolrPlugin/lib/arSolrPlugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public function populate($options = [])
}
}

$this->addAutoCompleteConfigs();

$this->log(
vsprintf(
'Index populated with %s documents in %s seconds.',
Expand Down Expand Up @@ -319,11 +321,11 @@ protected function initialize()
$addQuery = ['add-field' => $subProperties];
$this->addFieldsToType(json_encode($addQuery));

$this->addAutoComplete();
$this->addAutoCompleteFields();
}
}

private function addAutoComplete()
private function addAutoCompleteFields()
{
// list should also include QubitInformationObject.referenceCode but
// since this field does not include a language code, it is added to
Expand All @@ -339,6 +341,20 @@ private function addAutoComplete()
'QubitAip.type.i18n.en.name',
];

foreach ($this->langs as $lang) {
$addCopyField = '{"add-field":{"name":"autocomplete_'.$lang.'","type":"text_'.$lang.'","stored":true},';
$copyField = '"add-copy-field":{"source":"QubitInformationObject.referenceCode","dest":"autocomplete_'.$lang.'"},';
foreach ($autocompleteFields as $field) {
$field = str_replace('en', $lang, $field);
$copyField .= '"add-copy-field":{"source":"'.$field.'","dest":"autocomplete_'.$lang.'"},';
}
$addCopyField .= substr($copyField, 0, -1).'}';
$url = $this->solrBaseUrl.'/api/collections/'.$this->solrClientOptions['collection'].'/schema/';
arSolrPlugin::makeHttpRequest($url, 'POST', $addCopyField);
}
}

private function addAutoCompleteConfigs() {
foreach ($this->langs as $lang) {
$url = $this->solrBaseUrl.'/api/collections/'.$this->solrClientOptions['collection'].'/config/';
$addSearchComponent = '{
Expand All @@ -347,6 +363,7 @@ private function addAutoComplete()
"class":"solr.SuggestComponent",
"suggester":{
"name":"autocomplete_'.$lang.'",
"field":"autocomplete_'.$lang.'",
"lookupImpl":"FuzzyLookupFactory",
"dictionaryImpl":"DocumentDictionaryFactory",
"suggestAnalyzerFieldType":"text_'.$lang.'"
Expand All @@ -367,16 +384,6 @@ private function addAutoComplete()
}';
arSolrPlugin::makeHttpRequest($url, 'POST', $addSearchComponent);
arSolrPlugin::makeHttpRequest($url, 'POST', $addRequestHandler);

$addCopyField = '{"add-field":{"name":"autocomplete_'.$lang.'","type":"text_'.$lang.'","stored":true},';
$copyField = '"add-copy-field":{"source":"QubitInformationObject.referenceCode","dest":"autocomplete_'.$lang.'"},';
foreach ($autocompleteFields as $field) {
$field = str_replace('en', $lang, $field);
$copyField .= '"add-copy-field":{"source":"'.$field.'","dest":"autocomplete_'.$lang.'"},';
}
$addCopyField .= substr($copyField, 0, -1).'}';
$url = $this->solrBaseUrl.'/api/collections/'.$this->solrClientOptions['collection'].'/schema/';
arSolrPlugin::makeHttpRequest($url, 'POST', $addCopyField);
}
}

Expand Down

0 comments on commit b108777

Please sign in to comment.