示例#1
0
 function launch()
 {
     global $interface;
     global $configArray;
     global $timer;
     global $analytics;
     /** @var string|LibrarySearchSource|LocationSearchSource $searchSource */
     $searchSource = isset($_REQUEST['searchSource']) ? $_REQUEST['searchSource'] : 'local';
     if (preg_match('/library\\d+/', $searchSource)) {
         $trimmedId = str_replace('library', '', $searchSource);
         $searchSourceObj = new LibrarySearchSource();
         $searchSourceObj->id = $trimmedId;
         if ($searchSourceObj->find(true)) {
             $searchSource = $searchSourceObj;
         }
     }
     if (isset($_REQUEST['replacementTerm'])) {
         $replacementTerm = $_REQUEST['replacementTerm'];
         $interface->assign('replacementTerm', $replacementTerm);
         $oldTerm = $_REQUEST['lookfor'];
         $interface->assign('oldTerm', $oldTerm);
         $_REQUEST['lookfor'] = $replacementTerm;
         $_GET['lookfor'] = $replacementTerm;
         $oldSearchUrl = $_SERVER['REQUEST_URI'];
         $oldSearchUrl = str_replace('replacementTerm=' . urlencode($replacementTerm), 'disallowReplacements', $oldSearchUrl);
         $interface->assign('oldSearchUrl', $oldSearchUrl);
     }
     // Include Search Engine Class
     require_once ROOT_DIR . '/sys/Solr.php';
     $timer->logTime('Include search engine');
     //Check to see if the year has been set and if so, convert to a filter and resend.
     $dateFilters = array('publishDate');
     foreach ($dateFilters as $dateFilter) {
         if (isset($_REQUEST[$dateFilter . 'yearfrom']) || isset($_REQUEST[$dateFilter . 'yearto'])) {
             $queryParams = $_GET;
             $yearFrom = preg_match('/^\\d{2,4}$/', $_REQUEST[$dateFilter . 'yearfrom']) ? $_REQUEST[$dateFilter . 'yearfrom'] : '*';
             $yearTo = preg_match('/^\\d{2,4}$/', $_REQUEST[$dateFilter . 'yearto']) ? $_REQUEST[$dateFilter . 'yearto'] : '*';
             if (strlen($yearFrom) == 2) {
                 $yearFrom = '19' . $yearFrom;
             } else {
                 if (strlen($yearFrom) == 3) {
                     $yearFrom = '0' . $yearFrom;
                 }
             }
             if (strlen($yearTo) == 2) {
                 $yearTo = '19' . $yearTo;
             } else {
                 if (strlen($yearFrom) == 3) {
                     $yearTo = '0' . $yearTo;
                 }
             }
             if ($yearTo != '*' && $yearFrom != '*' && $yearTo < $yearFrom) {
                 $tmpYear = $yearTo;
                 $yearTo = $yearFrom;
                 $yearFrom = $tmpYear;
             }
             unset($queryParams['module']);
             unset($queryParams['action']);
             unset($queryParams[$dateFilter . 'yearfrom']);
             unset($queryParams[$dateFilter . 'yearto']);
             if (!isset($queryParams['sort'])) {
                 $queryParams['sort'] = 'year';
             }
             $queryParamStrings = array();
             foreach ($queryParams as $paramName => $queryValue) {
                 if (is_array($queryValue)) {
                     foreach ($queryValue as $arrayValue) {
                         if (strlen($arrayValue) > 0) {
                             $queryParamStrings[] = $paramName . '[]=' . $arrayValue;
                         }
                     }
                 } else {
                     if (strlen($queryValue)) {
                         $queryParamStrings[] = $paramName . '=' . $queryValue;
                     }
                 }
             }
             if ($yearFrom != '*' || $yearTo != '*') {
                 $queryParamStrings[] = "&filter[]={$dateFilter}:[{$yearFrom}+TO+{$yearTo}]";
             }
             $queryParamString = join('&', $queryParamStrings);
             header("Location: {$configArray['Site']['path']}/Search/Results?{$queryParamString}");
             exit;
         }
     }
     $rangeFilters = array('lexile_score', 'accelerated_reader_reading_level', 'accelerated_reader_point_value');
     foreach ($rangeFilters as $filter) {
         if (isset($_REQUEST[$filter . 'from']) && strlen($_REQUEST[$filter . 'from']) > 0 || isset($_REQUEST[$filter . 'to']) && strlen($_REQUEST[$filter . 'to']) > 0) {
             $queryParams = $_GET;
             $from = isset($_REQUEST[$filter . 'from']) && preg_match('/^\\d*(\\.\\d*)?$/', $_REQUEST[$filter . 'from']) ? $_REQUEST[$filter . 'from'] : '*';
             $to = isset($_REQUEST[$filter . 'to']) && preg_match('/^\\d*(\\.\\d*)?$/', $_REQUEST[$filter . 'to']) ? $_REQUEST[$filter . 'to'] : '*';
             if ($to != '*' && $from != '*' && $to < $from) {
                 $tmpFilter = $to;
                 $to = $from;
                 $from = $tmpFilter;
             }
             unset($queryParams['module']);
             unset($queryParams['action']);
             unset($queryParams[$filter . 'from']);
             unset($queryParams[$filter . 'to']);
             $queryParamStrings = array();
             foreach ($queryParams as $paramName => $queryValue) {
                 if (is_array($queryValue)) {
                     foreach ($queryValue as $arrayValue) {
                         if (strlen($arrayValue) > 0) {
                             $queryParamStrings[] = $paramName . '[]=' . $arrayValue;
                         }
                     }
                 } else {
                     if (strlen($queryValue)) {
                         $queryParamStrings[] = $paramName . '=' . $queryValue;
                     }
                 }
             }
             if ($from != '*' || $to != '*') {
                 $queryParamStrings[] = "&filter[]={$filter}:[{$from}+TO+{$to}]";
             }
             $queryParamString = join('&', $queryParamStrings);
             header("Location: {$configArray['Site']['path']}/Search/Results?{$queryParamString}");
             exit;
         }
     }
     // Initialise from the current search globals
     /** @var SearchObject_Solr $searchObject */
     $searchObject = SearchObjectFactory::initSearchObject();
     $searchObject->init($searchSource);
     $timer->logTime("Init Search Object");
     // Build RSS Feed for Results (if requested)
     if ($searchObject->getView() == 'rss') {
         // Throw the XML to screen
         echo $searchObject->buildRSS();
         // And we're done
         exit;
     } else {
         if ($searchObject->getView() == 'excel') {
             // Throw the Excel spreadsheet to screen for download
             echo $searchObject->buildExcel();
             // And we're done
             exit;
         }
     }
     // TODO : Investigate this... do we still need
     // If user wants to print record show directly print-dialog box
     if (isset($_GET['print'])) {
         $interface->assign('print', true);
     }
     // Set Interface Variables
     //   Those we can construct BEFORE the search is executed
     $interface->setPageTitle('Search Results');
     $interface->assign('sortList', $searchObject->getSortList());
     $interface->assign('rssLink', $searchObject->getRSSUrl());
     $interface->assign('excelLink', $searchObject->getExcelUrl());
     $timer->logTime('Setup Search');
     // Process Search
     $result = $searchObject->processSearch(true, true);
     if (PEAR_Singleton::isError($result)) {
         PEAR_Singleton::raiseError($result->getMessage());
     }
     $timer->logTime('Process Search');
     // Some more variables
     //   Those we can construct AFTER the search is executed, but we need
     //   no matter whether there were any results
     $interface->assign('qtime', round($searchObject->getQuerySpeed(), 2));
     $interface->assign('spellingSuggestions', $searchObject->getSpellingSuggestions());
     $interface->assign('lookfor', $searchObject->displayQuery());
     $interface->assign('searchType', $searchObject->getSearchType());
     // Will assign null for an advanced search
     $interface->assign('searchIndex', $searchObject->getSearchIndex());
     // We'll need recommendations no matter how many results we found:
     $interface->assign('topRecommendations', $searchObject->getRecommendationsTemplates('top'));
     $interface->assign('sideRecommendations', $searchObject->getRecommendationsTemplates('side'));
     // 'Finish' the search... complete timers and log search history.
     $searchObject->close();
     $interface->assign('time', round($searchObject->getTotalSpeed(), 2));
     // Show the save/unsave code on screen
     // The ID won't exist until after the search has been put in the search history
     //    so this needs to occur after the close() on the searchObject
     $interface->assign('showSaved', true);
     $interface->assign('savedSearch', $searchObject->isSavedSearch());
     $interface->assign('searchId', $searchObject->getSearchId());
     $currentPage = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
     $interface->assign('page', $currentPage);
     //Enable and disable functionality based on library settings
     //This must be done before we process each result
     global $library;
     /** @var Location $locationSingleton */
     global $locationSingleton;
     $location = $locationSingleton->getActiveLocation();
     $showHoldButton = 1;
     $showHoldButtonInSearchResults = 1;
     $interface->assign('showNotInterested', false);
     if (isset($library) && $location != null) {
         $interface->assign('showFavorites', $library->showFavorites);
         $interface->assign('showComments', $library->showComments);
         $showHoldButton = $location->showHoldButton == 1 && $library->showHoldButton == 1 ? 1 : 0;
         $showHoldButtonInSearchResults = $location->showHoldButton == 1 && $library->showHoldButtonInSearchResults == 1 ? 1 : 0;
     } else {
         if ($location != null) {
             $interface->assign('showFavorites', 1);
             $showHoldButton = $location->showHoldButton;
         } else {
             if (isset($library)) {
                 $interface->assign('showFavorites', $library->showFavorites);
                 $showHoldButton = $library->showHoldButton;
                 $showHoldButtonInSearchResults = $library->showHoldButtonInSearchResults;
                 $interface->assign('showComments', $library->showComments);
             } else {
                 $interface->assign('showFavorites', 1);
                 $interface->assign('showComments', 1);
             }
         }
     }
     if ($showHoldButton == 0) {
         $showHoldButtonInSearchResults = 0;
     }
     $interface->assign('showHoldButton', $showHoldButtonInSearchResults);
     $interface->assign('page_body_style', 'sidebar_left');
     $interface->assign('overDriveVersion', isset($configArray['OverDrive']['interfaceVersion']) ? $configArray['OverDrive']['interfaceVersion'] : 1);
     //Check to see if we should show unscoped results
     $enableUnscopedSearch = false;
     $searchLibrary = Library::getSearchLibrary();
     if ($searchLibrary != null && $searchLibrary->showMarmotResultsAtEndOfSearch) {
         if (is_object($searchSource)) {
             $enableUnscopedSearch = $searchSource->catalogScoping != 'unscoped';
             $unscopedSearch = clone $searchObject;
         } else {
             $searchSources = new SearchSources();
             $searchOptions = $searchSources->getSearchSources();
             if (isset($searchOptions['marmot'])) {
                 $unscopedSearch = clone $searchObject;
                 $enableUnscopedSearch = true;
             }
         }
     }
     $enableProspectorIntegration = isset($configArray['Content']['Prospector']) ? $configArray['Content']['Prospector'] : false;
     $showRatings = 1;
     $showProspectorResultsAtEndOfSearch = true;
     if (isset($library)) {
         $enableProspectorIntegration = $library->enablePospectorIntegration == 1;
         $showRatings = $library->showRatings;
         $showProspectorResultsAtEndOfSearch = $library->showProspectorResultsAtEndOfSearch == 1;
     }
     $interface->assign('showRatings', $showRatings);
     $numProspectorTitlesToLoad = 0;
     $numUnscopedTitlesToLoad = 0;
     // Save the ID of this search to the session so we can return to it easily:
     $_SESSION['lastSearchId'] = $searchObject->getSearchId();
     // Save the URL of this search to the session so we can return to it easily:
     $_SESSION['lastSearchURL'] = $searchObject->renderSearchUrl();
     if (is_object($searchSource)) {
         $translatedSearch = $searchSource->label;
     } else {
         $allSearchSources = SearchSources::getSearchSources();
         if (!isset($allSearchSources[$searchSource]) && $searchSource == 'marmot') {
             $searchSource = 'local';
         }
         $translatedSearch = $allSearchSources[$searchSource]['name'];
     }
     $analytics->addSearch($translatedSearch, $searchObject->displayQuery(), $searchObject->isAdvanced(), $searchObject->getFullSearchType(), $searchObject->hasAppliedFacets(), $searchObject->getResultTotal());
     if ($searchObject->getResultTotal() < 1) {
         //We didn't find anything.  Look for search Suggestions
         //Don't try to find suggestions if facets were applied
         $autoSwitchSearch = false;
         $disallowReplacements = isset($_REQUEST['disallowReplacements']) || isset($_REQUEST['replacementTerm']);
         if (!$disallowReplacements && (!isset($facetSet) || count($facetSet) == 0)) {
             require_once ROOT_DIR . '/services/Search/lib/SearchSuggestions.php';
             $searchSuggestions = new SearchSuggestions();
             $commonSearches = $searchSuggestions->getCommonSearchesMySql($searchObject->displayQuery(), $searchObject->getSearchIndex());
             //If the first search in the list is used 10 times more than the next, just show results for that
             $numSuggestions = count($commonSearches);
             if ($numSuggestions == 1) {
                 $autoSwitchSearch = true;
             } elseif ($numSuggestions >= 2) {
                 $firstTimesSearched = $commonSearches[0]['numSearches'];
                 $secondTimesSearched = $commonSearches[1]['numSearches'];
                 if ($firstTimesSearched / $secondTimesSearched > 10) {
                     $autoSwitchSearch = true;
                 }
             }
             $interface->assign('autoSwitchSearch', $autoSwitchSearch);
             if ($autoSwitchSearch) {
                 //Get search results for the new search
                 $interface->assign('oldTerm', $searchObject->displayQuery());
                 $interface->assign('newTerm', $commonSearches[0]['phrase']);
                 $thisUrl = $_SERVER['REQUEST_URI'];
                 $thisUrl = $thisUrl . "&replacementTerm=" . urlencode($commonSearches[0]['phrase']);
                 header("Location: " . $thisUrl);
                 exit;
             }
             $interface->assign('searchSuggestions', $commonSearches);
         }
         //Var for the IDCLREADER TEMPLATE
         $interface->assign('ButtonBack', true);
         $interface->assign('ButtonHome', true);
         $interface->assign('MobileTitle', 'No Results Found');
         // No record found
         $interface->setTemplate('list-none.tpl');
         $interface->assign('recordCount', 0);
         // Was the empty result set due to an error?
         $error = $searchObject->getIndexError();
         if ($error !== false) {
             // If it's a parse error or the user specified an invalid field, we
             // should display an appropriate message:
             if (stristr($error, 'org.apache.lucene.queryParser.ParseException') || preg_match('/^undefined field/', $error)) {
                 $interface->assign('parseError', true);
                 // Unexpected error -- let's treat this as a fatal condition.
             } else {
                 PEAR_Singleton::raiseError(new PEAR_Error('Unable to process query<br />' . 'Solr Returned: ' . $error));
             }
         }
         $numProspectorTitlesToLoad = 10;
         $numUnscopedTitlesToLoad = 10;
         $timer->logTime('no hits processing');
     } else {
         if ($searchObject->getResultTotal() == 1 && (strpos($searchObject->displayQuery(), 'id') === 0 || $searchObject->getSearchType() == 'id')) {
             //Redirect to the home page for the record
             $recordSet = $searchObject->getResultRecordSet();
             $record = reset($recordSet);
             $_SESSION['searchId'] = $searchObject->getSearchId();
             if ($record['recordtype'] == 'list') {
                 $listId = substr($record['id'], 4);
                 header("Location: " . $configArray['Site']['path'] . "/MyResearch/MyList/{$listId}");
                 exit;
             } elseif ($record['recordtype'] == 'econtentRecord') {
                 $shortId = str_replace('econtentRecord', '', $record['id']);
                 header("Location: " . $configArray['Site']['path'] . "/EcontentRecord/{$shortId}/Home");
                 exit;
             } else {
                 header("Location: " . $configArray['Site']['path'] . "/Record/{$record['id']}/Home");
                 exit;
             }
         } else {
             $timer->logTime('save search');
             // Assign interface variables
             $summary = $searchObject->getResultSummary();
             $interface->assign('recordCount', $summary['resultTotal']);
             $interface->assign('recordStart', $summary['startRecord']);
             $interface->assign('recordEnd', $summary['endRecord']);
             $facetSet = $searchObject->getFacetList();
             $interface->assign('facetSet', $facetSet);
             //Check to see if a format category is already set
             $categorySelected = false;
             if (isset($facetSet['top'])) {
                 foreach ($facetSet['top'] as $cluster) {
                     if ($cluster['label'] == 'Category') {
                         foreach ($cluster['list'] as $thisFacet) {
                             if ($thisFacet['isApplied']) {
                                 $categorySelected = true;
                             }
                         }
                     }
                 }
             }
             $interface->assign('categorySelected', $categorySelected);
             $timer->logTime('load selected category');
             // Big one - our results
             $recordSet = $searchObject->getResultRecordHTML();
             $interface->assign('recordSet', $recordSet);
             $timer->logTime('load result records');
             // Setup Display
             $interface->assign('sitepath', $configArray['Site']['path']);
             $interface->assign('subpage', 'Search/list-list.tpl');
             $interface->setTemplate('list.tpl');
             //Var for the IDCLREADER TEMPLATE
             $interface->assign('ButtonBack', true);
             $interface->assign('ButtonHome', true);
             $interface->assign('MobileTitle', 'Search Results');
             // Process Paging
             $link = $searchObject->renderLinkPageTemplate();
             $options = array('totalItems' => $summary['resultTotal'], 'fileName' => $link, 'perPage' => $summary['perPage']);
             $pager = new VuFindPager($options);
             $interface->assign('pageLinks', $pager->getLinks());
             if ($pager->isLastPage()) {
                 $numProspectorTitlesToLoad = 5;
                 $numUnscopedTitlesToLoad = 5;
             }
             $timer->logTime('finish hits processing');
         }
     }
     if ($numProspectorTitlesToLoad > 0 && $enableProspectorIntegration && $showProspectorResultsAtEndOfSearch) {
         $interface->assign('prospectorNumTitlesToLoad', $numProspectorTitlesToLoad);
         $interface->assign('prospectorSavedSearchId', $searchObject->getSearchId());
     } else {
         $interface->assign('prospectorNumTitlesToLoad', 0);
     }
     if ($enableUnscopedSearch && isset($unscopedSearch)) {
         $unscopedSearch->setLimit($numUnscopedTitlesToLoad * 4);
         $unscopedSearch->disableScoping();
         $unscopedSearch->processSearch(false, false);
         $numUnscopedResults = $unscopedSearch->getResultTotal();
         $interface->assign('numUnscopedResults', $numUnscopedResults);
         $unscopedSearchUrl = $unscopedSearch->renderSearchUrl();
         if (preg_match('/searchSource=(.*?)(?:&|$)/', $unscopedSearchUrl)) {
             $unscopedSearchUrl = preg_replace('/(.*searchSource=)(.*?)(&|$)(.*)/', '$1marmot$3$4', $unscopedSearchUrl);
             $unscopedSearchUrl = preg_replace('/&/', '&amp;', $unscopedSearchUrl);
         } else {
             $unscopedSearchUrl .= "&amp;searchSource=marmot";
         }
         $unscopedSearchUrl .= "&amp;shard=";
         $interface->assign('unscopedSearchUrl', $unscopedSearchUrl);
         if ($numUnscopedTitlesToLoad > 0) {
             $unscopedResults = $unscopedSearch->getSupplementalResultRecordHTML($searchObject->getResultRecordSet(), $numUnscopedTitlesToLoad, $searchObject->getResultTotal());
             $interface->assign('unscopedResults', $unscopedResults);
         }
     }
     //Determine whether or not materials request functionality should be enabled
     $interface->assign('enableMaterialsRequest', MaterialsRequest::enableMaterialsRequest());
     if ($configArray['Statistics']['enabled'] && isset($_GET['lookfor'])) {
         require_once ROOT_DIR . '/Drivers/marmot_inc/SearchStat.php';
         $searchStat = new SearchStat();
         $searchStat->saveSearch(strip_tags($_GET['lookfor']), strip_tags(isset($_GET['type']) ? $_GET['type'] : (isset($_GET['basicType']) ? $_GET['basicType'] : 'Keyword')), $searchObject->getResultTotal());
     }
     // Done, display the page
     $interface->display('layout.tpl');
 }
