Skip to content

Commit

Permalink
Remove copy field feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung committed Jun 4, 2024
1 parent 9bf3cee commit 000048b
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions plugins/arSolrPlugin/lib/arSolrPlugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,10 @@ protected function initialize()
arSolrPlugin::makeHttpRequest($url);

$addFieldQuery = '';
$addCopyFieldQuery = '';

// Add fields to 'all' field
$q = $this->getFieldQuery('all', 'text_general', true, false, false);
$addFieldQuery .= $q[0];
$addCopyFieldQuery .= $q[1];

$url = $this->solrBaseUrl.'/api/collections/'.$this->solrClientOptions['collection'].'/config/';
$updateDefaultHandler = '{"update-requesthandler": {"name": "/select", "class": "solr.SearchHandler", "defaults": {"df": "all", "echoParams": "explicit"}}}';
Expand All @@ -358,17 +356,14 @@ protected function initialize()
$typeName = 'Qubit'.sfInflector::camelize($typeName);

foreach ($typeProperties['properties'] as $key => $value) {
$includeInCopy = $value['include_in_all'] ? $value['include_in_all'] : true;
if (null != $value['type'] && 'nested' !== $value['type'] && 'object' !== $value['type']) {
$q = $this->getFieldQuery($key, $this->setType($value['type']), false, $includeInCopy);
$q = $this->getFieldQuery($key, $this->setType($value['type']), false);
$addFieldQuery .= $q[0];
$addCopyFieldQuery .= $q[1];
} else {
if (null === $value['type']) {
// array fields
$q = $this->getFieldQuery($key, '_nest_path_', true);
$addFieldQuery .= $q[0];
$addCopyFieldQuery .= $q[1];
$this->addNestedFields($key, $value['properties']);
} else {
// object and nested fields
Expand All @@ -377,15 +372,13 @@ protected function initialize()
if ('object' === $value['type']) {
foreach ($value['properties'] as $k => $v) {
$fields .= '"'.$k.':/'.$key.'/'.$k.'",';
$q = $this->getFieldQuery($k, $this->setType($v['type']), false, $includeInCopy);
$q = $this->getFieldQuery($k, $this->setType($v['type']), false);
$addFieldQuery .= $q[0];
$addCopyFieldQuery .= $q[1];
}
} elseif (null != $value['type']) {
$fields .= '"'.$key.':/'.$key.'",';
$q = $this->getFieldQuery($key, $this->setType($value['type']), false, $includeInCopy);
$q = $this->getFieldQuery($key, $this->setType($value['type']), false);
$addFieldQuery .= $q[0];
$addCopyFieldQuery .= $q[1];
}
}
$fields = rtrim($fields, ',').']';
Expand All @@ -396,8 +389,7 @@ protected function initialize()
}

$addFieldQuery = rtrim($addFieldQuery, ',');
$addCopyFieldQuery = rtrim($addCopyFieldQuery, ',');
$addQuery = '{"add-field":['.$addFieldQuery.'],"add-copy-field":['.$addCopyFieldQuery.']}';
$addQuery = '{"add-field":['.$addFieldQuery.']}';

$this->addFieldsToType($addQuery);
}
Expand All @@ -409,8 +401,7 @@ private function addNestedFields($key, $properties)
if (null === $v['type']) {
$this->addNestedFields($k, $v['properties']);
} else {
$includeInCopy = $v['include_in_all'] ? $v['include_in_all'] : true;
$this->getFieldQuery($key.'.'.$k, $this->setType($v['type']), false, $includeInCopy);
$this->getFieldQuery($key.'.'.$k, $this->setType($v['type']), false);
}
}
}
Expand Down Expand Up @@ -446,17 +437,14 @@ private function setType($type)
return $type;
}

private function getFieldQuery($field, $type, $multiValue, $stored = true, $includeInCopy = true)
private function getFieldQuery($field, $type, $multiValue, $stored = true)
{
$stored = $stored ? 'true' : 'false';
$multiValue = $multiValue ? 'true' : 'false';
$addFieldQuery = '{"name": "'.$field.'","stored": "'.$stored.'","type": "'.$type.'","indexed": "true","multiValued": "'.$multiValue.'"},';
if ($includeInCopy) {
$addCopyFieldQuery = '{"source": "'.$field.'", "dest": "all"},';
}
$this->log(sprintf('Defining mapping %s...', $field));

return [$addFieldQuery.$addCopyFieldQuery];
return $addFieldQuery;
}

private function addFieldsToType($query)
Expand Down

0 comments on commit 000048b

Please sign in to comment.