@@ -0,0 +1,1504 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%0A__author__ = 'Armando Guereca'%0A%0Aclass ScriptFields:%0A    _internal_name = %22script_fields%22%0A    %22%22%22%0A    This object create the script_fields definition%0A    %22%22%22%0A    def __init__(self, field_name, script, params = None):%0A        self.fields=%7B%7D%0A        self.add_field(field_name, script, params or %7B%7D)%0A    %0A    def add_field(self, field_name, script, params = None):%0A        %22%22%22%0A        Add a field to script_fields%0A        %22%22%22%0A        data = %7B%7D%0A        if script:%0A            data%5B'script'%5D = script%0A        else:%0A            raise ScriptFieldsError(%22Script is required for script_fields definition%22)%0A        if params:%0A            if isinstance(params, dict):%0A                if len(params):%0A                    data%5B'params'%5D = params%0A            else:%0A                raise ScriptFieldsError(%22Parameters should be a valid dictionary%22)        %0A                %0A        self.fields%5Bfield_name%5D = data%0A    %0A    def add_parameter(self, field_name, param_name, param_value):%0A        %22%22%22%0A        Add a parameter to a field into script_fields%0A        %0A        The ScriptFields object will be returned, so calls to this can be chained.%0A        %22%22%22%0A        try:%0A            self.fields%5Bfield_name%5D%5B'params'%5D%5Bparam_name%5D = param_value%0A        except Exception as ex:%0A            raise ScriptFieldsError(%22Error adding parameter %25s with value %25s :%25s%22 %25 (param_name,param_value,ex))%0A        %0A        return self%0A%0A    def serialize(self):       %0A        return self.fields%0A

Add ScriptFields object used as parameter script_fields of Search object