示例#2
0
 public function clearSearchSources()
 {
     $facets = new LibrarySearchSource();
     $facets->libraryId = $this->libraryId;
     $facets->delete();
     $this->searchSources = array();
 }
 function getObjectStructure()
 {
     return LibrarySearchSource::getObjectStructure();
 }
示例#4
0
 function launch()
 {
     global $module;
     global $action;
     global $interface;
     //Get the search source and determine what to show.
     $searchSource = isset($_REQUEST['searchSource']) ? $_REQUEST['searchSource'] : 'local';
     //Check the search source
     if (preg_match('/library\\d+/', $searchSource)) {
         require_once ROOT_DIR . '/Drivers/marmot_inc/LibrarySearchSource.php';
         $trimmedId = str_replace('library', '', $searchSource);
         $searchSource = new LibrarySearchSource();
         $searchSource->id = $trimmedId;
         if ($searchSource->find(true)) {
             if ($searchSource->searchWhat == 'catalog') {
                 require_once ROOT_DIR . '/services/Search/Results.php';
                 $module = 'Search';
                 $interface->assign('module', $module);
                 $action = 'Results';
                 $interface->assign('action', $action);
                 $results = new Search_Results();
                 $results->launch();
             } elseif ($searchSource->searchWhat == 'genealogy') {
                 require_once ROOT_DIR . '/services/Genealogy/Results.php';
                 $module = 'Search';
                 $interface->assign('module', $module);
                 $action = 'Results';
                 $interface->assign('action', $action);
                 $results = new Results();
                 $results->launch();
             } elseif ($searchSource->searchWhat == 'tags') {
                 require_once ROOT_DIR . '/services/Search/Results.php';
                 $module = 'Search';
                 $interface->assign('module', $module);
                 $action = 'Results';
                 $interface->assign('action', $action);
                 $_REQUEST['basicType'] = 'tag';
                 $results = new Search_Results();
                 $results->launch();
             } elseif ($searchSource->searchWhat == 'title_browse' || $searchSource->searchWhat == 'author_browse' || $searchSource->searchWhat == 'subject_browse') {
                 require_once ROOT_DIR . '/services/AlphaBrowse/Results.php';
                 $module = 'AlphaBrowse';
                 $interface->assign('module', $module);
                 $action = 'Results';
                 $interface->assign('action', $action);
                 $results = new AlphaBrowse_Results();
                 $results->launch();
             } else {
                 $searchSources = new SearchSources();
                 $type = isset($_REQUEST['basicType']) ? $_REQUEST['basicType'] : $_REQUEST['type'];
                 $lookfor = isset($_REQUEST['lookfor']) ? $_REQUEST['lookfor'] : '';
                 $link = $searchSources->getExternalLink($searchSource, $type, $lookfor);
                 header('Location: ' . $link);
                 die;
             }
         }
     } else {
         $searchSources = new SearchSources();
         $searches = $searchSources->getSearchSources();
         if (!isset($searches[$searchSource]) && $searchSource == 'marmot') {
             $searchSource = 'local';
         }
         $searchInfo = $searches[$searchSource];
         if (isset($searchInfo['external']) && $searchInfo['external'] == true) {
             //Reset to a local search source so the external search isn't remembered
             $_SESSION['searchSource'] = 'local';
             //Need to redirect to the appropriate search location with the new value for look for
             $type = isset($_REQUEST['basicType']) ? $_REQUEST['basicType'] : $_REQUEST['type'];
             $lookfor = isset($_REQUEST['lookfor']) ? $_REQUEST['lookfor'] : '';
             $filters = isset($_REQUEST['filter']) ? $_REQUEST['filter'] : null;
             $link = $searchSources->getExternalLink($searchSource, $type, $lookfor);
             header('Location: ' . $link);
             die;
         } else {
             if ($searchSource == 'genealogy') {
                 require_once ROOT_DIR . '/services/Genealogy/Results.php';
                 $module = 'Search';
                 $interface->assign('module', $module);
                 $action = 'Results';
                 $interface->assign('action', $action);
                 $results = new Results();
                 $results->launch();
             } else {
                 $type = isset($_REQUEST['basicType']) ? $_REQUEST['basicType'] : (isset($_REQUEST['type']) ? $_REQUEST['type'] : 'Keyword');
                 if (strpos($type, 'browse') === 0) {
                     require_once ROOT_DIR . '/services/AlphaBrowse/Results.php';
                     $module = 'AlphaBrowse';
                     $interface->assign('module', $module);
                     $action = 'Results';
                     $interface->assign('action', $action);
                     $results = new AlphaBrowse_Results();
                     $results->launch();
                 } else {
                     require_once ROOT_DIR . '/services/Search/Results.php';
                     $module = 'Search';
                     $interface->assign('module', $module);
                     $action = 'Results';
                     $interface->assign('action', $action);
                     if ($searchSource == 'econtent') {
                         if (!isset($_REQUEST['shard'])) {
                             $_SESSION['shards'] = array('eContent');
                         }
                     } else {
                         if (!isset($_REQUEST['shard'])) {
                             $_SESSION['shards'] = array('eContent', 'Main Catalog');
                         }
                     }
                     $results = new Search_Results();
                     $results->launch();
                 }
             }
         }
     }
 }
