public function testDetails() { $this->assertFalse($this->searchOptions->getDetails()); $this->searchOptions = $this->searchOptions->withDetails(); $this->assertTrue($this->searchOptions->getDetails()); $this->searchOptions = $this->searchOptions->withoutDetails(); $this->assertFalse($this->searchOptions->getDetails()); }
<?php /** * Copyright (c) 2008 Massachusetts Institute of Technology * * Licensed under the MIT License * Redistributions of files must retain the above copyright notice. * */ // various copy includes require_once "../../config.gen.inc.php"; require_once "data/data.inc.php"; // records stats require_once "../page_builder/page_header.php"; //defines all the variables related to being today require_once "lib/calendar.lib.php"; require_once "lib/textformat.lib.php"; $today = day_info(time()); $search_options = SearchOptions::get_options(); require "templates/{$prefix}/index.html"; $page->output();
* */ // various copy includes require_once "../../config.gen.inc.php"; require_once "data/data.inc.php"; // records stats require_once "../page_builder/page_header.php"; // sets up google calendar classes require_once "lib/google_calendar.init.php"; // libs require_once "lib/calendar.lib.php"; require_once "lib/textformat.lib.php"; $search_terms = $_REQUEST['filter']; $search_options = SearchOptions::get_options(); $timeframe = isset($_REQUEST['timeframe']) ? $_REQUEST['timeframe'] : 0; $dates = SearchOptions::search_dates($timeframe); $service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar $client = Zend_Gdata_ClientLogin::getHttpClient($username . '@gmail.com', $password, $service); $gdataCal = new Zend_Gdata_Calendar($client); $query = $gdataCal->newEventQuery(); $query->setUser($calendars['all']['user']); $query->setVisibility('private'); $query->setProjection('full'); $query->setOrderby('starttime'); $query->setSortorder('a'); $query->setStartMin($dates['start']); $query->setStartMax($dates['end']); $query->setmaxresults('50'); $query->setQuery($search_terms); $eventFeed = $gdataCal->getCalendarEventFeed($query);
/** * Processes incoming search request */ public function readInSearchRequest() { global $wgCanonicalNamespaceNames, $wgExtraNamespaces, $wgContentNamespaces; $this->aOptions['searchStringRaw'] = $this->oSearchRequest->sInput; $this->aOptions['searchStringOrig'] = ExtendedSearchBase::preprocessSearchInput($this->oSearchRequest->sInput); self::$searchStringRaw = $this->aOptions['searchStringRaw']; $sCustomerId = $this->getCustomerId(); $sLogOp = ' OR '; $aFq = array(); $aBq = array(); $oRequest = RequestContext::getMain()->getRequest(); $scope = $oRequest->getVal('search_scope', BsConfig::get('MW::ExtendedSearch::DefScopeUser')) == 'title' ? 'title' : 'text'; $this->aOptions['scope'] = $scope; $vNamespace = $this->checkSearchstringForNamespace($this->aOptions['searchStringRaw'], $this->aOptions['searchStringOrig'], $aFq, BsConfig::get('MW::ExtendedSearch::ShowFacets')); $this->aOptions['searchStringWildcarded'] = SearchService::wildcardSearchstring($this->aOptions['searchStringOrig']); $this->aOptions['searchStringForStatistics'] = $this->aOptions['searchStringWildcarded']; $aSearchTitle = array('title:(' . $this->aOptions['searchStringOrig'] . ')^5', 'titleWord:(' . $this->aOptions['searchStringOrig'] . ')^2', 'titleReverse:(' . $this->aOptions['searchStringWildcarded'] . ')', 'redirects:(' . $this->aOptions['searchStringOrig'] . ')'); $aSearchText = array('textWord:(' . $this->aOptions['searchStringOrig'] . ')^2', 'textReverse:(' . $this->aOptions['searchStringWildcarded'] . ')', 'sections:(' . $this->aOptions['searchStringOrig'] . ')'); $sSearchStringTitle = implode($sLogOp, $aSearchTitle); $sSearchStringText = implode($sLogOp, $aSearchText); $this->aOptions['searchStringFinal'] = $this->aOptions['scope'] === 'title' ? $sSearchStringTitle : $sSearchStringTitle . $sLogOp . $sSearchStringText; // filter query $aFq[] = 'redirect:0'; $aFq[] = 'special:0'; $aFq[] = 'wiki:(' . $sCustomerId . ')'; // $this->aOptions['namespaces'] HAS TO BE an array with numeric indices of type string! $this->aOptions['namespaces'] = $this->oSearchRequest->aNamespaces; $aNamespaces = array_slice($wgCanonicalNamespaceNames, 2); $aNamespaces = $aNamespaces + $wgExtraNamespaces; $bTagNamespace = false; if ($vNamespace === false) { $this->aOptions['files'] = $this->oSearchRequest->bSearchFiles === true ? true : false; $oUser = RequestContext::getMain()->getUser(); if (!$oUser->getOption('searcheverything')) { if (empty($this->aOptions['namespaces']) && $this->oSearchRequest->bNoSelect === false) { $this->aOptions['namespaces'] = array(); $aOptions = $oUser->getOptions(); foreach ($aOptions as $sOpt => $sValue) { if (strpos($sOpt, 'searchNs') !== false && $sValue == true) { $this->aOptions['namespaces'][] = '' . str_replace('searchNs', '', $sOpt); } } $aAllowedTypes = explode(',', BsConfig::get('MW::ExtendedSearch::IndexFileTypes')); $aAllowedTypes = array_map('trim', $aAllowedTypes); $aSearchFilesFacet = array_intersect($this->oSearchRequest->aType, $aAllowedTypes); if (($this->aOptions['files'] === true || !empty($aSearchFilesFacet)) && $oUser->isAllowed('searchfiles')) { $this->aOptions['namespaces'][] = '999'; $this->aOptions['namespaces'][] = '998'; } } else { $bTagNamespace = true; $aTmp = array(); foreach ($this->aOptions['namespaces'] as $iNs) { if (BsNamespaceHelper::checkNamespacePermission($iNs, 'read') === true) { $aTmp[] = $iNs; } } $this->aOptions['namespaces'] = $aTmp; } } else { if (empty($this->aOptions['namespaces'])) { $aTmp = array(); foreach ($aNamespaces as $iNs) { if (BsNamespaceHelper::checkNamespacePermission($iNs, 'read') === true) { $this->aOptions['namespaces'][] = $iNs; } } } else { $bTagNamespace = true; $aTmp = array(); foreach ($this->aOptions['namespaces'] as $iNs) { if (!BsNamespaceHelper::checkNamespacePermission($iNs, 'read')) { $aTmp[] = $iNs; } } if (!empty($aTmp)) { $this->aOptions['namespaces'] = array_diff($this->aOptions['namespaces'], $aTmp); } } } } else { $bTagNamespace = true; $this->aOptions['namespaces'][] = '' . $vNamespace; } $this->aOptions['namespaces'] = array_unique($this->aOptions['namespaces']); if (!empty($this->aOptions['namespaces'])) { $aFqNamespaces = array(); foreach ($this->aOptions['namespaces'] as $sNamespace) { $aFqNamespaces[] = $sNamespace; if ($sNamespace == '999') { $filesAlreadyAddedInLoopBefore = true; } } if (!isset($filesAlreadyAddedInLoopBefore) && $this->aOptions['files'] === true && $oUser->isAllowed('searchfiles')) { $aFqNamespaces[] = '999'; } $bTagNamespace = true; $aFq[] = BsConfig::get('MW::ExtendedSearch::ShowFacets') ? '{!tag=na}namespace:("' . implode('" "', $aFqNamespaces) . '")' : 'namespace:("' . implode('" "', $aFqNamespaces) . '")'; } // $this->aOptions['cats'] = $this->oSearchRequest->sCat; // string, defaults to '' if 'search_cat' not set in REQUEST $this->aOptions['cats'] = $this->oSearchRequest->sCategories; // array of strings or empty array if (!empty($this->aOptions['cats'])) { if (isset($this->oSearchRequest->sOperator)) { switch ($this->oSearchRequest->sOperator) { case 'AND': $sLogOp = ' AND '; break; default: } } $sFqCategories = BsConfig::get('MW::ExtendedSearch::ShowFacets') ? '{!tag=ca}' : ''; $sFqCategories .= 'cat:("' . implode('"' . $sLogOp . '"', $this->aOptions['cats']) . '")'; $aFq[] = $sFqCategories; } $this->aOptions['type'] = $this->oSearchRequest->aType; if (!empty($this->aOptions['type'])) { $sFqType = BsConfig::get('MW::ExtendedSearch::ShowFacets') ? '{!tag=ty}' : ''; $sFqType .= 'type:("' . implode('"' . $sLogOp . '"', $this->aOptions['type']) . '")'; $aFq[] = $sFqType; } $this->aOptions['editor'] = $this->oSearchRequest->sEditor; if (!empty($this->aOptions['editor'])) { // there may be spaces in name of editor. solr analyses those to two // terms (editor's names) thus we wrap the name into quotation marks // todo: better: in schema.xml define field editor not to be tokenized // at whitespace // but: +editor:("Robert V" "Mathias S") is already split correctly! $sFqEditor = BsConfig::get('MW::ExtendedSearch::ShowFacets') ? '{!tag=ed}' : ''; $sFqEditor .= 'editor:("' . implode('"' . $sLogOp . '"', $this->aOptions['editor']) . '")'; $aFq[] = $sFqEditor; } // Boost query foreach ($wgContentNamespaces as $iNs) { $aBq[] = "namespace:{$iNs}^2"; } // We want that files are also seen as a content namespace $aBq[] = "namespace:999^2"; $searchLimit = BsConfig::get('MW::ExtendedSearch::LimitResults'); $this->aOptions['offset'] = $this->oSearchRequest->iOffset; $this->aOptions['order'] = $this->oSearchRequest->sOrder; $this->aOptions['asc'] = $this->oSearchRequest->sAsc; $this->aOptions['searchLimit'] = $searchLimit == 0 ? 15 : $searchLimit; $this->aOptions['titleExists'] = ExtendedSearchBase::titleExists($this->oSearchRequest->sInput, $this->aOptions); $this->aOptions['bExtendedForm'] = $this->oSearchRequest->bExtendedForm; $this->aSearchOptions['defType'] = 'edismax'; $this->aSearchOptions['fl'] = 'uid,type,title,path,namespace,cat,ts,redirects,overall_type'; $this->aSearchOptions['fq'] = $aFq; $this->aSearchOptions['sort'] = $this->aOptions['order'] . ' ' . $this->aOptions['asc']; $this->aSearchOptions['hl'] = 'on'; $this->aSearchOptions['hl.fl'] = 'titleWord, titleReverse, sections, textWord, textReverse'; $this->aSearchOptions['hl.snippets'] = BsConfig::get('MW::ExtendedSearch::HighlightSnippets'); $this->aSearchOptions['bq'] = implode(' ', $aBq); if (BsConfig::get('MW::ExtendedSearch::ShowFacets')) { $this->aSearchOptions['facet'] = 'on'; $this->aSearchOptions['facet.sort'] = 'false'; $this->aSearchOptions['facet.mincount'] = '1'; $this->aSearchOptions['facet.missing'] = 'true'; $this->aSearchOptions['facet.field'] = array(); $this->aSearchOptions['facet.field'][] = $bTagNamespace === true ? '{!ex=na}namespace' : 'namespace'; $this->aSearchOptions['facet.field'][] = isset($sFqCategories) ? '{!ex=ca}cat' : 'cat'; $this->aSearchOptions['facet.field'][] = isset($sFqType) ? '{!ex=ty}type' : 'type'; $this->aSearchOptions['facet.field'][] = isset($sFqEditor) ? '{!ex=ed}editor' : 'editor'; } }
$dates = SearchOptions::search_dates($timeframe); $events = MIT_Calendar::fullTextSearch($search_terms, $dates['start'], $dates['end'], $category); } else { if (isset($_REQUEST['timeframe'])) { $dates = SearchOptions::search_dates($timeframe); $start = $dates['start']; $end = $dates['end']; } else { $today = day_info(time()); $start = $today['date']; $end = NULL; } $events = MIT_Calendar::CategoryEventsHeaders($category, $start, $end); } $content = new ResultsContent( "items", "calendar", $page, array( "id" => $category->catid, "timeframe" => $timeframe ) ); $form = new CalendarForm($page, SearchOptions::get_options($timeframe), $category->catid); $content->set_form($form); require "$page->branch/category.html"; $page->output(); ?>
/** * @param SearchOptions $searchOptions * @return array */ public static function build(SearchOptions $searchOptions) { $queryParameters = []; if (!is_null($searchOptions->getPage())) { $queryParameters[self::PAGE] = $searchOptions->getPage()->toNative(); } if (!is_null($searchOptions->getLimit())) { $queryParameters[self::LIMIT] = $searchOptions->getLimit()->toNative(); } if (!is_null($searchOptions->getQuery())) { $queryParameters[self::QUERY] = $searchOptions->getQuery()->toNative(); } if (!is_null($searchOptions->getSortField())) { $queryParameters[self::SORTING] = $searchOptions->getSortField()->toNative() . '_' . $searchOptions->getSortOrder()->toNative(); } if ($searchOptions->getDetails()) { $queryParameters[self::DETAILED] = true; } return $queryParameters; }
<?php /** * Copyright (c) 2010 West Virginia University * * Licensed under the MIT License * Redistributions of files must retain the above copyright notice. * */ /** * This script is simply used to provide customized search results for the federated search module */ // sets up adapter class require_once "../page_builder/adapter.php"; $adapter = ModuleAdapter::find('calendar'); require_once "../calendar/adapters/" . $adapter . "/adapter.php"; // libs require_once "lib/calendar.lib.php"; require_once "lib/textformat.lib.php"; $dates = SearchOptions::search_dates(3); // next 30 days $results = CalendarAdapter::searchEvents($filter, $dates['start'], $dates['end']); $total = count($results); require "../calendar/templates/{$prefix}/federated.html";
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; }
<?php require_once "../config/mobi_web_constants.php"; require PAGE_HEADER; require LIBDIR . "mit_calendar.php"; require "calendar_lib.php"; $search_terms = $_REQUEST['filter']; $timeframe = isset($_REQUEST['timeframe']) ? $_REQUEST['timeframe'] : 0; $dates = SearchOptions::search_dates($timeframe); $events = MIT_Calendar::fullTextSearch($search_terms, $dates['start'], $dates['end']); $content = new ResultsContent("items", "calendar", $page, array("timeframe" => $timeframe)); $form = new CalendarForm($page, SearchOptions::get_options($timeframe)); $content->set_form($form); require "{$page->branch}/search.html"; $page->output();