cvs: php-bugs-web / index.php search.php /include functions.inc
| From: | Philip Olson | Date: | Wed, 04 Jun 2003 01:21:03 +0000 |
| Subject: | cvs: php-bugs-web / index.php search.php /include functions.inc | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-18476@lists.php.net to get a copy of this message | ||
philip Tue Jun 3 21:21:03 2003 EDT
Modified files:
/php-bugs-web search.php index.php
/php-bugs-web/include functions.inc
Log:
Implement boolean FULLTEXT support into the advanced search.
Index: php-bugs-web/search.php
diff -u php-bugs-web/search.php:1.38 php-bugs-web/search.php:1.39
--- php-bugs-web/search.php:1.38 Fri Apr 25 18:19:44 2003
+++ php-bugs-web/search.php Tue Jun 3 21:21:03 2003
@@ -16,6 +16,8 @@
$errors = array();
$warnings = array();
+define('BOOLEAN_SEARCH', @intval($boolean));
+
if (isset($cmd) && $cmd == "display") {
@mysql_pconnect("localhost","nobody","")
or die("Unable to connect to SQL server.");
@@ -208,8 +210,9 @@
<table id="primary" width="95%">
<tr>
<th>Find bugs</th>
- <td nowrap="nowrap">with <b>any</b> of the words</td>
- <td><input type="text" name="search_for" value="<?php echo
htmlspecialchars(stripslashes($search_for));?>" size="20"
maxlength="255" /></td>
+ <td nowrap="nowrap">with all or any of the words</td>
+ <td><input type="text" name="search_for" value="<?php echo
htmlspecialchars(stripslashes($search_for));?>" size="20"
maxlength="255" />
+ <br><?php show_boolean_options(BOOLEAN_SEARCH) ?> (<a
href="index.php">?</a>)</td>
<td rowspan="2">
<select name="limit"><?php show_limit_options($limit);?></select>
<br />
Index: php-bugs-web/index.php
diff -u php-bugs-web/index.php:1.7 php-bugs-web/index.php:1.8
--- php-bugs-web/index.php:1.7 Wed Apr 23 16:56:01 2003
+++ php-bugs-web/index.php Tue Jun 3 21:21:03 2003
@@ -36,7 +36,11 @@
<p>You can search all of the bugs that have been reported on our
<a href="search.php">advanced search page</a>, or use the form
-at the top of the page.</p>
+at the top of the page. Choosing the <i>any</i> checkbox (default) will yield
+results with any of the search terms, <i>all</i> will require all search terms
+while <i>raw</i> allows full use of MySQL's
+<a href="http://www.mysql.com/doc/en/Fulltext_Search.html">FULLTEXT</a>
boolean
+search operators.</p>
<h1>Bug System Statistics</h1>
Index: php-bugs-web/include/functions.inc
diff -u php-bugs-web/include/functions.inc:1.72 php-bugs-web/include/functions.inc:1.73
--- php-bugs-web/include/functions.inc:1.72 Thu May 29 06:35:13 2003
+++ php-bugs-web/include/functions.inc Tue Jun 3 21:21:03 2003
@@ -188,6 +188,17 @@
}
}
+function show_boolean_options($current) {
+ $options = array('any', 'all', 'raw');
+ while (list($val, $type) = each($options)) {
+ echo '<input type="checkbox" name="boolean" value="', $val,
'"';
+ if ($val === $current) {
+ echo ' CHECKED';
+ }
+ echo "> $type \n";
+ }
+}
+
function mail_bug_updates($bug, $in, $from, $ncomment, $edit=1)
{
$text = array();
@@ -517,16 +528,35 @@
// Function will be updated to make results more relevant.
// Quick hack for indicating ignored words.
+ global $mysql4;
+
$min_word_len=3;
$words = preg_split("/\s+/", stripslashes($search));
- $ignored = array();
+ $ignored = $used = array();
foreach($words AS $match) {
if(strlen($match) < $min_word_len) {
array_push($ignored, $match);
+ } else {
+ array_push($used, $match);
}
}
-
+
+ if ($mysql4 && BOOLEAN_SEARCH) {
+ // require all used words (all)
+ if (BOOLEAN_SEARCH === 1) {
+ $newsearch = '';
+ foreach ($used as $word) {
+ $newsearch .= "+$word ";
+ }
+ return array(" AND MATCH (email,sdesc,ldesc) AGAINST ('" . addslashes($newsearch)
. "' IN BOOLEAN MODE)", $ignored);
+
+ // allow custom boolean search (raw)
+ } elseif (BOOLEAN_SEARCH === 2) {
+ return array(" AND MATCH (email,sdesc,ldesc) AGAINST ('" . addslashes($search) .
"' IN BOOLEAN MODE)", $ignored);
+ }
+ }
+ // require any of the words (any)
return array(" AND MATCH (email,sdesc,ldesc) AGAINST ('" . addslashes($search) .
"')", $ignored);
}