示例#5
0
 static function getSearchLocation($searchSource = null)
 {
     if (is_null($searchSource)) {
         $searchSource = isset($_REQUEST['searchSource']) ? $_REQUEST['searchSource'] : 'local';
         if (strpos($searchSource, 'library') === 0) {
             $trimmedSearchSource = str_replace('library', '', $searchSource);
             require_once ROOT_DIR . '/Drivers/marmot_inc/LibrarySearchSource.php';
             $librarySearchSource = new LibrarySearchSource();
             $librarySearchSource->id = $trimmedSearchSource;
             if ($librarySearchSource->find(true)) {
                 $searchSource = $librarySearchSource;
             }
         }
     }
     if (is_object($searchSource)) {
         $scopingSetting = $searchSource->catalogScoping;
     } else {
         $scopingSetting = $searchSource;
     }
     if ($scopingSetting == 'local' || $scopingSetting == 'econtent' || $scopingSetting == 'location') {
         global $locationSingleton;
         return $locationSingleton->getActiveLocation();
     } else {
         if ($scopingSetting == 'marmot' || $scopingSetting == 'unscoped') {
             return null;
         } else {
             $location = new Location();
             $location->code = $scopingSetting;
             $location->find();
             if ($location->N > 0) {
                 $location->fetch();
                 return clone $location;
             }
             return null;
         }
     }
 }
