protected function add_fields($fields, $checkexisting = true) {

        if ($checkexisting) {
            // Check that non of them exists.
            $this->validate_fields($fields, false);
        }

        $url = $this->engine->get_connection_url('/schema');

        // Add all fields.
        foreach ($fields as $fieldname => $data) {

            if (!isset($data['type']) || !isset($data['stored']) || !isset($data['indexed'])) {
                throw new \coding_exception($fieldname . ' does not define all required field params: type, stored and indexed.');
            }
            $type = $this->doc_field_to_solr_field($data['type']);

            // Changing default multiValued value to false as we want to match values easily.
            $params = array(
                'add-field' => array(
                    'name' => $fieldname,
                    'type' => $type,
                    'stored' => $data['stored'],
                    'multiValued' => false,
                    'indexed' => $data['indexed']
                )
            );
            $results = $this->curl->post($url, json_encode($params));

            // We only validate if we are interested on it.
            if ($checkexisting) {
                if ($this->curl->error) {
                    throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $this->curl->error);
                }
                $this->validate_add_field_result($results);
            }
        }

        return true;
    }
protected function add_fields($fields, $checkexisting = true) {

        if ($checkexisting) {
            // Check that non of them exists.
            $this->validate_fields($fields, false);
        }

        $url = $this->engine->get_connection_url('/schema');

        // Add all fields.
        foreach ($fields as $fieldname => $data) {

            if (!isset($data['type']) || !isset($data['stored']) || !isset($data['indexed'])) {
                throw new \coding_exception($fieldname . ' does not define all required field params: type, stored and indexed.');
            }
            $type = $this->doc_field_to_solr_field($data['type']);

            // Changing default multiValued value to false as we want to match values easily.
            $params = array(
                'add-field' => array(
                    'name' => $fieldname,
                    'type' => $type,
                    'stored' => $data['stored'],
                    'multiValued' => false,
                    'indexed' => $data['indexed']
                )
            );
            $results = $this->curl->post($url, json_encode($params));

            // We only validate if we are interested on it.
            if ($checkexisting) {
                if ($this->curl->error) {
                    throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $this->curl->error);
                }
                $this->validate_add_field_result($results);
            }
        }

        return true;
    }
protected function add_fields ( $ fields , $ checkexisting = true ) { if ( $ checkexisting ) { // Check that non of them exists. $ this -> validate_fields ( $ fields , false ) ; } $ url = $ this -> engine -> get_connection_url ( '/schema' ) ; // Add all fields. foreach ( $ fields as $ fieldname => $ data ) { if ( ! isset ( $ data [ 'type' ] ) || ! isset ( $ data [ 'stored' ] ) || ! isset ( $ data [ 'indexed' ] ) ) { throw new \ coding_exception ( $ fieldname . ' does not define all required field params: type, stored and indexed.' ) ; } $ type = $ this -> doc_field_to_solr_field ( $ data [ 'type' ] ) ; // Changing default multiValued value to false as we want to match values easily. $ params = array ( 'add-field' => array ( 'name' => $ fieldname , 'type' => $ type , 'stored' => $ data [ 'stored' ] , 'multiValued' => false , 'indexed' => $ data [ 'indexed' ] ) ) ; $ results = $ this -> curl -> post ( $ url , json_encode ( $ params ) ) ; // We only validate if we are interested on it. if ( $ checkexisting ) { if ( $ this -> curl -> error ) { throw new \ moodle_exception ( 'errorcreatingschema' , 'search_solr' , '' , $ this -> curl -> error ) ; } $ this -> validate_add_field_result ( $ results ) ; } } return true ; }
Adds the provided fields to Solr schema.

Intentionally separated from create(), it can be called to add extra fields.
fields separately.

@throws \coding_exception
@throws \moodle_exception
@param  array $fields \core_search\document::$requiredfields format
@param  bool $checkexisting Whether to check if the fields already exist or not
@return bool
Adds the provided fields to Solr schema .