/**
  * @return mixed an HTTP response, or
  */
 public function configureAction()
 {
     if (null !== ($response = $this->checkAuth(AdminResources::MODULE, 'OpenSearchServerSearch', AccessManager::UPDATE))) {
         return $response;
     }
     // Initialize the potential error message, and the potential exception
     $error_msg = $ex = null;
     // Create the Form from the request
     $configurationForm = new ConfigurationForm($this->getRequest());
     try {
         // Check the form against constraints violations
         $form = $this->validateForm($configurationForm, "POST");
         // Get the form field values
         $data = $form->getData();
         foreach ($data as $name => $value) {
             if (is_array($value)) {
                 $value = implode(';', $value);
             }
             OpenSearchServerConfigQuery::set($name, $value);
         }
         //get handle to work with the API
         $oss_api = OpenSearchServerSearchHelper::getHandler();
         //check if index exists, if not, creates it
         $index = OpensearchserverConfigQuery::read('index_name');
         $indexCreated = false;
         $request = new \OpenSearchServer\Index\Exists();
         $request->index($index);
         $response = $oss_api->submit($request);
         //index doesn't exist, create it
         if (!$response->isSuccess()) {
             $this->createIndex($index);
             $indexCreated = true;
         }
         //check if Analyzer "PriceAnalyzer" exists, create it if it doesn't
         $analyzerName = 'PriceAnalyzer';
         $request = new \OpenSearchServer\Analyzer\Get();
         $request->index($index)->name($analyzerName);
         $response = $oss_api->submit($request);
         if (!$response->isSuccess()) {
             $this->createAnalyzer($index, $analyzerName);
         }
         //if index has just been created, create its schema
         if ($indexCreated) {
             $this->createSchema($index);
         }
         //check if query template exists, if not, creates it
         $queryTemplate = OpensearchserverConfigQuery::read('query_template');
         $request = new \OpenSearchServer\SearchTemplate\Get();
         $request->index($index)->name($queryTemplate);
         $response = $oss_api->submit($request);
         if (!$response->isSuccess()) {
             $this->createQueryTemplate($index, $queryTemplate);
         }
         // Log configuration modification
         $this->adminLogAppend("opensearchserversearch.configuration.message", AccessManager::UPDATE, sprintf("OpenSearchServer configuration updated"));
         // Redirect to the success URL,
         if ($this->getRequest()->get('save_mode') == 'stay') {
             // If we have to stay on the same page, redisplay the configuration page/
             $route = '/admin/module/OpenSearchServerSearch';
         } else {
             // If we have to close the page, go back to the module back-office page.
             $route = '/admin/modules';
         }
         //$this->getRequest()->getSession()->getFlashBag()->add('notice', $this->getTranslator()->trans('Settings have been saved.'));
         $this->getRequest()->getSession()->getFlashBag()->add('oss', $this->getTranslator()->trans('Settings have been saved.', [], OpenSearchServerSearch::MODULE_DOMAIN));
         $this->redirect(URL::getInstance()->absoluteUrl($route));
         exit;
     } catch (FormValidationException $ex) {
         // Form cannot be validated. Create the error message using
         // the BaseAdminController helper method.
         $error_msg = $this->createStandardFormValidationErrorMessage($ex);
     } catch (\Exception $ex) {
         // Any other error
         $error_msg = $ex->getMessage();
     }
     // At this point, the form has errors, and should be redisplayed. We don not redirect,
     // just redisplay the same template.
     // Setup the Form error context, to make error information available in the template.
     $this->setupFormErrorContext($this->getTranslator()->trans("OpenSearchServer configuration", [], OpenSearchServerSearch::MODULE_DOMAIN), $error_msg, $configurationForm, $ex);
     // Do not redirect at this point, or the error context will be lost.
     // Just redisplay the current template.
     return $this->renderTemplate();
 }