Update of /cvsroot/phpwiki/phpwiki/lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv11835/lib
Modified Files:
fullsearch.php mysql.php
Log Message:
more sophisticated search: match individual words, also excluding words possible
Index: fullsearch.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/fullsearch.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** fullsearch.php 2000/10/20 11:42:52 1.2
--- fullsearch.php 2000/11/18 13:50:36 1.3
***************
*** 17,25 ****
$result .= "</B></P>\n<DL>\n";
- // quote regexp chars
- $full = preg_quote($full);
-
// search matching pages
$query = InitFullSearch($dbi, $full);
while ($pagehash = FullSearchNextMatch($dbi, $query)) {
$result .= "<DT><B>" . LinkExistingWikiWord($pagehash["pagename"]) . "</B>\n";
--- 17,26 ----
$result .= "</B></P>\n<DL>\n";
// search matching pages
$query = InitFullSearch($dbi, $full);
+
+ // quote regexp chars
+ $full = preg_replace("/\s+/", "|", preg_quote($full));
+
while ($pagehash = FullSearchNextMatch($dbi, $query)) {
$result .= "<DT><B>" . LinkExistingWikiWord($pagehash["pagename"]) . "</B>\n";
***************
*** 28,33 ****
// print out all matching lines, highlighting the match
for ($j = 0; $j < (count($pagehash["content"])); $j++) {
! if ($hits = preg_match_all("|$full|i", $pagehash["content"][$j], $dummy)) {
! $matched = preg_replace("|$full|i",
"${FieldSeparator}OT\\0${FieldSeparator}CT",
$pagehash["content"][$j]);
--- 29,34 ----
// print out all matching lines, highlighting the match
for ($j = 0; $j < (count($pagehash["content"])); $j++) {
! if ($hits = preg_match_all("/$full/i", $pagehash["content"][$j], $dummy)) {
! $matched = preg_replace("/$full/i",
"${FieldSeparator}OT\\0${FieldSeparator}CT",
$pagehash["content"][$j]);
Index: mysql.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/mysql.php,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** mysql.php 2000/11/13 14:54:08 1.6
--- mysql.php 2000/11/18 13:50:36 1.7
***************
*** 15,18 ****
--- 15,19 ----
IncreaseHitCount($dbi, $pagename)
GetHitCount($dbi, $pagename)
+ MakeSQLSearchClause($search, $column)
InitTitleSearch($dbi, $search)
TitleSearchNextMatch($dbi, $res)
***************
*** 200,208 ****
}
// setup for title-search
function InitTitleSearch($dbi, $search) {
! $search = addslashes($search);
! $res = mysql_query("select pagename from $dbi[table] where pagename like '%$search%' order by pagename", $dbi["dbc"]);
return $res;
--- 201,226 ----
}
+ function MakeSQLSearchClause($search, $column)
+ {
+ $search = addslashes(preg_replace("/\s+/", " ", $search));
+ $term = strtok($search, ' ');
+ while($term) {
+ $word = "$term";
+ if ($word[0] == '-') {
+ $word = substr($word, 1);
+ $clause .= "not ($column like '%$word%') ";
+ } else {
+ $clause .= "($column like '%$word%') ";
+ }
+ if ($term = strtok(' '))
+ $clause .= 'and ';
+ }
+ return $clause;
+ }
// setup for title-search
function InitTitleSearch($dbi, $search) {
! $clause = MakeSQLSearchClause($search, 'pagename');
! $res = mysql_query("select pagename from $dbi[table] where $clause order by pagename", $dbi["dbc"]);
return $res;
***************
*** 223,228 ****
// setup for full-text search
function InitFullSearch($dbi, $search) {
! $search = addslashes($search);
! $res = mysql_query("select * from $dbi[table] where content like '%$search%'", $dbi["dbc"]);
return $res;
--- 241,246 ----
// setup for full-text search
function InitFullSearch($dbi, $search) {
! $clause = MakeSQLSearchClause($search, 'content');
! $res = mysql_query("select * from $dbi[table] where $clause", $dbi["dbc"]);
return $res;
|