示例#6
0
 function launch()
 {
     global $interface;
     global $configArray;
     global $timer;
     global $analytics;
     global $library;
     /** @var string|LibrarySearchSource|LocationSearchSource $searchSource */
     $searchSource = isset($_REQUEST['searchSource']) ? $_REQUEST['searchSource'] : 'local';
     if (preg_match('/library\\d+/', $searchSource)) {
         $trimmedId = str_replace('library', '', $searchSource);
         $searchSourceObj = new LibrarySearchSource();
         $searchSourceObj->id = $trimmedId;
         if ($searchSourceObj->find(true)) {
             $searchSource = $searchSourceObj;
         }
     }
     if (isset($_REQUEST['replacementTerm'])) {
         $replacementTerm = $_REQUEST['replacementTerm'];
         $interface->assign('replacementTerm', $replacementTerm);
         $oldTerm = $_REQUEST['lookfor'];
         $interface->assign('oldTerm', $oldTerm);
         $_REQUEST['lookfor'] = $replacementTerm;
         $_GET['lookfor'] = $replacementTerm;
         $oldSearchUrl = $_SERVER['REQUEST_URI'];
         $oldSearchUrl = str_replace('replacementTerm=' . urlencode($replacementTerm), 'disallowReplacements', $oldSearchUrl);
         $interface->assign('oldSearchUrl', $oldSearchUrl);
     }
     $interface->assign('showDplaLink', false);
     if ($configArray['DPLA']['enabled']) {
         if ($library->includeDplaResults) {
             $interface->assign('showDplaLink', true);
         }
     }
     // Include Search Engine Class
     require_once ROOT_DIR . '/sys/Solr.php';
     $timer->logTime('Include search engine');
     //Check to see if the year has been set and if so, convert to a filter and resend.
     $dateFilters = array('publishDate');
     foreach ($dateFilters as $dateFilter) {
         if (isset($_REQUEST[$dateFilter . 'yearfrom']) && !empty($_REQUEST[$dateFilter . 'yearfrom']) || isset($_REQUEST[$dateFilter . 'yearto']) && !empty($_REQUEST[$dateFilter . 'yearto'])) {
             $queryParams = $_GET;
             $yearFrom = preg_match('/^\\d{2,4}$/', $_REQUEST[$dateFilter . 'yearfrom']) ? $_REQUEST[$dateFilter . 'yearfrom'] : '*';
             $yearTo = preg_match('/^\\d{2,4}$/', $_REQUEST[$dateFilter . 'yearto']) ? $_REQUEST[$dateFilter . 'yearto'] : '*';
             if (strlen($yearFrom) == 2) {
                 $yearFrom = '19' . $yearFrom;
             } else {
                 if (strlen($yearFrom) == 3) {
                     $yearFrom = '0' . $yearFrom;
                 }
             }
             if (strlen($yearTo) == 2) {
                 $yearTo = '19' . $yearTo;
             } else {
                 if (strlen($yearFrom) == 3) {
                     $yearTo = '0' . $yearTo;
                 }
             }
             if ($yearTo != '*' && $yearFrom != '*' && $yearTo < $yearFrom) {
                 $tmpYear = $yearTo;
                 $yearTo = $yearFrom;
                 $yearFrom = $tmpYear;
             }
             unset($queryParams['module']);
             unset($queryParams['action']);
             unset($queryParams[$dateFilter . 'yearfrom']);
             unset($queryParams[$dateFilter . 'yearto']);
             if (!isset($queryParams['sort'])) {
                 $queryParams['sort'] = 'year';
             }
             $queryParamStrings = array();
             foreach ($queryParams as $paramName => $queryValue) {
                 if (is_array($queryValue)) {
                     foreach ($queryValue as $arrayValue) {
                         if (strlen($arrayValue) > 0) {
                             $queryParamStrings[] = $paramName . '[]=' . $arrayValue;
                         }
                     }
                 } else {
                     if (strlen($queryValue)) {
                         $queryParamStrings[] = $paramName . '=' . $queryValue;
                     }
                 }
             }
             if ($yearFrom != '*' || $yearTo != '*') {
                 $queryParamStrings[] = "&filter[]={$dateFilter}:[{$yearFrom}+TO+{$yearTo}]";
             }
             $queryParamString = join('&', $queryParamStrings);
             header("Location: {$configArray['Site']['path']}/Search/Results?{$queryParamString}");
             exit;
         }
     }
     $rangeFilters = array('lexile_score', 'accelerated_reader_reading_level', 'accelerated_reader_point_value');
     foreach ($rangeFilters as $filter) {
         if (isset($_REQUEST[$filter . 'from']) && strlen($_REQUEST[$filter . 'from']) > 0 || isset($_REQUEST[$filter . 'to']) && strlen($_REQUEST[$filter . 'to']) > 0) {
             $queryParams = $_GET;
             $from = isset($_REQUEST[$filter . 'from']) && preg_match('/^\\d*(\\.\\d*)?$/', $_REQUEST[$filter . 'from']) ? $_REQUEST[$filter . 'from'] : '*';
             $to = isset($_REQUEST[$filter . 'to']) && preg_match('/^\\d*(\\.\\d*)?$/', $_REQUEST[$filter . 'to']) ? $_REQUEST[$filter . 'to'] : '*';
             if ($to != '*' && $from != '*' && $to < $from) {
                 $tmpFilter = $to;
                 $to = $from;
                 $from = $tmpFilter;
             }
             unset($queryParams['module']);
             unset($queryParams['action']);
             unset($queryParams[$filter . 'from']);
             unset($queryParams[$filter . 'to']);
             $queryParamStrings = array();
             foreach ($queryParams as $paramName => $queryValue) {
                 if (is_array($queryValue)) {
                     foreach ($queryValue as $arrayValue) {
                         if (strlen($arrayValue) > 0) {
                             $queryParamStrings[] = $paramName . '[]=' . $arrayValue;
                         }
                     }
                 } else {
                     if (strlen($queryValue)) {
                         $queryParamStrings[] = $paramName . '=' . $queryValue;
                     }
                 }
             }
             if ($from != '*' || $to != '*') {
                 $queryParamStrings[] = "&filter[]={$filter}:[{$from}+TO+{$to}]";
             }
             $queryParamString = join('&', $queryParamStrings);
             header("Location: {$configArray['Site']['path']}/Search/Results?{$queryParamString}");
             exit;
         }
     }
     // Initialise from the current search globals
     /** @var SearchObject_Solr $searchObject */
     $searchObject = SearchObjectFactory::initSearchObject();
     //		$searchObject->viewOptions = $this->viewOptions; // set valid view options for the search object
     $searchObject->init($searchSource);
     $timer->logTime("Init Search Object");
     // Build RSS Feed for Results (if requested)
     if ($searchObject->getView() == 'rss') {
         // Throw the XML to screen
         echo $searchObject->buildRSS();
         // And we're done
         exit;
     } else {
         if ($searchObject->getView() == 'excel') {
             // Throw the Excel spreadsheet to screen for download
             echo $searchObject->buildExcel();
             // And we're done
             exit;
         }
     }
     $displayMode = $searchObject->getView();
     if ($displayMode == 'covers') {
         $searchObject->setLimit(24);
         // a set of 24 covers looks better in display
     }
     // Set Interface Variables
     //   Those we can construct BEFORE the search is executed
     $displayQuery = $searchObject->displayQuery();
     $pageTitle = $displayQuery;
     if (strlen($pageTitle) > 20) {
         $pageTitle = substr($pageTitle, 0, 20) . '...';
     }
     $pageTitle .= ' | Search Results';
     $interface->setPageTitle($pageTitle);
     $interface->assign('sortList', $searchObject->getSortList());
     $interface->assign('rssLink', $searchObject->getRSSUrl());
     $interface->assign('excelLink', $searchObject->getExcelUrl());
     $timer->logTime('Setup Search');
     // Process Search
     $result = $searchObject->processSearch(true, true);
     if (PEAR_Singleton::isError($result)) {
         PEAR_Singleton::raiseError($result->getMessage());
     }
     $timer->logTime('Process Search');
     // Some more variables
     //   Those we can construct AFTER the search is executed, but we need
     //   no matter whether there were any results
     $interface->assign('qtime', round($searchObject->getQuerySpeed(), 2));
     $interface->assign('spellingSuggestions', $searchObject->getSpellingSuggestions());
     $interface->assign('lookfor', $displayQuery);
     $interface->assign('searchType', $searchObject->getSearchType());
     // Will assign null for an advanced search
     $interface->assign('searchIndex', $searchObject->getSearchIndex());
     // We'll need recommendations no matter how many results we found:
     $interface->assign('topRecommendations', $searchObject->getRecommendationsTemplates('top'));
     $interface->assign('sideRecommendations', $searchObject->getRecommendationsTemplates('side'));
     // 'Finish' the search... complete timers and log search history.
     $searchObject->close();
     $interface->assign('time', round($searchObject->getTotalSpeed(), 2));
     // Show the save/unsave code on screen
     // The ID won't exist until after the search has been put in the search history
     //    so this needs to occur after the close() on the searchObject
     $interface->assign('showSaved', true);
     $interface->assign('savedSearch', $searchObject->isSavedSearch());
     $interface->assign('searchId', $searchObject->getSearchId());
     $currentPage = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
     $interface->assign('page', $currentPage);
     //Enable and disable functionality based on library settings
     //This must be done before we process each result
     $interface->assign('showNotInterested', false);
     $interface->assign('page_body_style', 'sidebar_left');
     $interface->assign('overDriveVersion', isset($configArray['OverDrive']['interfaceVersion']) ? $configArray['OverDrive']['interfaceVersion'] : 1);
     //Check to see if we should show unscoped results
     global $solrScope;
     $enableUnscopedSearch = false;
     // fallback setting
     if ($solrScope) {
         $searchLibrary = Library::getSearchLibrary();
         if ($searchLibrary != null && $searchLibrary->showMarmotResultsAtEndOfSearch) {
             if (is_object($searchSource)) {
                 $enableUnscopedSearch = $searchSource->catalogScoping != 'unscoped';
                 $unscopedSearch = clone $searchObject;
             } else {
                 $searchSources = new SearchSources();
                 $searchOptions = $searchSources->getSearchSources();
                 if (isset($searchOptions['marmot'])) {
                     //TODO: change name of search option to 'consortium'
                     $unscopedSearch = clone $searchObject;
                     $enableUnscopedSearch = true;
                 }
             }
         }
     }
     $showRatings = 1;
     $enableProspectorIntegration = isset($configArray['Content']['Prospector']) ? $configArray['Content']['Prospector'] : false;
     if (isset($library)) {
         $enableProspectorIntegration = $library->enablePospectorIntegration == 1;
         $showRatings = $library->showRatings;
     }
     if ($enableProspectorIntegration) {
         $interface->assign('showProspectorLink', true);
         $interface->assign('prospectorSavedSearchId', $searchObject->getSearchId());
     } else {
         $interface->assign('showProspectorLink', false);
     }
     $interface->assign('showRatings', $showRatings);
     $numUnscopedTitlesToLoad = 0;
     // Save the ID of this search to the session so we can return to it easily:
     $_SESSION['lastSearchId'] = $searchObject->getSearchId();
     // Save the URL of this search to the session so we can return to it easily:
     $_SESSION['lastSearchURL'] = $searchObject->renderSearchUrl();
     if (is_object($searchSource)) {
         $translatedSearch = $searchSource->label;
     } else {
         $allSearchSources = SearchSources::getSearchSources();
         if (!isset($allSearchSources[$searchSource]) && $searchSource == 'marmot') {
             $searchSource = 'local';
         }
         $translatedSearch = $allSearchSources[$searchSource]['name'];
     }
     // Save the search for statistics
     $analytics->addSearch($translatedSearch, $searchObject->displayQuery(), $searchObject->isAdvanced(), $searchObject->getFullSearchType(), $searchObject->hasAppliedFacets(), $searchObject->getResultTotal());
     // No Results Actions //
     if ($searchObject->getResultTotal() < 1) {
         //We didn't find anything.  Look for search Suggestions
         //Don't try to find suggestions if facets were applied
         $autoSwitchSearch = false;
         $disallowReplacements = isset($_REQUEST['disallowReplacements']) || isset($_REQUEST['replacementTerm']);
         if (!$disallowReplacements && (!isset($facetSet) || count($facetSet) == 0)) {
             require_once ROOT_DIR . '/services/Search/lib/SearchSuggestions.php';
             $searchSuggestions = new SearchSuggestions();
             $commonSearches = $searchSuggestions->getAllSuggestions($searchObject->displayQuery(), $searchObject->getSearchIndex());
             //assign here before we start popping stuff off
             $interface->assign('searchSuggestions', $commonSearches);
             //If the first search in the list is used 10 times more than the next, just show results for that
             $numSuggestions = count($commonSearches);
             if ($numSuggestions == 1) {
                 $firstSearch = array_pop($commonSearches);
                 $autoSwitchSearch = true;
             } elseif ($numSuggestions >= 2) {
                 $firstSearch = array_shift($commonSearches);
                 $secondSearch = array_shift($commonSearches);
                 $firstTimesSearched = $firstSearch['numSearches'];
                 $secondTimesSearched = $secondSearch['numSearches'];
                 if ($secondTimesSearched > 0 && $firstTimesSearched / $secondTimesSearched > 10) {
                     // avoids division by zero
                     $autoSwitchSearch = true;
                 }
             }
             // Switch to search with a better search term //
             //				$interface->assign('autoSwitchSearch', $autoSwitchSearch);
             if ($autoSwitchSearch) {
                 //Get search results for the new search
                 //					$interface->assign('oldTerm', $searchObject->displayQuery());
                 //					$interface->assign('newTerm', $commonSearches[0]['phrase']);
                 // The above assignments probably do nothing when there is a redirect below
                 $thisUrl = $_SERVER['REQUEST_URI'] . "&replacementTerm=" . urlencode($firstSearch['phrase']);
                 header("Location: " . $thisUrl);
                 exit;
             }
         }
         // No record found
         $interface->assign('recordCount', 0);
         // Was the empty result set due to an error?
         $error = $searchObject->getIndexError();
         if ($error !== false) {
             // If it's a parse error or the user specified an invalid field, we
             // should display an appropriate message:
             if (stristr($error['msg'], 'org.apache.lucene.queryParser.ParseException') || preg_match('/^undefined field/', $error['msg'])) {
                 $interface->assign('parseError', $error['msg']);
                 if (preg_match('/^undefined field/', $error['msg'])) {
                     // Setup to try as a possible subtitle search
                     $fieldName = trim(str_replace('undefined field', '', $error['msg'], $replaced));
                     // strip out the phrase 'undefined field' to get just the fieldname
                     $original = urlencode("{$fieldName}:");
                     if ($replaced === 1 && !empty($fieldName) && strpos($_SERVER['REQUEST_URI'], $original)) {
                         // ensure only 1 replacement was done, that the fieldname isn't an empty string, and the label is in fact in the Search URL
                         $new = urlencode("{$fieldName} :");
                         // include space in between the field name & colon to avoid the parse error
                         $thisUrl = str_replace($original, $new, $_SERVER['REQUEST_URI'], $replaced);
                         if ($replaced === 1) {
                             // ensure only one modification was made
                             header("Location: " . $thisUrl);
                             exit;
                         }
                     }
                 }
                 // Unexpected error -- let's treat this as a fatal condition.
             } else {
                 PEAR_Singleton::raiseError(new PEAR_Error('Unable to process query<br />' . 'Solr Returned: ' . $error));
             }
         }
         // Set up to try an Unscoped Search //
         $numUnscopedTitlesToLoad = 10;
         $timer->logTime('no hits processing');
     } elseif ($searchObject->getResultTotal() == 1 && (strpos($searchObject->displayQuery(), 'id') === 0 || $searchObject->getSearchType() == 'id')) {
         //Redirect to the home page for the record
         $recordSet = $searchObject->getResultRecordSet();
         $record = reset($recordSet);
         $_SESSION['searchId'] = $searchObject->getSearchId();
         if ($record['recordtype'] == 'list') {
             $listId = substr($record['id'], 4);
             header("Location: " . $configArray['Site']['path'] . "/MyResearch/MyList/{$listId}");
             exit;
         } elseif ($record['recordtype'] == 'econtentRecord') {
             $shortId = str_replace('econtentRecord', '', $record['id']);
             header("Location: " . $configArray['Site']['path'] . "/EcontentRecord/{$shortId}/Home");
             exit;
         } else {
             header("Location: " . $configArray['Site']['path'] . "/Record/{$record['id']}/Home");
             exit;
         }
     } else {
         $timer->logTime('save search');
         // Assign interface variables
         $summary = $searchObject->getResultSummary();
         $interface->assign('recordCount', $summary['resultTotal']);
         $interface->assign('recordStart', $summary['startRecord']);
         $interface->assign('recordEnd', $summary['endRecord']);
         $facetSet = $searchObject->getFacetList();
         $interface->assign('facetSet', $facetSet);
         //Check to see if a format category is already set
         $categorySelected = false;
         if (isset($facetSet['top'])) {
             foreach ($facetSet['top'] as $cluster) {
                 if ($cluster['label'] == 'Category') {
                     foreach ($cluster['list'] as $thisFacet) {
                         if ($thisFacet['isApplied']) {
                             $categorySelected = true;
                             break;
                         }
                     }
                 }
                 if ($categorySelected) {
                     break;
                 }
             }
         }
         $interface->assign('categorySelected', $categorySelected);
         $timer->logTime('load selected category');
     }
     // What Mode will search results be Displayed In //
     if ($displayMode == 'covers') {
         $displayTemplate = 'Search/covers-list.tpl';
         // structure for bookcover tiles
     } else {
         // default
         $displayTemplate = 'Search/list-list.tpl';
         // structure for regular results
         $displayMode = 'list';
         // In case the view is not explicitly set, do so now for display & clients-side functions
         // Process Paging (only in list mode)
         if ($searchObject->getResultTotal() > 1) {
             $link = $searchObject->renderLinkPageTemplate();
             $options = array('totalItems' => $summary['resultTotal'], 'fileName' => $link, 'perPage' => $summary['perPage']);
             $pager = new VuFindPager($options);
             $interface->assign('pageLinks', $pager->getLinks());
             if ($pager->isLastPage()) {
                 $numUnscopedTitlesToLoad = 5;
             }
         }
     }
     $timer->logTime('finish hits processing');
     $interface->assign('subpage', $displayTemplate);
     $interface->assign('displayMode', $displayMode);
     // For user toggle switches
     // Suplementary Unscoped Search //
     if ($enableUnscopedSearch && isset($unscopedSearch)) {
         // Total & Link will be shown in result header even if none of these results will be shown on this page
         $unscopedSearch->setLimit($numUnscopedTitlesToLoad * 4);
         $unscopedSearch->disableScoping();
         $unscopedSearch->processSearch(false, false);
         $numUnscopedResults = $unscopedSearch->getResultTotal();
         $interface->assign('numUnscopedResults', $numUnscopedResults);
         $unscopedSearchUrl = $unscopedSearch->renderSearchUrl();
         if (preg_match('/searchSource=(.*?)(?:&|$)/', $unscopedSearchUrl)) {
             $unscopedSearchUrl = preg_replace('/(.*searchSource=)(.*?)(&|$)(.*)/', '$1marmot$3$4', $unscopedSearchUrl);
             //				$unscopedSearchUrl = preg_replace('/&/', '&amp;', $unscopedSearchUrl);
             $unscopedSearchUrl = str_replace('&', '&amp;', $unscopedSearchUrl);
             // faster than preg_replace for simple substitutions
         } else {
             $unscopedSearchUrl .= "&amp;searchSource=marmot";
         }
         $unscopedSearchUrl .= "&amp;shard=";
         $interface->assign('unscopedSearchUrl', $unscopedSearchUrl);
         if ($numUnscopedTitlesToLoad > 0) {
             $unscopedResults = $unscopedSearch->getSupplementalResultRecordHTML($searchObject->getResultRecordSet(), $numUnscopedTitlesToLoad, $searchObject->getResultTotal());
             $interface->assign('recordSet', $unscopedResults);
             $unscopedResults = $interface->fetch($displayTemplate);
             $interface->assign('unscopedResults', $unscopedResults);
         }
     }
     // Big one - our results //
     $recordSet = $searchObject->getResultRecordHTML($displayMode);
     $interface->assign('recordSet', $recordSet);
     $timer->logTime('load result records');
     if ($configArray['Statistics']['enabled'] && isset($_GET['lookfor']) && !is_array($_GET['lookfor'])) {
         require_once ROOT_DIR . '/Drivers/marmot_inc/SearchStatNew.php';
         $searchStat = new SearchStatNew();
         $searchStat->saveSearch(strip_tags($_GET['lookfor']), strip_tags(isset($_GET['type']) ? $_GET['type'] : (isset($_GET['basicType']) ? $_GET['basicType'] : 'Keyword')), $searchObject->getResultTotal());
     }
     // Done, display the page
     $interface->setTemplate($searchObject->getResultTotal() ? 'list.tpl' : 'list-none.tpl');
     // main search results content
     $interface->assign('sidebar', 'Search/results-sidebar.tpl');
     $interface->display('layout.tpl');
 }
