Finishing off search capability with the ability to search by instance,
and in this case, by forum.
This commit is contained in:
+28
-1
@@ -12,6 +12,7 @@ define("TOKEN_STRING","4");
|
||||
define("TOKEN_USERID","5");
|
||||
define("TOKEN_DATEFROM","6");
|
||||
define("TOKEN_DATETO","7");
|
||||
define("TOKEN_INSTANCE","8");
|
||||
|
||||
// Class to hold token/value pairs after they're parsed.
|
||||
|
||||
@@ -75,6 +76,17 @@ class search_lexer extends Lexer{
|
||||
$this->addExitPattern("\s","indateto");
|
||||
|
||||
|
||||
// Patterns to handle strings of the form instance:foo
|
||||
|
||||
// If we see the string instance: while in the base accept state, start
|
||||
// parsing for instance number and go to the ininstance state.
|
||||
$this->addEntryPattern("instance:\S+","accept","ininstance");
|
||||
|
||||
// Snarf everything into the username until we see whitespace, then exit
|
||||
// back to the base accept state.
|
||||
$this->addExitPattern("\s","ininstance");
|
||||
|
||||
|
||||
// Patterns to handle strings of the form userid:foo
|
||||
|
||||
// If we see the string userid: while in the base accept state, start
|
||||
@@ -197,6 +209,18 @@ class search_parser {
|
||||
return true;
|
||||
}
|
||||
|
||||
// State for handling instance:foo constructs. Potentially emits a token.
|
||||
function ininstance($content){
|
||||
if (strlen($content) < 10) { // State exit or missing parameter.
|
||||
return true;
|
||||
}
|
||||
// Strip off the instance: part and add the reminder to the parsed token array
|
||||
$param = trim(substr($content,9));
|
||||
$this->tokens[] = new search_token(TOKEN_INSTANCE,$param);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// State for handling userid:foo constructs. Potentially emits a token.
|
||||
function inuserid($content){
|
||||
if (strlen($content) < 8) { // State exit or missing parameter.
|
||||
@@ -287,7 +311,7 @@ class search_parser {
|
||||
// Other fields are database table names to search.
|
||||
|
||||
function search_generate_SQL($parsetree, $datafield, $metafield, $mainidfield, $useridfield,
|
||||
$userfirstnamefield, $userlastnamefield, $timefield) {
|
||||
$userfirstnamefield, $userlastnamefield, $timefield, $instancefield) {
|
||||
global $CFG;
|
||||
|
||||
if ($CFG->dbtype == "postgres7") {
|
||||
@@ -335,6 +359,9 @@ function search_generate_SQL($parsetree, $datafield, $metafield, $mainidfield, $
|
||||
case TOKEN_USERID:
|
||||
$SQLString .= "($useridfield = $value)";
|
||||
break;
|
||||
case TOKEN_INSTANCE:
|
||||
$SQLString .= "($instancefield = $value)";
|
||||
break;
|
||||
case TOKEN_DATETO:
|
||||
$SQLString .= "($timefield <= $value)";
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user