public function Search($Search, $Offset = 0, $Limit = 20)
 {
     $AllSettings = SphinxFactory::BuildSettings();
     $Settings = $AllSettings->GetAllSettings();
     // if (($Settings['Status']->SearchdRunning == 1) && ($Settings['Status']->EnableSphinxSearch == 1))
     if (true) {
         // Force this to be true while the sphinxsearch plugin is enabled!
         return FALSE;
     } else {
         // If there are no searches then return an empty array.
         if (trim($Search) == '') {
             return array();
         }
         // Figure out the exact search mode.
         if ($this->ForceSearchMode) {
             $SearchMode = $this->ForceSearchMode;
         } else {
             $SearchMode = strtolower(C('Garden.Search.Mode', 'matchboolean'));
         }
         if ($SearchMode == 'matchboolean') {
             if (strpos($Search, '+') !== FALSE || strpos($Search, '-') !== FALSE) {
                 $SearchMode = 'boolean';
             } else {
                 $SearchMode = 'match';
             }
         } else {
             $this->_SearchMode = $SearchMode;
         }
         $this->_SearchMode = $SearchMode;
         $this->FireEvent('Search');
         //print_r($this->_SearchSql);
         if (count($this->_SearchSql) == 0) {
             return array();
         }
         // Perform the search by unioning all of the sql together.
         $Sql = $this->SQL->Select()->From('_TBL_ s')->OrderBy('s.DateInserted', 'desc')->Limit($Limit, $Offset)->GetSelect();
         $Sql = str_replace($this->Database->DatabasePrefix . '_TBL_', "(\n" . implode("\nunion all\n", $this->_SearchSql) . "\n)", $Sql);
         $this->EventArguments['Search'] = $Search;
         $this->FireEvent('AfterBuildSearchQuery');
         if ($this->_SearchMode == 'like') {
             $Search = '%' . $Search . '%';
         }
         foreach ($this->_Parameters as $Key => $Value) {
             $this->_Parameters[$Key] = $Search;
         }
         $Result = $this->Database->Query($Sql, $this->_Parameters)->ResultArray();
         $this->Reset();
         $this->SQL->Reset();
         foreach ($Result as $Key => $Value) {
             if (isset($Value['Summary'])) {
                 $Value['Summary'] = Gdn_Format::Text(Gdn_Format::To($Value['Summary'], $Value['Format']));
                 $Result[$Key] = $Value;
             }
         }
         return $Result;
     }
 }
 /**
  * Force a manual install via distro or command line (Plugin CANNOT do install by itself)
  * @param type $InstallAction
  * @param type $Background
  * @param type $Service
  * @param type $Install
  */
 public function InstallAction($InstallAction, $Background, $Service, $Install)
 {
     $Detect = true;
     // For non-Wizard installs, simply detect TRUE to avoid webserver permissions
     if ($Detect) {
         //if they do, then save them at the REAL paths that are used by plugin (i.e strip off the 'Manual' prefix)
         parent::Update(SS_SUCCESS, 'IndexerPath', $this->Settings['Install']->IndexerPath);
         parent::Update(SS_SUCCESS, 'SearchdPath', $this->Settings['Install']->SearchdPath);
         parent::Update(SS_SUCCESS, 'ConfPath', $this->Settings['Install']->ConfPath);
         parent::Update(SS_SUCCESS, 'ConfText', $this->Settings['Install']->ConfText);
         //get new settings here since confpath has suddnely changed above
         $Settings = SphinxFactory::BuildSettings();
         $Service->NewSettings($Settings->GetAllSettings());
         //now get the existing PID/log/query_log paths to save in the new sphinx.conf from the exisitng sphinx.conf
         parent::Update(SS_SUCCESS, 'LogPath', $Service->GetSearchLog());
         parent::Update(SS_SUCCESS, 'QueryPath', $Service->GetQueryLog());
         parent::Update(SS_SUCCESS, 'PIDPath', $Service->GetPIDFileName());
         parent::Update(SS_SUCCESS, 'DataPath', $Service->GetDataPath());
     }
 }
 /**
  * Force a manual install via distro or command line (Plugin CANNOT do install by itself)
  * @param type $InstallAction
  * @param type $Background
  * @param type $Service
  * @param type $Install
  */
 public function InstallAction($InstallAction, $Background, $Service, $Install)
 {
     /**
      * Lets not detect the location of the indexer/searchd/sphinx.conf file. The webserver
      * must be given proper read/write permissions outside of the web root in order to detect
      * the prescense of sphinx (assuming installation is outside of the web root).
      */
     //            $Detect = $this->DetectProgram($ShowError = TRUE, array(
     //                'IndexerPath' => $this->Settings['Install']->IndexerPath,
     //                'SearchdPath' => $this->Settings['Install']->SearchdPath,
     //                'ConfPath' => $this->Settings['Install']->ConfPath,
     //                    ));
     $Detect = true;
     if ($Detect) {
         //if they do, then save them at the REAL paths that are used by plugin (i.e strip off the 'Manual' prefix)
         parent::Update(SS_SUCCESS, 'IndexerPath', $this->Settings['Install']->IndexerPath);
         parent::Update(SS_SUCCESS, 'SearchdPath', $this->Settings['Install']->SearchdPath);
         parent::Update(SS_SUCCESS, 'ConfPath', $this->Settings['Install']->ConfPath);
         parent::Update(SS_SUCCESS, 'ConfText', $this->Settings['Install']->ConfText);
         //get new settings here since confpath has suddnely changed above
         $Settings = SphinxFactory::BuildSettings();
         $Service->NewSettings($Settings->GetAllSettings());
         //now get the existing PID/log/query_log paths to save in the new sphinx.conf from the exisitng sphinx.conf
         parent::Update(SS_SUCCESS, 'LogPath', $Service->GetSearchLog());
         parent::Update(SS_SUCCESS, 'QueryPath', $Service->GetQueryLog());
         parent::Update(SS_SUCCESS, 'PIDPath', $Service->GetPIDFileName());
         parent::Update(SS_SUCCESS, 'DataPath', $Service->GetDataPath());
     }
 }
 public function GetSettings()
 {
     //return $this->Settings;
     $Setup = SphinxFactory::BuildSettings();
     return $Setup->GetAllSettings();
 }
 /**
  * main entry point for the install wizard
  * input parameters for wizard are in the $_GET buffer
  * @param type $Sender
  */
 public function Controller_InstallWizard($Sender)
 {
     include_once PATH_PLUGINS . DS . 'SphinxSearchLite' . DS . 'class.sphinxsearchinstallwizard.php';
     //include the install wizard
     $SphinxAdmin = SphinxFactory::BuildSphinx($Sender, $this->getview('wizard.php'));
     //SaveToConfig('Plugin.SphinxSearchLite.SearchdPath', '/usr/bin/sphinx-searchd');
     $Sender->SetData('PluginDescription', $this->GetPluginKey('Description'));
     $Sender->SetData('PluginVersion', $this->GetPluginKey('Version'));
     //create validation
     $Validation = new Gdn_Validation();
     $this->ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $this->ConfigurationModel->SetField(array());
     $Sender->Form->SetModel($this->ConfigurationModel);
     //set model on form
     $Sender->SetData('NextAction', 'Detection');
     $Sender->SetData('InstallSphinx', FALSE);
     $Sender->Form->SetData($this->ConfigurationModel->Data);
     $Sender->Form->InputPrefix = 'Configuration';
     //print_r($_POST); die;
     //Wizard State Machine (SM)
     if (GetIncomingValue('NextAction')) {
         SaveToConfig('Plugin.SphinxSearchLite.Config', TRUE);
         //next action
         $Sender->SetData('NextAction', 'Config');
     }
     if (GetIncomingValue('action') == 'ToggleWizard') {
         if (Gdn::Session()->ValidateTransientKey(GetValue(1, $Sender->RequestArgs))) {
             $SphinxAdmin->ToggleWizard();
             //stop/start wizard
             redirect('plugin/sphinxsearchlite/installwizard');
             //load the wizard page again
         }
     } else {
         if (isset($_POST[$this->PostPrefix . 'NextAction'])) {
             $Background = GetIncomingValue($this->PostPrefix . 'Background');
             switch ($_POST[$this->PostPrefix . 'NextAction']) {
                 case 'Detection':
                     $Sender->SetData('NextAction', 'Detection');
                     //in case it fails
                     // Don't detect anymore
                     // $SphinxAdmin->Detect();
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.Prefix', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.Port', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.Host', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.Port', 'Integer');
                     //PORT must be an int
                     if ($Sender->Form->Save()) {
                         //@todo don't check port just yet
                         $Sender->StatusMessage = T("Your changes have been saved.");
                         SaveToConfig('Plugin.SphinxSearchLite.Connection', TRUE);
                         //complete this step
                         $Sender->SetData('NextAction', 'Install');
                         //next step
                     } else {
                         SaveToConfig('Plugin.SphinxSearchLite.Connection', FALSE);
                     }
                     //don't continue
                     break;
                 case 'Install':
                     //Install Sphinx
                     $Sender->SetData('NextAction', 'Install');
                     //in case it fails
                     $InstallAction = GetValue($this->PostPrefix . 'Plugin-dot-SphinxSearch-dot-Detected', $_POST);
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.SearchdPath', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.IndexerPath', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.ConfPath', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearchLite.ConfText', 'Required');
                     if ($Sender->Form->Save()) {
                         //refresh settings after save by getting new instance @todo pretty janky
                         $SphinxAdmin = SphinxFactory::BuildSphinx($Sender, $this->getview('wizard.php'));
                         //check if running in background - if so, requrie that these files are writable for poller
                         $SphinxAdmin->InstallAction($InstallAction, $Background);
                         //install if using package sphinx, if using manual, verify that paths exist and read info from sphinx.conf
                         //manual install requires no polling...simply check if files exist and if sphinx.conf has info we need and move one
                         SaveToConfig('Plugin.SphinxSearchLite.Config', TRUE);
                         //next step
                         $Sender->SetData('NextAction', 'Config');
                         //next step
                         $Sender->StatusMessage = T("Your changes have been saved.");
                     } else {
                         //return FALSE;
                     }
                     break;
                 case 'Config':
                     $SphinxAdmin->InstallConfig();
                     $Sender->SetData('NextAction', 'Finish');
                     SaveToConfig('Plugin.SphinxSearchLite.Installed', TRUE);
                     //complete this step
                     break;
                 default:
                     break;
             }
         }
     }
     if ($this->Settings['Wizard']->Config == TRUE) {
         $Sender->SetData('NextAction', 'Config');
     }
     //get new settings that may have changed
     $Settings = SphinxFactory::BuildSettings();
     $Sender->SetData('Settings', $Settings->GetAllSettings());
     $Sender->Render($this->GetView('wizard.php'));
     //render wizard view
 }
 /**
  * main entry point for the install wizard
  * input parameters for wizard are in the $_GET buffer
  * @param type $Sender
  */
 public function Controller_InstallWizard($Sender)
 {
     include_once PATH_PLUGINS . DS . 'SphinxSearch' . DS . 'class.sphinxsearchinstallwizard.php';
     //include the install wizard
     $SphinxAdmin = SphinxFactory::BuildSphinx($Sender, $this->getview('wizard.php'));
     //SaveToConfig('Plugin.SphinxSearch.SearchdPath', '/usr/bin/sphinx-searchd');
     $Sender->SetData('PluginDescription', $this->GetPluginKey('Description'));
     $Sender->SetData('PluginVersion', $this->GetPluginKey('Version'));
     //create validation
     $Validation = new Gdn_Validation();
     $this->ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $this->ConfigurationModel->SetField(array());
     $Sender->Form->SetModel($this->ConfigurationModel);
     //set model on form
     $Sender->SetData('NextAction', 'Detection');
     $Sender->SetData('InstallSphinx', FALSE);
     $Sender->Form->SetData($this->ConfigurationModel->Data);
     $Sender->Form->InputPrefix = 'Configuration';
     //Wizard State Machine (SM)
     if (GetIncomingValue('action') == 'ToggleWizard') {
         // The validation transient keys don't work in 2.1b for some reason
         // if (Gdn::Session()->ValidateTransientKey(GetValue(1, $Sender->RequestArgs))) {
         if (true) {
             $SphinxAdmin->ToggleWizard();
             //stop/start wizard
             redirect('plugin/sphinxsearch/installwizard');
             //load the wizard page again
         }
     } else {
         if (isset($_POST[$this->PostPrefix . 'NextAction'])) {
             $Background = GetIncomingValue($this->PostPrefix . 'Background');
             switch ($_POST[$this->PostPrefix . 'NextAction']) {
                 case 'Detection':
                     $Sender->SetData('NextAction', 'Detection');
                     //in case it fails
                     $SphinxAdmin->Detect();
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearch.Prefix', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearch.Port', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearch.Host', 'Required');
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearch.Port', 'Integer');
                     //PORT must be an int
                     $Sender->Form->Save();
                     if (!$Sender->Form->Errors()) {
                         //@todo don't check port just yet
                         $Sender->StatusMessage = T("Your changes have been saved.");
                         SaveToConfig('Plugin.SphinxSearch.Connection', TRUE);
                         //complete this step
                         $Sender->SetData('NextAction', 'Install');
                         //next step
                     } else {
                         SaveToConfig('Plugin.SphinxSearch.Connection', FALSE);
                     }
                     //don't continue
                     break;
                 case 'Install':
                     //Install Sphinx
                     $Sender->SetData('NextAction', 'Install');
                     //in case it fails
                     $InstallAction = GetValue($this->PostPrefix . 'Plugin-dot-SphinxSearch-dot-Detected', $_POST);
                     /*
                      *  The paths are no longer required inputs since only the creation of the cron files require it!
                      */
                     $this->ConfigurationModel->Validation->ApplyRule('Plugin.SphinxSearch.ConfText', 'Required');
                     // This is the only input required!
                     $Sender->Form->Save();
                     if (!$Sender->Form->Errors()) {
                         //refresh settings after save by getting new instance @todo pretty janky
                         $SphinxAdmin = SphinxFactory::BuildSphinx($Sender, $this->getview('wizard.php'));
                         $SphinxAdmin->InstallAction($InstallAction, $Background);
                         //Read info from the pasted sphinx.conf
                         //refresh settings (PID/log/query/ path) after save by getting new instance @todo pretty janky
                         $SphinxAdmin = SphinxFactory::BuildSphinx($Sender, $this->getview('wizard.php'));
                         $SphinxAdmin->InstallConfig();
                         // Write the new sphinx.conf file
                         SaveToConfig('Plugin.SphinxSearch.Config', TRUE);
                         //next step
                         $Sender->SetData('NextAction', 'Config');
                         //next step is Cron Config
                         // Sphinx is technically all set. Cron file generation is optional
                         $Sender->StatusMessage = T("Your changes have been saved.");
                     } else {
                         //return FALSE;
                     }
                     break;
                 case 'Config':
                     // AKA cron setup
                     $Sender->SetData('NextAction', 'Config');
                     //in case it fails
                     $this->ConfigurationModel->Validation->AddValidationField('Plugin.SphinxSearch.IndexerPath', $_POST);
                     $this->ConfigurationModel->Validation->AddValidationField('Plugin.SphinxSearch.ConfPath', $_POST);
                     $Sender->Form->Save();
                     if (!$Sender->Form->Errors()) {
                         $SphinxAdmin->InstallCron();
                         SaveToConfig('Plugin.SphinxSearch.Installed', TRUE);
                         // Sphinx is technically all set. Cron file generation is optional
                         $Sender->SetData('NextAction', 'Finish');
                         //complete this step
                     }
                     break;
                 default:
                     break;
             }
         }
     }
     //get new settings that may have changed
     $Settings = SphinxFactory::BuildSettings();
     $Sender->SetData('Settings', $Settings->GetAllSettings());
     $Sender->Render($this->GetView('wizard.php'));
     //render wizard view
 }