/** * Triggers commit and optimize xml update messages * @param boolean $bOptimize optimize index or not * @return object Always null */ public function commitAndOptimize($bOptimize = false, $bWaitSearcher = true, $bSoftCommit = false, $bExpungeDeletes = true) { // http://wiki.apache.org/solr/UpdateXmlMessages#A.22commit.22_and_.22optimize.22 try { $this->oSearchService->commit($bWaitSearcher, $bSoftCommit, $bExpungeDeletes, 60); // Don't optimize on every call it is very expensive if ($bOptimize === true) { $this->oSearchService->optimize(true); } } catch (Exception $e) { } }
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); }