public function execute()
 {
     $this->sType = $this->getOption('param', '');
     //PW(24.07.2013) TODO: add help, descriptions, status/error output
     $solr = SearchService::getInstance();
     echo $solr->deleteIndex($this->sType);
     return;
 }
 /**
  * Constructor for BuildIndexMainControl class
  */
 public function __construct()
 {
     $this->oSearchService = SearchService::getInstance();
     $this->sFilePathIndexProgTxt = BSDATADIR . DS . 'index_prog.txt';
     $this->sFilePathIndexLogFile = BSDATADIR . DS . 'ExtendedSearchIndex.log';
     $this->sFilePathLockFile = BSDATADIR . DS . 'ExtendedSearch.lock';
     //Possible values of PHP_SAPI (not all): apache, cgi (until PHP 5.3), cgi-fcgi, cli
     $this->bCommandLineMode = PHP_SAPI === 'cli';
     $this->sCustomerId = BsConfig::get('MW::ExtendedSearch::CustomerID');
     // Set major types to be indexed
     $this->aTypes['wiki'] = (bool) BsConfig::get('MW::ExtendedSearch::IndexTypesWiki');
     $this->aTypes['special'] = (bool) BsConfig::get('MW::ExtendedSearch::IndexTypesSpecial');
     $this->aTypes['repo'] = (bool) BsConfig::get('MW::ExtendedSearch::IndexTypesRepo');
     $this->aTypes['linked'] = (bool) BsConfig::get('MW::ExtendedSearch::IndexTyLinked');
     $this->aTypes['special-linked'] = (bool) BsConfig::get('MW::ExtendedSearch::IndexTypesSpecialLinked');
 }
 /**
  * Returns status information of delete index progress.
  * Error is indicated by return false or return null
  * @return string information about the Progress or error message.
  */
 public function getDeleteFeedback()
 {
     $sForm = '';
     $oSolr = SearchService::getInstance();
     if ($oSolr === null) {
         return '';
     }
     try {
         $iStatus = $oSolr->deleteIndex();
         if ($iStatus == 200) {
             $iStatus = $oSolr->deleteIndex();
             $sForm .= wfMessage('bs-extendedsearch-index-successfully-deleted')->plain() . '<br />';
         } else {
             $sForm .= wfMessage('bs-extendedsearch-index-error-deleting', $iStatus)->plain() . '<br />';
         }
     } catch (Exception $e) {
         $sForm .= wfMessage('bs-extendedsearch-no-success-deleting', $e->getMessage())->plain() . '<br />';
         $sForm .= $e->getMessage();
     }
     return $sForm;
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     //HINT: includes/api/ApiFeedContributions.php
     //HINT: includes/api/ApiFeedWatchlist.php
     global $wgSitename, $wgLanguageCode, $wgEnableOpenSearchSuggest, $wgSearchSuggestCacheExpiry, $wgFeed, $wgFeedClasses;
     if (!$wgFeed) {
         $this->dieUsage('Syndication feeds are not available', 'feed-unavailable');
     }
     if (!isset($wgFeedClasses[$params['feedformat']])) {
         $this->dieUsage('Invalid subscription feed type', 'feed-invalid');
     }
     $msg = wfMessage('specialextendedsearch')->inContentLanguage()->text();
     $feedTitle = $wgSitename . ' - ' . $msg . ' [' . $wgLanguageCode . ']';
     $feedUrl = SpecialPage::getTitleFor('SpecialExtendedSearch')->getFullURL();
     $feed = new $wgFeedClasses[$params['feedformat']]($feedTitle, htmlspecialchars($msg), $feedUrl);
     $feedItems = array();
     try {
         $oSearchService = SearchService::getInstance();
         $oSearchRequest = new BsSearchRequest('apifeed');
         $oSearchRequestMW = new SearchRequestMW($oSearchRequest);
         $oSearchOptions = new SearchOptions($oSearchRequestMW);
         // Prepare search input
         $sSearchString = $params['q'];
         $sSearchString = urldecode($sSearchString);
         $sSearchString = BsSearchService::preprocessSearchInput($sSearchString);
         $sSearchString = BsSearchService::sanitzeSearchString($sSearchString);
         // Make solr query suitable for autocomplete
         $aSolrQuery = $oSearchOptions->getSolrQuery();
         //$sSearchString = 'titleWord:("'.$params['q'].'") OR titleWord:('.$params['q'].') OR titleReverse:(*'.$params['q'].'*) OR textWord:("'.$params['q'].'") OR textWord:('.$params['q'].') OR textReverse:(*'.$params['q'].'*)';
         $sSearchString = 'titleWord:(' . $sSearchString . ') OR titleWord:(' . $sSearchString . '*) OR titleReverse:(*' . $sSearchString . '*) OR textWord:(' . $sSearchString . ') OR textReverse:(*' . $sSearchString . '*)';
         $aSearchOptions = $aSolrQuery['searchOptions'];
         $aSearchOptions['facet'] = 'off';
         $aSearchOptions['hl'] = 'on';
         $aSearchOptions['hl.fl'] = 'textWord, textReverse';
         $aSearchOptions['hl.snippets'] = 3;
         // params are query, offset, limit, params
         $aHits = $oSearchService->search($sSearchString, 0, 25, $aSearchOptions);
         foreach ($aHits->response->docs as $doc) {
             if ($doc->namespace != '999') {
                 $oTitle = Title::makeTitle($doc->namespace, $doc->title);
             } else {
                 continue;
             }
             if (!$oTitle->userCan('read')) {
                 continue;
             }
             $oHighlightData = $aHits->highlighting->{$doc->uid};
             if (isset($oHighlightData->textWord)) {
                 $aHighlightsnippets = $oHighlightData->textWord;
             } else {
                 if (isset($oHighlightData->textReverse)) {
                     $aHighlightsnippets = $oHighlightData->textReverse;
                 }
             }
             $sTextFragment = '';
             foreach ($aHighlightsnippets as $sFrag) {
                 $sFrag = strip_tags($sFrag, '<em>');
                 if (empty($sFrag)) {
                     continue;
                 }
                 $sTextFragment .= "{$sFrag}<br />";
             }
             $feedItems[] = new FeedItem($doc->title, $sTextFragment, $oTitle->getFullURL());
         }
     } catch (Exception $e) {
         $this->dieUsage($e->getMessage(), 'feed-invalid');
     }
     ApiFormatFeedWrapper::setResult($this->getResult(), $feed, $feedItems);
 }
 /**
  * Starts a autocomplete search
  * @param string $sSearchString Reference to given search string
  * @param boolean $vNsSearch bool always false
  * @return array Array of Apache_Solr_Documents
  */
 private static function searchAutocomplete(&$sSearchString, &$vNsSearch)
 {
     $oSerachService = SearchService::getInstance();
     $oSearchRequest = new SearchRequest();
     $oSearchRequest->init();
     $oSearchOptions = new SearchOptions($oSearchRequest, RequestContext::getMain());
     $oSearchOptions->readInSearchRequest();
     $sSearchString = urldecode($sSearchString);
     $sSolrSearchString = self::preprocessSearchInput($sSearchString);
     $aQuery = $oSearchOptions->getSolrAutocompleteQuery($sSearchString, $sSolrSearchString);
     try {
         $oHits = $oSerachService->search($aQuery['searchString'], $aQuery['offset'], $aQuery['searchLimit'], $aQuery['searchOptions']);
     } catch (Exception $e) {
         return '';
     }
     $oDocuments = $oHits->response->docs;
     if ($aQuery['namespace'] !== false) {
         $vNsSearch = $aQuery['namespace'];
     }
     $bEscalateToFuzzy = $oHits->response->numFound == 0;
     // boolean!
     // Escalate to fuzzy
     if ($bEscalateToFuzzy) {
         $oSearchOptions->setOption('scope', 'title');
         $aFuzzyQuery = $oSearchOptions->getSolrFuzzyQuery($sSolrSearchString);
         $aFuzzyQuery['searchLimit'] = BsConfig::get('MW::ExtendedSearch::AcEntries');
         $aFuzzyQuery['searchOptions']['facet'] = 'off';
         $aFuzzyQuery['searchOptions']['hl'] = 'off';
         try {
             $oHits = $oSerachService->search($aFuzzyQuery['searchString'], $aFuzzyQuery['offset'], $aFuzzyQuery['searchLimit'], $aFuzzyQuery['searchOptions']);
         } catch (Exception $e) {
             return '';
         }
         $oDocuments = $oHits->response->docs;
     }
     return $oDocuments;
 }