示例#7
0
 /**
  * Display the page.
  *
  * @return void
  * @access public
  */
 public function launch()
 {
     global $interface;
     global $configArray;
     global $analytics;
     // Process incoming parameters:
     $source = isset($_GET['source']) ? $_GET['source'] : false;
     $type = isset($_REQUEST['basicType']) ? $_REQUEST['basicType'] : $_REQUEST['type'];
     if ($source == false) {
         $searchSource = $_REQUEST['searchSource'];
         if (preg_match('/library\\d+/', $searchSource)) {
             $trimmedId = str_replace('library', '', $searchSource);
             $searchSourceObj = new LibrarySearchSource();
             $searchSourceObj->id = $trimmedId;
             if ($searchSourceObj->find(true)) {
                 $source = $searchSourceObj->searchWhat;
                 $source = str_replace('_browse', '', $source);
             }
         } else {
             if ($type) {
                 $source = $type;
                 if (strpos($source, 'browse') === 0) {
                     $source = substr($source, strlen('browse'));
                     $source = strtolower(substr($source, 0, 1)) . substr($source, 1);
                 }
             }
         }
     }
     $interface->assign('searchIndex', 'browse' . ucfirst($source));
     $from = isset($_GET['from']) ? $_GET['from'] : false;
     if ($from == false & isset($_REQUEST['lookfor'])) {
         $from = $_REQUEST['lookfor'];
     }
     $interface->assign('lookfor', $from);
     $page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 0;
     $limit = isset($configArray['AlphaBrowse']['page_size']) ? $configArray['AlphaBrowse']['page_size'] : 20;
     // If required parameters are present, load results:
     if ($source && $from !== false) {
         require_once ROOT_DIR . '/sys/AlphaBrowse.php';
         $alphaBrowse = new AlphaBrowse();
         $result = $alphaBrowse->getBrowseResults($source, $from, $page, $limit);
         // No results?  Try the previous page just in case we've gone past the
         // end of the list....
         if (!$result['success']) {
             $page--;
             $result = $alphaBrowse->getBrowseResults($source, $from, $page, $limit);
         }
         $allSearchSources = SearchSources::getSearchSources();
         $searchSource = isset($_REQUEST['searchSource']) ? $_REQUEST['searchSource'] : 'local';
         $translatedScope = $allSearchSources[$searchSource]['name'];
         $analytics->addSearch($translatedScope, $from, false, "alpha browse - {$type}", false, $result['totalCount']);
         if ($result['totalCount'] == 0) {
             $interface->assign('error', "No Results were found");
         } else {
             // Only display next/previous page links when applicable:
             if ($result['showNext']) {
                 $interface->assign('nextpage', $page + 1);
             }
             if ($result['showPrev']) {
                 $interface->assign('prevpage', $page - 1);
             }
             // Send other relevant values to the template:
             $interface->assign('source', $source);
             $interface->assign('from', $from);
             $interface->assign('result', $result);
         }
     }
     // We also need to load all the same details as the basic Home action:
     parent::launch();
 }
