Exemple #1
0
 /**
  * Gathers results for a general search
  */
 private function generalSearch()
 {
     // Split search terms into an array
     $query_terms = array();
     $query = $this->query;
     // Words in double quotes stay together
     while (preg_match('/"([^"]+)"/', $query, $match)) {
         $query_terms[] = trim($match[1]);
         $query = str_replace($match[0], '', $query);
     }
     // Other words get treated separately
     while (preg_match('/[\\S]+/', $query, $match)) {
         $query_terms[] = trim($match[0]);
         $query = str_replace($match[0], '', $query);
     }
     //-- perform the search
     if ($query_terms && $this->search_trees) {
         // Write a log entry
         $logstring = "Type: General\nQuery: " . $this->query;
         Log::AddSearchlog($logstring, $this->search_trees);
         // Search the individuals
         if ($this->srindi && $query_terms) {
             $this->myindilist = FunctionsDb::searchIndividuals($query_terms, $this->search_trees);
         }
         // Search the fams
         if ($this->srfams && $query_terms) {
             $this->myfamlist = array_merge(FunctionsDb::searchFamilies($query_terms, $this->search_trees), FunctionsDb::searchFamilyNames($query_terms, $this->search_trees));
             $this->myfamlist = array_unique($this->myfamlist);
         }
         // Search the sources
         if ($this->srsour && $query_terms) {
             $this->mysourcelist = FunctionsDb::searchSources($query_terms, $this->search_trees);
         }
         // Search the notes
         if ($this->srnote && $query_terms) {
             $this->mynotelist = FunctionsDb::searchNotes($query_terms, $this->search_trees);
         }
         // If only 1 item is returned, automatically forward to that item
         // If ID cannot be displayed, continue to the search page.
         if (count($this->myindilist) == 1 && !$this->myfamlist && !$this->mysourcelist && !$this->mynotelist) {
             $indi = reset($this->myindilist);
             if ($indi->canShowName()) {
                 header('Location: ' . WT_BASE_URL . $indi->getRawUrl());
                 exit;
             }
         }
         if (!$this->myindilist && count($this->myfamlist) == 1 && !$this->mysourcelist && !$this->mynotelist) {
             $fam = reset($this->myfamlist);
             if ($fam->canShowName()) {
                 header('Location: ' . WT_BASE_URL . $fam->getRawUrl());
                 exit;
             }
         }
         if (!$this->myindilist && !$this->myfamlist && count($this->mysourcelist) == 1 && !$this->mynotelist) {
             $sour = reset($this->mysourcelist);
             if ($sour->canShowName()) {
                 header('Location: ' . WT_BASE_URL . $sour->getRawUrl());
                 exit;
             }
         }
         if (!$this->myindilist && !$this->myfamlist && !$this->mysourcelist && count($this->mynotelist) == 1) {
             $note = reset($this->mynotelist);
             if ($note->canShowName()) {
                 header('Location: ' . WT_BASE_URL . $note->getRawUrl());
                 exit;
             }
         }
     }
 }