Volltextsuche für 4.4.4
Verfasst: Di 2. Nov 2004, 21:35
Hallo,
ich habe bis jetzt noch keine Volltextsuche funktionierend hinbekommen:
Ich habe folgende gefunden:
Volltextsuche
INPUT
OUTPUT
Volltextsuche Formular
nur Output
Allerdings wie auch bei vielen anderen Volltextsuchen erhalte ich folgendes im ErrorLog:
Ich benutze 4.4.4
Achso zur Ausgabe musste ich noch folgende Dateien anlegen und ins Template Verzeichnis schieben:
search_found.html
search_notfound.html
Das Komische an der ganzen Sache ist, dass die Volltextsuche mal funktioniert hatte, aber nach ziemlich vielen Änderungen an Layout und Kategorien und Strukturen funktionierte die Suche dann irgendwann nicht mehr
ich habe bis jetzt noch keine Volltextsuche funktionierend hinbekommen:
Ich habe folgende gefunden:
Volltextsuche
INPUT
Code: Alles auswählen
$linktarget = "CMS_VALUE[1]";
$extratext = "CMS_VALUE[2]";
if($linktarget == "") {
$linktarget = "_self";
}
if($extratext == "") {
$extratext = 0;
}
?>
<table>
<tr>
<td>Linktarget</td>
<td>
<select name="CMS_VAR[1]">
<option value="_self"<? if(strcmp("_self", $linktarget) == 0) echo " selected"; ?>>gleiches Fenster (_self)</option>
<option value="_new"<? if(strcmp("_new", $linktarget) == 0) echo " selected"; ?>>neues Fenster (_new)</option>
</select>
</td>
</tr>
<tr>
<td>Zusätzlicher Text zum Artikellink</td>
<td>
<select name="CMS_VAR[2]">
<option value="0"<? if($extratext == 0) echo " selected"; ?>>kein zusätzlicher Text</option>
<option value="1"<? if($extratext == 1) echo " selected"; ?>>Artikelkommentar</option>
<option value="2"<? if($extratext == 2) echo " selected"; ?>>Anfang des Artikeltextes</option>
</select>
</td>
</tr>
</table>
<?
Code: Alles auswählen
<?php
//$linkziel = "front_content.php?idcat=35";
$linkziel = $auth->url();
$ignore_konj = array("und","oder","als","wenn","auch","wo","wie");
$ignore_art = array("der","die","das","ein","eine");
$ignore = array("ich","du","er","sie","es","wir","ihr","sie");
$extratextLength = 200;
$suchtext = $_POST["suchtext"];
?>
<form name="suche" action="<?= $linkziel ?>" method="post">
<table>
<tr>
<td><input name="suchtext" type="text" size="20" value="<?= $suchtext ?>"></td>
<td><input name="submit" type="submit" value="suchen" class="button"></td>
</tr>
</table>
</form>
<?php
$linktarget = "CMS_VALUE[1]";
$extratext = "CMS_VALUE[2]";
/* DB Instances */
$db = new DB_Contenido;
$db2 = new DB_Contenido;
/* Template Instance */
include_once($cfg["path"]["contenido"] . "/classes/class.template.php");
$tpl = new Template;
if($suchtext != "") {
while(ereg(' ', $suchtext)) {
$suchtext = ereg_replace(' ', ' ', $suchtext);
}
$suchliste = explode(" ", strtolower($suchtext));
$suchliste = array_diff($suchliste, $ignore_konj, $ignore_art, $ignore);
$suchtext = trim(implode(" ", $suchliste));
if($verknuepfung == "oder") {
$suchregexp = "(" . str_replace(" ", ")|(", $suchtext) . ")";
$s = ereg_replace("ü", "%FC", strtolower($suchtext));
$s = ereg_replace("ä", "%E4", $s);
$s = ereg_replace("ö", "%F6", $s);
$suchregexp .= "|$s";
$sql = "SELECT " .
"A.title AS title, " .
"A.idart AS idart, " .
"A.summary AS comment, " .
"B.idcat AS idcat, " .
"D.value AS content, " .
"A.idartlang AS sideid " .
"FROM " .
$cfg["tab"]["art_lang"] . " AS A, " .
$cfg["tab"]["cat_art"] . " AS B, " .
$cfg["tab"]["cat"] . " AS C, " .
$cfg["tab"]["content"] . " AS D " .
"WHERE " .
"A.idart = B.idart " .
"AND A.idartlang = D.idartlang " .
"AND B.idcat = C.idcat " .
"AND C.idclient = '$client' " .
"AND idlang = '$lang' " .
"AND online='1' " .
"AND (D.value REGEXP '" . $suchregexp . "' " .
"OR A.title REGEXP '" . $suchregexp . "' " .
"OR A.summary REGEXP '" . $suchregexp . "')";
} // end if($verkuepfung)
else {
$sql = "SELECT " .
"A.title AS title, " .
"A.idart AS idart, " .
"A.summary AS comment, " .
"B.idcat AS idcat, " .
"D.value AS content, " .
"A.idartlang AS sideid " .
"FROM " .
$cfg["tab"]["art_lang"] . " AS A, " .
$cfg["tab"]["cat_art"] . " AS B, " .
$cfg["tab"]["cat"] . " AS C, " .
$cfg["tab"]["content"]." AS D " .
"WHERE " .
"A.idart = B.idart " .
"AND A.idartlang = D.idartlang " .
"AND B.idcat = C.idcat " .
"AND C.idclient = '$client' " .
"AND idlang = '$lang' " .
"AND online = '1'";
while(list($key, $val) = each($suchliste)) {
$suchregexp = "(" . str_replace(" ", ")|(", $val) . ")";
$s = ereg_replace("ü", "%FC", strtolower($val));
$s = ereg_replace("ä", "%E4", $s);
$s = ereg_replace("ö", "%F6", $s);
$suchregexp .= "|$s";
$sql .= " AND (D.value REGEXP '" . $suchregexp . "' " .
"OR A.title REGEXP '" . $suchregexp . "' " .
"OR A.summary REGEXP '" . $suchregexp . "')";
} // end while
reset($suchliste);
} // end else($verknuepfung)
$db->query($sql);
if($db->num_rows() != 0){
while($db->next_record()) {
if ($auth->auth["uid"] == "nobody"){
$sql2 = "SELECT " .
"public " .
"FROM " .
$cfg["tab"]["cat_lang"] . " " .
"WHERE " .
"idcat = '" . $db->f("idcat") . "'";
$db2->query($sql2);
if($db2->next_record()) {
if($db2->f("public") == 0) {
continue;
} // end if(public)
} // end if(next_record)
} // end if(auth nobody)
$num = 0 + $db->f("sideid");
$results[$num][link] = "front_content.php?" .
"client=" . $client .
"&lang=" . $lang .
"&idcat=" . $db->f("idcat") .
"&idart=" . $db->f("idart");
$results[$num][title] = $db->f("title");
//anzuzeigenden Text ermitteln
switch($extratext) {
case 0:
$results[$num][text] = "";
break;
case 1:
$results[$num][text] = nl2br($db->f("comment"));
break;
case 2:
$results[$num][text] = capiStrTrimSentence(strip_tags(urldecode($db->f("content")), "<br><br/><br />"), $extratextLength) . "...";
$results[$num][text] = nl2br($results[$num][text]);
break;
} // end switch
// unnötige Zeilenumbrüche entfernen
$results[$num][text] = preg_replace("/(?s)^(\<br(.?)(\/?)\>(\\r\\n)?(\ |\040)*)+/", "", $results[$num][text]);
$results[$num][text] = preg_replace("/(?s)(\<br(.?)(\/?)\>(\\r\\n)?(\ |\040)*)+/", "<br />", $results[$num][text]);
while(list($key, $val) = each($suchliste)) {
$hits[$num] += substr_count(strtolower(strip_tags(urldecode($db->f("title")))), $val) +
substr_count(strtolower(strip_tags(urldecode($db->f("comment")))), $val) +
substr_count(strtolower(strip_tags(urldecode($db->f("content")))), $val);
} // end while
reset($suchliste);
} // end while(next_record)
if(count($hits) > 0) {
//anzahl hits speichern
$anzahlhits = count($hits);
$hits = array_values($hits);
$results = array_values($results);
array_multisort ($results, SORT_DESC, SORT_NUMERIC, $hits, SORT_DESC, SORT_NUMERIC);
} // end if(count hits)
} // end if(num_rows)
//Ausgabe-----------------
/* Start Output buffer */
ob_start();
if(count($hits) > 0) {
$tpl->reset();
$tpl->set('s', 'SUCHTEXT', $suchtext);
$tpl->set('s', 'TREFFER', $anzahlhits);
for($i = 0; $i < count($hits); $i++) {
$tpl->set('d', 'ARTIKELNAME', $results[$i][title]);
$tpl->set('d', 'TARGET', $linktarget);
$tpl->set('d', 'HREF', $results[$i][link]);
$tpl->set('d', 'TEXT', $results[$i][text]);
$tpl->next();
}
$tpl->generate('templates/search_found.html');
} // end if(count hits)
else {
$tpl->reset();
$tpl->set('s', 'SUCHTEXT', $suchtext);
$tpl->generate('templates/search_notfound.html');
} // end else (count hits)
} // end if(suchtext)
/* Read out buffer */
$html = ob_get_contents();
/* Clean buffer */
ob_end_clean();
/* Output buffer-contents */
echo $html;
?>
nur Output
Code: Alles auswählen
<?php
$linkziel = "front_content.php?idcat=35";
//$linkziel = $auth->url();
?>
<form name="suche" action="<?= $linkziel ?>" method="post">
<table>
<tr>
<td align="center"><input name="suchtext" type="text" size="16"></td>
</tr>
<tr>
<td align="center"><input class="button" name="submit" type="submit" value="suchen"></td>
</tr>
</table>
</form>
Kann jemand damit was anfangen und helfen?[02-Nov-2004 21:31:13] PHP Warning: Cannot use a scalar value as an array in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 752
[02-Nov-2004 21:31:13] PHP Warning: Cannot use a scalar value as an array in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 752
[02-Nov-2004 21:31:13] PHP Warning: Cannot use a scalar value as an array in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 752
[02-Nov-2004 21:31:13] PHP Warning: Cannot use a scalar value as an array in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 752
[02-Nov-2004 21:31:13] PHP Warning: Cannot use a scalar value as an array in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 752
[02-Nov-2004 21:31:13] PHP Warning: Cannot use a scalar value as an array in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 752
[02-Nov-2004 21:31:13] PHP Warning: Cannot use a scalar value as an array in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 752
[02-Nov-2004 21:31:13] PHP Warning: Cannot use a scalar value as an array in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 752
[02-Nov-2004 21:31:13] PHP Warning: Cannot use a scalar value as an array in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 752
[02-Nov-2004 21:31:13] PHP Warning: Cannot use a scalar value as an array in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 752
[02-Nov-2004 21:31:13] PHP Warning: Cannot use a scalar value as an array in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 752
[02-Nov-2004 21:31:13] PHP Warning: Argument to array_values() should be an array in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 764
[02-Nov-2004 21:31:13] PHP Warning: Argument 4 to array_multisort() is expected to be an array or a sort flag in /home/httpd/vhosts/yogie.de/httpdocs/cms/front_content.php(563) : eval()'d code on line 766
Ich benutze 4.4.4
Achso zur Ausgabe musste ich noch folgende Dateien anlegen und ins Template Verzeichnis schieben:
search_found.html
Code: Alles auswählen
<div>
Suchergebnisse für "<b>{SUCHTEXT}</b>"
<br>
Anzahl Treffer: <b>{TREFFER}</b>
</div>
<br>
<!-- BEGIN:BLOCK -->
<div>
<a href="{HREF}" target="{TARGET}"><b>{ARTIKELNAME}</b></a><br>
{TEXT}
</div>
<br>
<!-- END:BLOCK -->
Code: Alles auswählen
<p><div class="text">
Es wurden keine mit Ihrer Suchanfrage "<b>{SUCHTEXT}</b>" übereinstimmenden Dokumente gefunden
</div>