I’m using latest version of SearchAPI (1.18) and SearchAPI Solr (4.1.10).
I’ve a custom field that I want to have multiple values (I use it for faceted search with Facets module). In the previous version of SearchAPI the second example worked.
If I use this code, SearchAPI save "Array" as value:
<?php namespace Drupalarchivio_utilsPluginsearch_apiprocessor; use Drupalsearch_apiDatasourceDatasourceInterface; use Drupalsearch_apiItemItemInterface; use Drupalsearch_apiProcessorProcessorPluginBase; use Drupalsearch_apiProcessorProcessorProperty; /** * * @SearchApiProcessor( * id = "periodo", * label = @Translation("Periodo"), * description = @Translation("Periodo"), * stages = { * "add_properties" = 0, * }, * locked = true, * hidden = false, * ) */ class Periodo extends ProcessorPluginBase { /** * {@inheritdoc} */ public function getPropertyDefinitions(DatasourceInterface $datasource = NULL) { $properties = []; if (!$datasource) { $definition = [ 'label' => $this->t('Periodo'), 'description' => $this->t('Periodo'), 'type' => 'string', 'processor_id' => $this->getPluginId(), ]; $properties['search_api_persona_periodo'] = new ProcessorProperty($definition); } return $properties; } /** * {@inheritdoc} */ public function addFieldValues(ItemInterface $item) { $entity = $item->getOriginalObject()->getValue(); /* @var DrupalnodeEntityNode $entity */ /* @var DrupalnodeEntityNode $carriera */ if ($entity->bundle() == 'persona') { $fields = $this->getFieldsHelper() ->filterForPropertyPath($item->getFields(), NULL, 'search_api_persona_periodo'); foreach ($fields as $field) { if (!$field->getDatasourceId()) { $values[] = 'test1'; $values[] = 'test2'; $field->addValue($values); } } } } }
If I replace code where I wrote values with this:
$values[] = 'test1'; $values[] = 'test2'; foreach ($values as $value) { $field->addValue($value); }
I obtain this error:
[error] Drupalsearch_api_solrSearchApiSolrException while indexing item entity:node/10008:it: Solr endpoint http://solr:8983/ bad request (400). ERROR: [doc=3igm00-archivio_indice-entity:node/10008:it] multiple values encountered for non multiValued field ss_persona_periodo: [test1, test1] in Drupalsearch_api_solrSolrConnectorSolrConnectorPluginBase->handleHttpException() (line 1016 of /var/www/html/web/modules/contrib/search_api_solr/src/SolrConnector/SolrConnectorPluginBase.php).
How can I add multiple values to this custom field?