moodle/moodle · error · core_search\engine_exception

multivaluedfield

multivaluedfield

Error message

multivaluedfield

What it means

core_search\document::__construct rejects documents whose field values came back from the search engine as PHP arrays. Solr supports multivalued fields, but Moodle's search document model only supports scalar values, so when importing a document from the engine an array value makes the document impossible to represent and engine_exception('multivaluedfield') is thrown, naming the offending field as the debuginfo.

Solutions

  1. Check the Solr schema for the field named in the debuginfo and set multivalued=false for fields Moodle expects scalar (match public/search/engine/solr/classes/schema.php definitions).
  2. Fix the search area's get_document/get_record_for_document so it stores a scalar (join array into a string) instead of an array.
  3. Reindex the affected area after fixing schema so stored values are scalar.
  4. If you need multivalue data, store it in a separate dedicated field or handle it before the document is constructed.

Example fix

// before (search area)
$docdata['tags'] = $tags; // array
// after
$docdata['tags'] = implode(', ', $tags);
Defensive patterns

Strategy: validation

Validate before calling

foreach ($docdata as $name => $value) {
    if (is_array($value) && $name !== 'id') {
        $docdata[$name] = implode(', ', array_map('strval', $value));
    }
}

Type guard

function is_scalar_field_value($value): bool {
    return is_string($value) || is_int($value) || is_float($value) || is_bool($value) || $value === null;
}

Try / catch

try {
    $doc = $searchmanager->get_document($accessinfo, $resultdata);
} catch (\core_search\engine_exception $e) {
    if ($e->errorcode === 'multivaluedfield') {
        debugging("Multivalued field {$e->debuginfo} returned by engine; skipping document.");
        $doc = null;
    } else {
        throw $e;
    }
}

Prevention

When it happens

Trigger: Called when a search area document is rehydrated from engine results (manager->get_document / engine get_document path) and $docdata[$fieldname] is_array() for a non-tdate field — i.e. the Solr schema defines that field as multivalued or the indexed value was stored as an array.

Common situations: Custom Solr schema edits marking fields multivalued=true; a search area indexing array values (e.g. tags, role lists) into a field; schema drift between Moodle's expected solr schema and the actual collection schema; upgrading Solr or the plugin so field definitions diverge.

Related errors


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/7d52184af1494daa. Report an issue: GitHub.

Appendix: source

Thrown at public/search/classes/document.php:479

     * Fills the document with data coming from the search engine.
     *
     * @throws \core_search\engine_exception
     * @param array $docdata
     * @return void
     */
    public function set_data_from_engine($docdata) {
        $fields = static::$requiredfields + static::$optionalfields + static::$enginefields;
        foreach ($fields as $fieldname => $field) {

            // Optional params might not be there.
            if (isset($docdata[$fieldname])) {
                if ($field['type'] === 'tdate') {
                    // Time fields may need a preprocessing.
                    $this->set($fieldname, static::import_time_from_engine($docdata[$fieldname]));
                } else {
                    // No way we can make this work if there is any multivalue field.
                    if (is_array($docdata[$fieldname])) {
                        throw new \core_search\engine_exception('multivaluedfield', 'search_solr', '', $fieldname);
                    }
                    $this->set($fieldname, $docdata[$fieldname]);
                }
            }
        }
    }

    /**
     * Sets the document url.
     *
     * @param \moodle_url $url
     * @return void
     */
    public function set_doc_url(\moodle_url $url) {
        $this->docurl = $url;
    }

    /**

View on GitHub (pinned to 48ea8c3322)