/** * Initialise the object from the global * search parameters in $_REQUEST. * * @access public * @return boolean */ public function init() { // Call the standard initialization routine in the parent: parent::init(); //******************** // Check if we have a saved search to restore -- if restored successfully, // our work here is done; if there is an error, we should report failure; // if restoreSavedSearch returns false, we should proceed as normal. $restored = $this->restoreSavedSearch(); if ($restored === true) { return true; } else { if (PEAR_Singleton::isError($restored)) { return false; } } $this->initView(); $this->initPage(); $this->initSort(); // Try to find a basic search first; check for advanced if no basic found. if (!$this->initBasicSearch()) { $this->initAdvancedSearch(); } return true; }
/** * Load titles that have been rated by other users which are similar to this. * * @param SearchObject_Solr|SearchObject_Base $db * @param UserRating $ratedTitle * @param integer $userId * @param array $ratedTitles * @param array $suggestions * @param integer[] $notInterestedTitles * @return int The number of suggestions for this title */ static function getSimilarlyRatedTitles($db, $ratedTitle, $userId, $ratedTitles, &$suggestions, $notInterestedTitles) { $numRecommendations = 0; //If there is no ISBN, can we come up with an alternative algorithm? //Possibly using common ratings with other patrons? //Get a list of other patrons that have rated this title and that like it as much or more than the active user.. $otherRaters = new UserRating(); //Query the database to get items that other users who rated this liked. $sqlStatement = "SELECT resourceid, record_id, " . " sum(case rating when 5 then 10 when 4 then 6 end) as rating " . " FROM `user_rating` inner join resource on resource.id = user_rating.resourceid WHERE userId in " . " (select userId from user_rating where resourceId = " . $ratedTitle->resourceid . " and rating >= 4 " . " and userid != " . $userId . ") " . " and rating >= 4 " . " and resourceId != " . $ratedTitle->resourceid . " and deleted = 0 " . " group by resourceid order by rating desc limit 10"; //Sort so the highest titles are on top and limit to 10 suggestions. $otherRaters->query($sqlStatement); if ($otherRaters->N > 0) { //Other users have also rated this title. while ($otherRaters->fetch()) { //Process the title disableErrorHandler(); if (!($ownedRecord = $db->getRecord($otherRaters->record_id))) { //Old record which has been removed? Ignore for purposes of suggestions. continue; } enableErrorHandler(); //get the title from the Solr Index if (isset($ownedRecord['isbn'])) { if (strpos($ownedRecord['isbn'][0], ' ') > 0) { $isbnInfo = explode(' ', $ownedRecord['isbn'][0]); $isbn = $isbnInfo[0]; } else { $isbn = $ownedRecord['isbn'][0]; } $isbn13 = strlen($isbn) == 13 ? $isbn : ISBNConverter::convertISBN10to13($isbn); $isbn10 = strlen($isbn) == 10 ? $isbn : ISBNConverter::convertISBN13to10($isbn); } else { $isbn13 = ''; $isbn10 = ''; } //See if we can get the series title from the record if (isset($ownedRecord['series'])) { $series = $ownedRecord['series'][0]; } else { $series = ''; } $similarTitle = array('title' => $ownedRecord['title'], 'title_short' => $ownedRecord['title_short'], 'author' => isset($ownedRecord['author']) ? $ownedRecord['author'] : '', 'publicationDate' => $ownedRecord['publishDate'], 'isbn' => $isbn13, 'isbn10' => $isbn10, 'upc' => isset($ownedRecord['upc']) ? $ownedRecord['upc'][0] : '', 'recordId' => $ownedRecord['id'], 'id' => $ownedRecord['id'], 'libraryOwned' => true, 'isCurrent' => false, 'shortId' => substr($ownedRecord['id'], 1), 'format_category' => isset($ownedRecord['format_category']) ? $ownedRecord['format_category'] : '', 'format' => $ownedRecord['format'], 'recordtype' => $ownedRecord['recordtype'], 'series' => $series, 'grouping_term' => $ownedRecord['grouping_term']); $numRecommendations++; Suggestions::addTitleToSuggestions($ratedTitle, $similarTitle['title'], $similarTitle['recordId'], $similarTitle, $ratedTitles, $suggestions, $notInterestedTitles); } } return $numRecommendations; }
/** * Get an array of strings to attach to a base URL in order to reproduce the * current search. * * @access protected * @return array Array of URL parameters (key=url_encoded_value format) */ protected function getSearchParams() { $params = parent::getSearchParams(); $params[] = 'genealogyType=' . $_REQUEST['genealogyType']; return $params; }
/** * Get information on the current state of the boolean checkbox facets. * * @return array * @access public */ public function getCheckboxFacets() { // Grab checkbox facet details using the standard method: $facets = parent::getCheckboxFacets(); // Special case -- if we have a "holdings only" facet, we want this to // always appear, even on the "no results" screen, since setting this // facet actually EXPANDS the result set, rather than reducing it: if (isset($facets['holdingsOnly'])) { $facets['holdingsOnly']['alwaysVisible'] = true; } // Return modified list: return $facets; }
/** * Add a field to facet on. * * @access public * @param string $newField Field name * @param string $newAlias Optional on-screen display label */ public function addFacet($newField, $newAlias = null) { // Save the full field name (which may include extra parameters); // we'll need these to do the proper search using the Summon class: $this->fullFacetSettings[] = $newField; // Strip parameters from field name if necessary (since they get // in the way of most Search Object functionality): $newField = explode(',', $newField); $newField = trim($newField[0]); parent::addFacet($newField, $newAlias); }
/** * Load all recommendation settings from the relevant ini file. Returns an * associative array where the key is the location of the recommendations (top * or side) and the value is the settings found in the file (which may be either * a single string or an array of strings). * * @access protected * @return array associative: location (top/side) => search settings */ protected function getRecommendationSettings() { // Special hard-coded case for author module. We should make this more // flexible in the future! // Marmot hard-coded case and use searches.ini and facets.ini instead. /*if ($this->searchType == 'author') { return array('side' => array('SideFacets:Author')); }*/ // Use default case from parent class the rest of the time: return parent::getRecommendationSettings(); }
/** * Load all recommendation settings from the relevant ini file. Returns an * associative array where the key is the location of the recommendations (top * or side) and the value is the settings found in the file (which may be either * a single string or an array of strings). * * @return array associative: location (top/side) => search settings * @access protected */ protected function getRecommendationSettings() { // Special case for author module. Use settings from searches.ini if // present; default to old hard-coded defaults otherwise for legacy // compatibility. if ($this->searchType == 'author') { $searchSettings = getExtraConfigArray('searches'); return isset($searchSettings['AuthorModuleRecommendations']) ? $searchSettings['AuthorModuleRecommendations'] : array('side' => array('ExpandFacets:Author')); } // Use default case from parent class the rest of the time: return parent::getRecommendationSettings(); }
/** * Return the field (index) searched by a basic search * * @return string The searched index * @access public */ public function getSearchIndex() { // Use normal parent method for non-advanced searches. if ($this->searchType == $this->basicSearchType) { return parent::getSearchIndex(); } else { return null; } }
private function getBrowseCategoryResults($pageToLoad = 1) { $browseMode = $this->setBrowseMode(); if ($pageToLoad == 1 && !isset($_REQUEST['reload'])) { // only first page is cached global $memCache, $solrScope; $key = 'browse_category_' . $this->textId . '_' . $solrScope . '_' . $browseMode; $browseCategoryInfo = $memCache->get($key); if ($browseCategoryInfo != false) { return $browseCategoryInfo; } } $result = array('result' => false); $browseCategory = $this->getBrowseCategory(); if ($browseCategory) { global $interface; $interface->assign('browseCategoryId', $this->textId); $result['result'] = true; $result['textId'] = $browseCategory->textId; $result['label'] = $browseCategory->label; //$result['description'] = $browseCategory->description; // the description is not used anywhere on front end. plb 1-2-2015 // User List Browse Category // if ($browseCategory->sourceListId != null && $browseCategory->sourceListId > 0) { require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php'; $sourceList = new UserList(); $sourceList->id = $browseCategory->sourceListId; if ($sourceList->find(true)) { $records = $sourceList->getBrowseRecords(($pageToLoad - 1) * self::ITEMS_PER_PAGE, self::ITEMS_PER_PAGE); } else { $records = array(); } $result['searchUrl'] = '/MyAccount/MyList/' . $browseCategory->sourceListId; // Search Browse Category // } else { $this->searchObject = SearchObjectFactory::initSearchObject(); $defaultFilterInfo = $browseCategory->defaultFilter; $defaultFilters = preg_split('/[\\r\\n,;]+/', $defaultFilterInfo); foreach ($defaultFilters as $filter) { $this->searchObject->addFilter(trim($filter)); } //Set Sorting, this is actually slightly mangled from the category to Solr $this->searchObject->setSort($browseCategory->getSolrSort()); if ($browseCategory->searchTerm != '') { $this->searchObject->setSearchTerm($browseCategory->searchTerm); } //Get titles for the list $this->searchObject->clearFacets(); $this->searchObject->disableSpelling(); $this->searchObject->disableLogging(); $this->searchObject->setLimit(self::ITEMS_PER_PAGE); $this->searchObject->setPage($pageToLoad); $this->searchObject->processSearch(); $records = $this->searchObject->getBrowseRecordHTML(); $result['searchUrl'] = $this->searchObject->renderSearchUrl(); //TODO: Check if last page // Shutdown the search object $this->searchObject->close(); } if (count($records) == 0) { $records[] = $interface->fetch('Browse/noResults.tpl'); } $result['records'] = implode('', $records); $result['numRecords'] = count($records); } // Store first page of browse category in the MemCache if ($pageToLoad == 1) { global $memCache, $configArray, $solrScope; $key = 'browse_category_' . $this->textId . '_' . $solrScope . '_' . $browseMode; $memCache->add($key, $result, 0, $configArray['Caching']['browse_category_info']); } return $result; }
/** * Initialise the object from the global * search parameters in $_REQUEST. * * @return boolean * @access public */ public function init() { // Call the standard initialization routine in the parent: parent::init(); $this->initView(); $this->initPage(); $this->initSort(); $this->initFilters(); //******************** // Basic Search logic return $this->initBasicSearch(); }