Sökformulär
Opublikowany przez:
familie
2006-03-23 12:58:21
$xQ = "";
if (!empty($forum)) { $xQ .= " forum=$forum"; }
if (!empty($community)) { $xQ .= " community=$community"; }
if (!empty($category)) { $xQ .= " category=$category"; }
if (!empty($trade)) { $xQ .= " trade=$trade"; }
if (!empty($area)) { $xQ .= " area=$area"; }
if (!empty($Q)) { $xQ .= " " . str_replace(" ", " ", trim($Q)); }
if (!empty($QAny)) { $xQ .= " or (" . str_replace(" ", " or ", str_replace(" ", " ", trim($QAny))) . ")"; }
if (!empty($QWithout)) { $xQ .= " not (" . str_replace(" ", " or ", str_replace(" ", " ", trim($QWithout))) . ")"; }
if (!empty($QPhrase)) { $xQ .= " \"" . trim($QPhrase) . "\""; }
$xQ = trim($xQ);
if (!empty($QDate)) { $limit = "-L swishlastmodified " . (time()-(60*24*7*4*$QDate)) . " " . time(); }
else { $limit = ""; }
if (!empty($QField)) { $field = "-t $QField"; }
else { $field = ""; }
if (!empty($QSort)) {
if ($QSort == "d") { $sort = "-s swishlastmodified desc"; }
elseif ($QSort == "t") { $sort = "-s swishtitle asc"; }
else { $sort = ""; }
} else { $sort = ""; }
if (!empty($QDB)) { $DB = "-f $DOCUMENT_ROOT/../data/index/$QDB"; }
else { $DB = "-f $DOCUMENT_ROOT/../data/index/forum.index $DOCUMENT_ROOT/../data/index/trade.index $DOCUMENT_ROOT/../data/index/user_presentation.index"; }
if (!empty($xQ)) {
$start = (($page-1) * $pagesize)+1;
$result = shell_exec("/usr/local/bin/swish-e $DB -w '$xQ' -m $pagesize -b $start $limit $field $sort -x '%c|%r|%p|%t|%D|%d||\n'");
//if ($REMOTE_ADDR == "84.55.65.90") {
// echo $result;
//}
if (!empty($debug)) echo "" . nl2br($result) . "
";
//echo "$limit ";
$stopwords = "";
$hits = 0;
$search_time = 0;
$run_time = 0;
$lines = explode("\n", $result);
$docs = array();
for ($i=0; $i
if (count($docs)>0) { ?>Resultat echo $docs[0][0] . "-" . $docs[count($docs)-1][0]; ?> av totalt echo number_format($hits, 0, " ", " "); ?> sökträffar (söktid echo $run_time; ?> sekunder)
} else { ?> Ingen sökträff! } ?> if (!empty($stopwords)) { ?>
OBS: Det går inte att söka på echo "'" . ov(str_replace(" ", ", ", $stopwords)) . "'"; ?> (se nedan*)
} ?>
$communitylist = array();
$communitylist[5] = "Allmänna diskussioner";
$communitylist[1] = "Planerar barn";
$communitylist[7] = "Svårt att få barn";
$communitylist[2] = "Väntar barn";
$communitylist[3] = "Förälder";
$communitylist[6] = "Pappagrupp";
$communitylist[4] = "Känsliga rummet";
$forumlist = array();
$fid = db_query("SELECT * FROM forums");
while ($f = db_fetch_object($fid)) {
$forumlist["$f->forum"] = $f->title;
}
//Remove stopwords in all of the query parameters and put them in an array
$xstopwords = explode(" ", strtolower(trim($stopwords)));
$tempQ = strtolower(trim($Q));
$tempQPhrase = strtolower(trim($QPhrase));
$tempQWithout = strtolower(trim($QWithout));
$tempQAny = strtolower(trim($QAny));
for ($i=0; $i < count($xstopwords); $i++) {
$tempQ = str_replace(" ", " ", str_replace($xstopwords[$i], "", $tempQ));
$tempQPhrase = str_replace(" ", " ", str_replace($xstopwords[$i], "", $tempQPhrase));
$tempQWithout = str_replace(" ", " ", str_replace($xstopwords[$i], "", $tempQWithout));
$tempQAny = str_replace(" ", " ", str_replace($xstopwords[$i], "", $tempQAny));
}
$aQ = explode(" ", $tempQ);
$aQPhrase = explode(" ", $tempQPhrase);
$aQWithout = explode(" ", $tempQWithout);
$aQAny = explode(" ", $tempQAny);
//Iterate through page result
foreach ($docs as $doc) {
if ($doc[6] == "forum") {
preg_match("/^\/Forum-([0-9]+)-([0-9F]+)\/m([0-9]+)(-([0-9]+))?\.html/i", $doc[2], $matches);
if (isset($matches[1])) { $Xcommunity = $matches[1]; }
if (isset($matches[2])) { $Xforum = $matches[2]; }
if (isset($matches[3])) { $Xmessage = $matches[3]; }
if (isset($matches[5])) { $page = $matches[5]; }
//Output title/subject
echo "" . ov($doc[3]) . " ";
//Fetch the first message that got a hit
$tid = db_query("SELECT forum_threads.* FROM forum_threads WHERE message='$Xmessage'");
if ($rt = db_fetch_object($tid)) {
//Go through this thread and try to find the first message that got a hit
$mid = db_query("SELECT body FROM $rt->db WHERE parent='$Xmessage' ORDER BY created LIMIT 1");
$msg_nr = 0;
$msghit = "";
while ($r = db_fetch_object($mid)) {
$msg_nr++;
$t = removeEvilTags($r->body, "");
//In case we do not find the hit in this thread, we save the first message we got
if (empty($msghit) && !empty($t)) { $msghit = $t; }
//Check if all words in the query has been found
$found = true;
for ($i; $i < count($aQ); $i++) {
if (empty($aQ[$i])) { continue; }
if (strpos($t, $aQ[$i]) === false) { $found = false; }
if (!$found) { break; }
}
if ($found) {
$msghit = $t;
break;
}
}
echo ov(wrap_long_words(get_focus($msghit, 160), 40)) . " ";
echo "$_SERVER[HTTP_HOST]$doc[2] ";
echo "";
echo "Forum: " . ov($communitylist["$Xcommunity"]) . " - " . ov($forumlist["$Xforum"]) . " ";
$created_by = strtr($rt->created_by, "\"'", " ");
if ($created_by != "Anonym" && $created_by <> " ") {
$user_link = "/krypin/" . get_normalized_string($rt->created_by) . "/presentation.php";
} else { $user_link = ""; }
echo "Trådstart: " . o(display_date($rt->created, 2)) . " ";
echo " av ";
if (!empty($user_link)) {
echo "" . ov($created_by) . " ";
} else {
echo "" . o($created_by) . " ";
}
$replied_by = strtr($rt->nick, "\"'", " ");
if (!empty($replied_by) && $replied_by != "Anonym") {
$user_link = "/krypin/" . get_normalized_string($rt->nick) . "/presentation.php";
} else {
$user_link = "";
}
echo "Senaste svar: ";
if ($rt->latest <> $rt->created) {
echo "";
if ($rt->latest>date('Y-m-d H:i:s', time()+240)) { echo o("Fäst av moderator"); }
else { echo o(display_date($rt->latest, 2)); }
echo " ";
echo " av ";
if (!empty($user_link)) {
echo "" . ov($replied_by) . " ";
} else {
echo "" . o($replied_by) . " ";
}
} else {
echo "(Ingen har svarat)";
}
echo " ";
}
} elseif ($doc[6] == "trade") {
preg_match("/^\/Annonser\/\?details=([0-9]+)/i", $doc[2], $matches);
if (isset($matches[1])) { $id= $matches[1]; }
echo "" . ov($doc[3]) . " ";
$mid = db_query("SELECT trade.*
FROM trade
WHERE trade.id = $id AND active = 1");
if ($r = db_fetch_object($mid)) {
$t = removeEvilTags($r->description, "");
echo ov(wrap_long_words(get_focus($t, 160), 40)) . " ";
}
echo "$_SERVER[HTTP_HOST]$doc[2] ";
echo "";
if ($r->trade == "kop") { $trade = "Köpes"; }
elseif ($r->trade == "salj") { $trade = "Säljes"; }
else { $trade = ""; }
echo "Typ: $trade Ort: " . ov($r->area) . " Inlaggd: " . o(display_date($r->created, 2)) . " ";
echo " ";
} elseif ($doc[6] == "presentation") {
preg_match("/^\/krypin\/(.+)\/presentation\.php/i", $doc[2], $matches);
if (isset($matches[1])) { $normalized_nick = $matches[1]; }
//echo "$doc[0] ";
echo "" . ov($doc[3]) . " ";
$mid = db_query("SELECT user_presentations.*, users.nick
FROM users, user_presentations
WHERE users.userid = user_presentations.userid AND users.normalized_nick='$normalized_nick'");
if ($r = db_fetch_object($mid)) {
$t = removeEvilTags($r->text, "");
echo ov(wrap_long_words(get_focus($t, 160), 40)) . " ";
}
echo "$_SERVER[HTTP_HOST]$doc[2] ";
echo "";
echo "Medlem: " . ov($r->nick) . " Storlek: $doc[7] ";
echo " ";
}
}
?>
if (!empty($stopwords)) { ?>
*) Vissa ord är s.k. stoppord, de förekommer oftast i mer än 50% av innehållet och är därför inte indexerade eller sökbara. Exempel på sådana ord är "och", "man", "jag", "vi" osv. Försök att istället söka på
mer innehållsrika och beskrivande ord för att öka relevansen i resultatet.
} ?>
} ?>
Sökfunktionen är ur funktion för tillfället, vi arbetar med att få igång den så fort som möjligt