/** * 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; } } } }
echo '<ul>'; foreach ($mynotelist as $note) { echo '<li><a href="', $note->getHtmlUrl(), '" onclick="pasteid(\'', $note->getXref(), '\');"><span class="list_item">', $note->getFullName(), '</span></a></li>'; } echo '</ul> <p>', I18N::translate('Shared notes found'), ' ', count($mynotelist), '</p>'; } else { echo '<p>', I18N::translate('No results found.'), '</p>'; } echo '</div>'; } // Output Sources if ($type == "source") { echo '<div id="find-output">'; if ($filter) { $mysourcelist = FunctionsDb::searchSources($filter_array, array($WT_TREE)); } else { $mysourcelist = FunctionsDb::getSourceList($WT_TREE); } if ($mysourcelist) { usort($mysourcelist, '\\Fisharebest\\Webtrees\\GedcomRecord::compare'); echo '<ul>'; foreach ($mysourcelist as $source) { echo '<li><a href="', $source->getHtmlUrl(), '" onclick="pasteid(\'', $source->getXref(), '\', \'', Filter::escapeJs($source->getFullName()), '\');"><span class="list_item">', $source->getFullName(), '</span></a></li>'; } echo '</ul> <p>', I18N::translate('Total sources: %s', count($mysourcelist)), '</p>'; } else { echo '<p>', I18N::translate('No results found.'), '</p>'; } echo '</div>';