示例#8
0
 function getMoreSearchResults($displayMode = 'covers')
 {
     // Called Only for Covers mode //
     $success = true;
     // set to false on error
     //		$currentPage = isset($_REQUEST['pageToLoad']) ? $_REQUEST['pageToLoad'] : 1;
     //		$query = ltrim($_REQUEST['query'], '?');
     //		parse_str($query, $_REQUEST);
     //		$_REQUEST['page'] = $currentPage;
     // quick & dirty way to get search parameters
     // More involved method for grabbing variables
     //		parse_str($query, $searchParams);
     //		$test = array_merge($_REQUEST, $searchParams, array('page' => $currentPage));
     //		$_REQUEST = $test;
     if (isset($_REQUEST['view'])) {
         $_REQUEST['view'] = $displayMode;
     }
     // overwrite any display setting for now
     /** @var string|LibrarySearchSource|LocationSearchSource $searchSource */
     //		$searchSource = isset($searchParams['searchSource']) ? $searchParams['searchSource'] : 'local';
     $searchSource = isset($_REQUEST['searchSource']) ? $_REQUEST['searchSource'] : 'local';
     if (preg_match('/library\\d+/', $searchSource)) {
         $trimmedId = str_replace('library', '', $searchSource);
         $searchSourceObj = new LibrarySearchSource();
         $searchSourceObj->id = $trimmedId;
         if ($searchSourceObj->find(true)) {
             $searchSource = $searchSourceObj;
         }
     }
     // Initialise from the current search globals
     /** @var SearchObject_Solr $searchObject */
     $searchObject = SearchObjectFactory::initSearchObject();
     $searchObject->init($searchSource);
     //		if ($displayMode == 'covers') {
     $searchObject->setLimit(24);
     // a set of 24 covers looks better in display
     //		}
     // Process Search
     $result = $searchObject->processSearch(true, true);
     if (PEAR_Singleton::isError($result)) {
         PEAR_Singleton::raiseError($result->getMessage());
         $success = false;
     }
     $searchObject->close();
     // Process for Display //
     $recordSet = $searchObject->getResultRecordHTML($displayMode);
     //		if ($displayMode == 'covers'){
     $displayTemplate = 'Search/covers-list.tpl';
     // structure for bookcover tiles
     //		}
     //		else { // default
     //			$displayTemplate = 'Search/list-list.tpl'; // structure for regular results
     //		}
     global $interface;
     $interface->assign('recordSet', $recordSet);
     $records = $interface->fetch($displayTemplate);
     $result = array('success' => $success, 'records' => $records);
     // let front end know if we have reached the end of the result set
     if ($searchObject->getPage() * $searchObject->getLimit() >= $searchObject->getResultTotal()) {
         $result['lastPage'] = true;
     }
     return $result;
 }