Skip to content

Commit

Permalink
Update mapping config params.
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung committed Jun 12, 2024
1 parent f73336f commit f74b148
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions plugins/arSolrPlugin/lib/arSolrPlugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ protected function initialize()
arSolrPlugin::makeHttpRequest($url);

$addFieldQuery = [];
$configParams = [];

// Add fields to 'all' field
//array_push($addFieldQuery, $this->getFieldQuery('all', 'text_general', true, false, false));
Expand All @@ -364,27 +365,39 @@ protected function initialize()
$this->addNestedFields($subType, $value['properties']);
} else {
// object and nested fields
$fields = '[';
$fields = [];
foreach ($value['properties'] as $fieldName => $value) {
if ('object' === $value['type']) {
foreach ($value['properties'] as $propertyName => $v) {
$fields .= '"'.$subType.':/'.$fieldName.'/'.$propertyName.'",';
array_push($fields, '"'.$subType.':/'.$fieldName.'/'.$propertyName.'"');
array_push($addFieldQuery, $this->getFieldQuery($propertyName, $this->setType($v['type']), false));
}
} elseif (null != $value['type']) {
$fields .= '"'.$subType.':/'.$fieldName.'",';
array_push($fields, '"'.$subType.':/'.$fieldName.'"');
array_push($addFieldQuery, $this->getFieldQuery($fieldName, $this->setType($value['type']), false));
}
}
$fields = rtrim($fields, ',').']';
$this->defineConfigParams($subType, $fields);

if (array_key_exists($subType, $configParams)) {
foreach ($fields as $field) {
if (!in_array($field, $configParams[$subType])) {
array_push($configParams[$subType], $field);
}
}
} else {
$configParams[$subType] = $fields;
}
}
}
}
}

$addQuery = ['add-field' => $addFieldQuery];

foreach($configParams as $param => $value) {
$this->defineConfigParams($param, $value);
}

$this->addFieldsToType(json_encode($addQuery));
}
}
Expand All @@ -405,7 +418,7 @@ private function defineConfigParams($name, $fields)
$this->log('--- Config params: '.$name.'---');
$this->log(print_r($fields, true));
$url = $this->solrBaseUrl.'/solr/'.$this->solrClientOptions['collection'].'/config/params';
$query = '"set": {"'.$name.'": {"split": "/'.$name.'", "f":'.$fields.'}}';
$query = '"set": {"'.$name.'": {"split": "/'.$name.'", "f":['.implode(',', $fields).']}}';
arSolrPlugin::makeHttpRequest($url, 'POST', $query);
}

Expand Down Expand Up @@ -451,7 +464,7 @@ private function getFieldQuery($field, $type, $multiValue, $stored = true)

private function addFieldsToType($query)
{
$this->log('Adding fields now');
$this->log("Adding fields now");
$this->log($query);
$url = $this->solrBaseUrl.'/solr/'.$this->solrClientOptions['collection'].'/schema/';
arSolrPlugin::makeHttpRequest($url, 'POST', $query);
Expand Down

0 comments on commit f74b148

Please sign in to comment.