Exemple #1
0
 /**
  * Initialise the object from the global
  *  search parameters in $_REQUEST.
  *
  * @access  public
  * @var string|LibrarySearchSource|LocationSearchSource $searchSource
  * @return  boolean
  */
 public function init($searchSource = null)
 {
     global $module;
     global $action;
     // Call the standard initialization routine in the parent:
     parent::init($searchSource);
     $this->indexEngine->setSearchSource($searchSource);
     //********************
     // 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(null, true, true);
     if ($restored === true) {
         return true;
     } else {
         if (PEAR_Singleton::isError($restored)) {
             return false;
         }
     }
     //********************
     // Initialize standard search parameters
     $this->initView();
     $this->initPage();
     $this->initSort();
     $this->initFilters();
     //Marmot - search both ISBN-10 and ISBN-13
     //Check to see if the search term looks like an ISBN10 or ISBN13
     if (isset($_REQUEST['type']) && isset($_REQUEST['lookfor']) && ($_REQUEST['type'] == 'ISN' || $_REQUEST['type'] == 'Keyword' || $_REQUEST['type'] == 'AllFields') && (preg_match('/^\\d-?\\d{3}-?\\d{5}-?\\d$/', $_REQUEST['lookfor']) || preg_match('/^\\d{3}-?\\d-?\\d{3}-?\\d{5}-?\\d$/', $_REQUEST['lookfor']))) {
         require_once ROOT_DIR . '/sys/ISBN.php';
         $isbn = new ISBN($_REQUEST['lookfor']);
         $_REQUEST['lookfor'] = $isbn->get10() . ' OR ' . $isbn->get13();
     }
     //********************
     // Basic Search logic
     if ($this->initBasicSearch()) {
         // If we found a basic search, we don't need to do anything further.
     } else {
         if (isset($_REQUEST['tag']) && $module != 'MyResearch') {
             // Tags, just treat them as normal searches for now.
             // The search processer knows what to do with them.
             if ($_REQUEST['tag'] != '') {
                 $this->searchTerms[] = array('index' => 'tag', 'lookfor' => strip_tags($_REQUEST['tag']));
             }
         } else {
             $this->initAdvancedSearch();
         }
     }
     //********************
     // Author screens - handled slightly differently
     if ($module == 'Author') {
         // *** Things in common to both screens
         // Log a special type of search
         $this->searchType = 'author';
         // We don't spellcheck this screen
         //   it's not for free user intput anyway
         $this->spellcheck = false;
         // *** Author/Home
         if ($action == 'Home') {
             $this->searchSubType = 'home';
             // Remove our empty basic search (default)
             $this->searchTerms = array();
             // Prepare the search as a normal author search
             $this->searchTerms[] = array('index' => 'Author', 'lookfor' => trim(strip_tags($_REQUEST['author'])));
         }
         // *** Author/Search
         if ($action == 'Search') {
             $this->searchSubType = 'search';
             // We already have the 'lookfor', just set the index
             $this->searchTerms[0]['index'] = 'Author';
             // We really want author facet data
             $this->facetConfig = array();
             $this->addFacet('authorStr');
             // Offset the facet list by the current page of results, and
             // allow up to ten total pages of results -- since we can't
             // get a total facet count, this at least allows the paging
             // mechanism to automatically add more pages to the end of the
             // list so that users can browse deeper and deeper as they go.
             // TODO: Make this better in the future if Solr offers a way
             //       to get a total facet count (currently not possible).
             $this->facetOffset = ($this->page - 1) * $this->limit;
             $this->facetLimit = $this->limit * 10;
             // Sorting - defaults to off with unlimited facets, so let's
             //           be explicit here for simplicity.
             if (isset($_REQUEST['sort']) && $_REQUEST['sort'] == 'author') {
                 $this->setFacetSortOrder('index');
             } else {
                 $this->setFacetSortOrder('count');
             }
         }
     } else {
         if ($module == 'Search' && ($action == 'NewItem' || $action == 'Reserves')) {
             // We don't need spell checking
             $this->spellcheck = false;
             $this->searchType = strtolower($action);
         } else {
             if ($module == 'MyResearch') {
                 $this->spellcheck = false;
                 $this->searchType = $action == 'Home' ? 'favorites' : 'list';
             }
         }
     }
     // If a query override has been specified, log it here
     if (isset($_REQUEST['q'])) {
         $this->query = strip_tags($_REQUEST['q']);
     }
     return true;
 }