Skip to content

Commit

Permalink
Add defineConfigParams (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung committed Jun 19, 2024
1 parent ca14a5b commit 3d605c3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions plugins/arSolrPlugin/lib/arSolrPlugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,6 @@ protected function initialize()
$url = $this->solrBaseUrl.'/solr/admin/collections?action=CREATE&name='.$this->solrClientOptions['collection'].'&numShards=2&replicationFactor=1&wt=json';
arSolrPlugin::makeHttpRequest($url);

$addFieldKeys = [];
$configParams = [];

$topLevelProperties = [];
$subProperties = [];

Expand All @@ -360,6 +357,7 @@ protected function initialize()
array_push($topLevelProperties, $this->getFieldQuery($typeName, $this->setType('_nest_path_'), true));

$this->addSubProperties($typeProperties['properties'], $subProperties, $typeName);
$this->defineConfigParams($typeProperties['properties'], $typeName);
}

$addQuery = ['add-field' => $topLevelProperties];
Expand Down Expand Up @@ -389,10 +387,17 @@ private function addSubProperties($properties, &$propertyFields, $parentType = '
}
}

private function defineConfigParams($name, $fields)
private function defineConfigParams($properties, $parentType = '')
{
$paramFields = [];
foreach ($properties as $propertyName => $value) {
$fieldName = $parentType ? "{$parentType}.{$propertyName}" : $propertyName;
$fields = explode('.', $fieldName);
array_push($paramFields, sprintf('"%s:/%s"', $fields[count($fields) - 1], str_replace('.', '/', $fieldName)));
}

$url = $this->solrBaseUrl.'/solr/'.$this->solrClientOptions['collection'].'/config/params';
$query = '"set": {"'.$name.'": {"split": "/'.$name.'", "f":['.implode(',', $fields).']}}';
$query = '"set": {"'.$parentType.'": {"split": "/'.$parentType.'", "f":['.implode(',', $paramFields).']}}';
arSolrPlugin::makeHttpRequest($url, 'POST', $query);
}

Expand Down

0 comments on commit 3d605c3

Please sign in to comment.