Hier ist die von ilch.de, wie du siehst sind das auch einzelne Abfragen und ohne Union.
Noch als Hinweis, ilch.de arbeitet mit der Volltextsuche Funktion von MySQL MyISAM Tabellen, was dann erst für die jeweiligen Spalten "eingstellt" werden muss.
Auch die $hmenu Belegung ist bei ilch.de anders, also da ggf. auch noch nachbessern.
<?php
# Copyright by: Manuel Staechele
# Support: www.ilch.de
defined ('main') or die ( 'no direct access' );
function getmicrotime() {
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$search_time_start = getmicrotime();
function search_mark($text,$such) {
#$text = BBcode($text);
$serar = explode(' ', $such);
$text = strip_tags($text);
$text = stripslashes($text);
$rte = '';
$tleng = 30;
foreach($serar as $v) {
$firs = strpos(strtolower($text),strtolower($v));
$begi = (($firs - $tleng) < 0 ? 0 : $firs - $tleng );
$leng = strlen($text);
$ende = (($firs + strlen($v) + $tleng) > $leng ? $leng : $firs + strlen($v) + $tleng );
$ttxt = substr($text,$begi,($ende - $begi));
$rte .= ' ... '.preg_replace("/".$v."/si",'<b>'.$v.'</b>',$ttxt);
}
return ($rte);
}
function texts_escape_name ($n) {
$n = strtolower($n);
$n = preg_replace("/[^a-z0-9\ ]/","",$n);
$n = preg_replace("/\s+/","-",$n);
return ($n);
}
function search_finduser() {
$tpl = new tpl ('search_finduser');
$tpl->out(0);
if ( isset ( $_POST['sub'] ) AND !empty($_POST['name']) ) {
$name = str_replace('*',"%", escape($_POST['name'], 'string'));
$q = "SELECT name,name FROM prefix_user WHERE name like '".$name."'";
$tpl->set ('username',dbliste('',$tpl,'username',$q));
$tpl->out(1);
}
$tpl->out(2);
}
// Funktion ende
$such = '';
if ($menu->get(1) != '') {
$such = $menu->get(1);
} elseif (isset($_REQUEST['search'])) {
$such = $_REQUEST['search'];
}
$such = escape($such, 'string');
$page = 1;
if (isset($_GET['page']) AND preg_match("/^-p\d+$/", $_GET['page'])) {
$page = str_replace('-p','',$_GET['page']);
}
$limit = $allgAr['Fpanz']; // Limit
$anfang = ($page - 1) * $limit;
// Spezial Searches
if ($menu->get(1) == 'finduser') {
$design = new design ( 'Finduser' , '', 0 );
$design->header();
search_finduser();
$design->footer(1);
}
if ($such == 'augt' OR $such == 'aeit' OR $such == 'aubt') {
include 'include/contents/forum/search.php';
exit;
}
/*
if (empty($suche)) {
$design->footer(1);
}
$url = "http://ajax.googleapis.com/ajax/services/search/web";
$url .= "?v=1.0";
$url .= "&key=ABQIAAAA4emrgXSDJ79tDQ6bleEXjhQzvQ5MgZdBweJByYuyUKTELq98hBTvcuCEf5XOsoTX_9EAFpqjmp6mmw";
$url .= "&cx=001485819746409043381:9loriye7ybq";
$url .= "&start=".$start;
$url .= "&rsz=large";
$url .= "&q=".urlencode(utf8_encode($suche));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://www.ilch.de/search.html");
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body);
if (! isset($json->responseData->results) || count($json->responseData->results) == 0) {
echo '<br /><br />Es konnte nichts gefunden werden.';
$design->footer(1);
}
echo '<div style="width: 500px;">';
echo '<div style="float: right;">Ergebnisse '.($start+1).'-'.($start+8).' von ungefähr '.$json->responseData->cursor->estimatedResultCount.'</div>';
echo '<br style="clear: both;" /><br />';
foreach ($json->responseData->results as $result) {
echo '<a style="color: #971100;" href="'.$result->url.'">'.utf8_decode(str_replace('ilch.de :: ', '', $result->title)).'</a><br />';
echo utf8_decode($result->content);
#echo '<br /><span style="color: #88C984;">'.$result->unescapedUrl.'</span>';
echo '<br /><br />';
}
echo '</div>';
echo '<hr>';
foreach ($json->responseData->cursor->pages as $page) {
if (($page->start / 8) == $json->responseData->cursor->currentPageIndex) {
echo '<b>';
}
echo '<a href="index.php?search='.urlencode($suche).'&start='.$page->start.'">'.$page->label.'</a>';
if (($page->start / 8) == $json->responseData->cursor->currentPageIndex) {
echo '</b>';
}
echo ' | ';
}
echo '<a href="'.$json->responseData->cursor->moreResultsUrl.'">weitere Ergebnisse</a>';
if (is_admin()) {
#echo '<pre>';
#print_R($json);
}
*/
// normal Programm start
$snac = 'Suche';
if ( isset($_REQUEST['search']) ) {
$snac = 'nach: '.stripslashes($such);
}
$opts = array(
'search_forum' => 1,
'search_news' => 0,
'search_texts' => 1,
'search_downloads' => 0,
'sort_datum' => 0,
'sort_relevanz' => 1,
'opt_own' => 0,
'opt_titel' => 0,
'opt_oldposts' => 0
);
foreach ($opts as $k => $v) {
if (isset($_GET[$k]) AND ($_GET[$k] == 0 OR $_GET[$k] == 1)) {
$opts[$k] = $_GET[$k];
}
}
$title = $allgAr['title'].' :: Suchen :: '.htmlentities($snac);
$hmenu = array(array('?search' => 'Suchen'), htmlentities($snac));
$design = new design ( $title , $hmenu );
$design->header();
$tpl = new tpl ('search');
$tpl->set ('size', 30);
foreach ($opts as $k => $v) {
$tpl->set($k, $v);
}
$tpl->set_out('search',escape_for_fields(stripslashes($such)),0);
if (empty($such)) {
$design->footer(1);
}
function search_get_sort($sorts, $opts) {
$sort = '';
if ($opts['sort_datum'] == 1 || $opts['sort_relevanz'] == 1) {
if ($opts['sort_datum'] == 1) {
$sort .= $sorts['sort_datum'];
}
if ($opts['sort_relevanz'] == 1) {
if (! empty($sort)) {
$sort .= ", ";
}
$sort .= $sorts['sort_relevanz'];
}
$sort = " ORDER BY ".$sort;
}
return $sort;
}
function search_news($such, $opts) {
$sorts = array(
'sort_datum' => "time DESC",
'sort_relevanz' => "match(news_title, news_text) against ('".$such."') DESC",
);
$query_news = "SELECT
news_title as titel,
news_id as id,
news_time as time
FROM prefix_news
WHERE match(news_title, news_text) against ('".$such."' IN BOOLEAN MODE)";
$query_news .= search_get_sort($sorts, $opts);
$e = db_query($query_news) or die (mysql_error());
$anzahl = db_num_rows($e);
if ($anzahl == 0) {
echo '0 Treffer';
return false;
}
echo $anzahl.' Treffer<table id="search_table_news" style="display: none;">';
while ($r = db_fetch_assoc($e)) {
echo '<tr>';
echo '<td><a href="news-'.$r['id'].'.html">'.$r['titel'].'</a></td>';
echo '</tr>';
}
echo '</table>';
return $anzahl;
}
function search_forum($such, $opts) {
$sorts = array(
'sort_datum' => "prefix_posts.time DESC",
'sort_relevanz' => "match(txt) against ('".$such."') DESC",
);
$query_forum = "SELECT
prefix_topics.fid as fid,
prefix_topics.name as titel,
prefix_forums.name as fname,
prefix_topics.id as id,
prefix_posts.time as time,
prefix_posts.id as pid,
prefix_posts.tpos,
match(txt) against ('".$such."') as relevanz
FROM prefix_posts
LEFT JOIN prefix_topics ON prefix_topics.id = prefix_posts.tid
LEFT JOIN prefix_forums ON prefix_forums.id = prefix_topics.fid";
$query_forum .= " WHERE (prefix_forums.view >= ".$_SESSION['authright']." OR prefix_forums.reply >= ".$_SESSION['authright'].
" OR prefix_forums.start >= ".$_SESSION['authright'].") ".($opts['opt_oldposts'] == 0 ? ' AND prefix_posts.time > UNIX_TIMESTAMP(TIMESTAMPADD(YEAR, -1, NOW())) ' : '')."
AND match(txt) against ('".$such."' IN BOOLEAN MODE)";
if ($opts['opt_own'] == 1) {
$query_forum .= "AND prefix_posts.erstid = ".$_SESSION['authid'];
}
$query_forum .= " GROUP BY prefix_topics.id";
$query_forum .= search_get_sort($sorts, $opts);
$query_forum .= " LIMIT 100";
echo '<!-- '.$query_forum.' -->';
$e = db_query($query_forum) or die (mysql_error());
$anzahl = db_num_rows($e);
if ($anzahl == 0) {
echo '0 Treffer';
return false;
}
echo $anzahl.' Treffer<div id="search_table_forum" style="display: none;"><table cellpadding="4" cellspacing="1" class="border">';
echo '<tr class="Cdark"><th>Relevanz</th><th>Datum</th><th>Thema</th></tr>';
while ($r = db_fetch_assoc($e)) {
echo '<tr class="Cmite">';
echo '<td>'.round($r['relevanz'],2).'</td>';
echo '<td>'.date('d. M Y', $r['time']).'</td>';
echo '<td><a href="forum-showposts-'.$r['id'].'.html#'.$r['pid'].'">'.$r['titel'].'</a></td>';
echo '</tr>';
}
echo '</table></div>';
return $anzahl;
}
function search_texts($such, $opts) {
$sorts = array(
'sort_datum' => "datum DESC",
'sort_relevanz' => "match(`name`,`text`) against ('".$such."') DESC",
);
$query_texts = "SELECT
name AS titel,
id,
UNIX_TIMESTAMP(datum) as time
FROM prefix_texts
WHERE match(`name`,`text`) against ('".$such."' IN BOOLEAN MODE)";
$query_texts .= search_get_sort($sorts, $opts);
$e = db_query($query_texts) or die (mysql_error());
$anzahl = db_num_rows($e);
if ($anzahl == 0) {
echo '0 Treffer';
return false;
}
echo $anzahl.' Treffer<table id="search_table_texts" style="display: none;">';
while ($r = db_fetch_assoc($e)) {
echo '<tr>';
echo '<td><a href="texts-s'.$r['id'].'-'.texts_escape_name($r['titel']).'.html">'.$r['titel'].'</a></td>';
echo '</tr>';
}
echo '</table>';
return $anzahl;
}
function search_downloads($such, $opts) {
$sorts = array(
'sort_datum' => "time DESC",
'sort_relevanz' => " match(`descl`,`desc`,`name`,`version`) against ('".$such."') DESC",
);
$query_downloads = "SELECT
CONCAT( name, ' ', version ) AS titel,
id,
UNIX_TIMESTAMP(time) as time
FROM prefix_downloads
WHERE match(`descl`,`desc`,`name`,`version`) against ('".$such."' IN BOOLEAN MODE)";
$query_downloads .= search_get_sort($sorts, $opts);
$e = db_query($query_downloads) or die (mysql_error());
$anzahl = db_num_rows($e);
if ($anzahl == 0) {
echo '0 Treffer';
return false;
}
echo $anzahl.' Treffer<table id="search_table_downloads" style="display: none;">';
while ($r = db_fetch_assoc($e)) {
echo '<tr>';
echo '<td><a href="downloads-show-'.$r['id'].'.html">'.$r['titel'].'</a></td>';
echo '</tr>';
}
echo '</table>';
return $anzahl;
}
$oneOpen = false;
$toOpen = '';
if ($opts['search_forum'] == 1) {
echo '<fieldset><legend><a href="javascript:show_search_table(\'forum\');">Forum</a></legend>';
$anz = search_forum($such, $opts);
echo '</fieldset>';
if (!$oneOpen and $anz) {
$toOpen = 'forum';
$oneOpen = true;
}
}
if ($opts['search_texts'] == 1) {
echo '<fieldset><legend><a href="javascript:show_search_table(\'texts\');">Texts</a></legend>';
$anz = search_texts($such, $opts);
echo '</fieldset>';
if (!$oneOpen and $anz) {
$toOpen = 'texts';
$oneOpen = true;
}
}
if ($opts['search_downloads'] == 1) {
echo '<fieldset><legend><a href="javascript:show_search_table(\'downloads\');">Downloads</a></legend>';
$anz = search_downloads($such, $opts);
echo '</fieldset>';
if (!$oneOpen and $anz) {
$toOpen = 'downloads';
$oneOpen = true;
}
}
if ($opts['search_news'] == 1) {
echo '<fieldset><legend><a href="javascript:show_search_table(\'news\');">News</a></legend>';
$anz = search_news($such, $opts);
echo '</fieldset>';
if (!$oneOpen and $anz) {
$toOpen = 'news';
$oneOpen = true;
}
}
echo <<<HTML
<script>
$(document).ready(function () {
var first_search_table = '{$toOpen}';
if (first_search_table != '') { show_search_table(first_search_table); }
});
</script>
HTML;
$design->footer();
?>
<script language="JavaScript" type="text/javascript">
<!--
function searchHelp() {
alert("1.) schreib ein + vor ein Wort wenn das Wort vorkommen muss. z.B. +ilch +clan dann muessten beide Worte vorkommen.\n2.) schreib ein - vor ein Wort was nicht vorkommen darf. z.B. +ilch -clan\n3.) mach \" Zeichen um Woerter die zusammen gefunden werden sollen. z.B. \"ilch clan\" dann wird alles gefunden wo genau ilch clan vorkommt.");
}
function show_search_table(idx) {
var x = document.getElementById('search_table_'+idx);
if (x.style.display == 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
function search_check(idx) {
var x = document.getElementById(idx);
var y = document.getElementById('val_'+idx);
if (y.value == 1) {
y.value = 0;
x.style.fontWeight = 'normal';
} else {
y.value = 1;
x.style.fontWeight = 'bold';
}
}
$(document).ready(function (){
var elems = ['search_forum','search_texts','search_downloads','search_news','opt_own','opt_titel','opt_oldposts','sort_relevanz','sort_datum'];
$.each(elems, function (index, item) {
var x = document.getElementById(item);
var y = document.getElementById('val_'+item);
if (y.value == 0) {
x.style.fontWeight = 'normal';
} else {
x.style.fontWeight = 'bold';
}
});
});
//-->
</script>
<style type="text/css">
<!--
#search_forum_content {
}
.cfso {
padding: 0px 4px 0px 4px;
margin: 0px 5px 0px 5px;
cursor: pointer;
text-decoration: none;
}
/* .sta1 {
background-color: #F5FFEF;
}
.sta0 {
background-color: #FEF7F7;
} */
.cfso:hover {
background-color: #FFFFFF;
}
.cfso input {
display: none;
}
.rightbundig {
text-align: right;
}
-->
</style>
<form action="index.php" method="GET" id="search_forum_content">
<table><tr><td>
<input type="text" value="{search}" name="search" size="{size}" /> <input type="submit" value="{_lang_search}" /> <a href="javascript:searchHelp();">Hilfe</a>
<br />
<a href="javascript:search_check('search_forum')" class="cfso sta{search_forum}" id="search_forum"><input value="{search_forum}" name="search_forum" id="val_search_forum" />Forum</a>
<a href="javascript:search_check('search_texts')" class="cfso sta{search_texts}" id="search_texts"><input value="{search_texts}" name="search_texts" id="val_search_texts" />FAQ's</a>
<a href="javascript:search_check('search_downloads')" class="cfso sta{search_downloads}" id="search_downloads"><input value="{search_downloads}" name="search_downloads" id="val_search_downloads" />Downloads</a>
<a href="javascript:search_check('search_news')" class="cfso sta{search_news}" id="search_news"><input value="{search_news}" name="search_news" id="val_search_news" />News</a>
</td><td width="50">
</td><td>
<a href="javascript:search_check('opt_own')" class="cfso sta{opt_own}" id="opt_own"><input value="{opt_own}" name="opt_own" id="val_opt_own" />nur eigene Beiträge</a>
<a href="javascript:search_check('opt_titel')" class="cfso sta{opt_titel}" id="opt_titel"><input value="{opt_titel}" name="opt_titel" id="val_opt_titel" />nur im Titel</a>
<br />
<a href="javascript:search_check('opt_oldposts')" class="cfso sta{opt_oldposts}" id="opt_oldposts" title="Auch in Beiträgen suchen, die älter als 1 Jahr sind."><input value="{opt_oldposts}" name="opt_oldposts" id="val_opt_oldposts" />alte Beiträge durchsuchen</a>
<br />
Sortieren:
<a href="javascript:search_check('sort_relevanz')" class="cfso sta{sort_relevanz}" id="sort_relevanz"><input value="{sort_relevanz}" name="sort_relevanz" id="val_sort_relevanz" />nach Relevanz</a>
<a href="javascript:search_check('sort_datum')" class="cfso sta{sort_datum}" id="sort_datum"><input value="{sort_datum}" name="sort_datum" id="val_sort_datum" />Datum</a>
</td></tr></table>
</form>
<hr>
{EXPLODE}
<br /><br />
<div style="float: left">{MPL}</div>
<div style="float: right; text-align: right">Gesamt: {gAnz}</div><br /><br />
<table width="100%" cellpadding="2" cellspacing="1" border="0" class="border">
{EXPLODE}<tr class="{class}">
<td class="erstezeile" width="15"><img src="include/images/icons/search_{typ}.png" width="15" height="15" border="0"></td>
<td class="erstezeile" width="15"><img src="include/images/ilchbb_forum/{ord}.gif" title="{tord}" width="15" height="15" border="0"></td>
<td class="erstezeile"><a title="{fname}" href="index.php?{link}">{titel}</a></td>
</tr>{EXPLODE}
</table>
{MPL}
<br />
<div style="text-align:right"><a href="forum-markallasread.html" target="_self">alles als gelesen markieren</a></div>
<br />
Suche dauerte: {seitetime} Sekunden
Zuletzt modifiziert von Mairu am 15.02.2013 - 08:24:06