ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilLuceneQueryParser Class Reference

Lucene query parser. More...

+ Inheritance diagram for ilLuceneQueryParser:
+ Collaboration diagram for ilLuceneQueryParser:

Public Member Functions

 __construct ($a_query_string)
 Constructor.
 parse ()
 parse query string
 parseAutoWildcard ()
 Append asterisk for remote search from global search form field.
 getQuery ()
 get query

Static Public Member Functions

static validateQuery ($a_query)

Protected Member Functions

 replaceOwnerCallback ($matches)
 Replace owner callback (preg_replace_callback)

Static Protected Member Functions

static checkAllowedCharacters ($query)
 Check allowed characters.
static checkAsterisk ($query)
 Check asterisk.
static checkAmpersands ($query)
 Check ampersands.
static checkCaret ($query)
 Check carets.
static checkSquiggle ($query)
 Check squiggles.
static checkExclamationMark ($query)
 Check exclamation marks (replacement for NOT)
static checkQuestionMark ($query)
 Check question mark (wild card single character)
static checkParenthesis ($a_query)
 Check parenthesis.
static checkPlusMinus ($a_query)
 Check plus minus.
static checkANDORNOT ($a_query)
 Check AND OR NOT.
static checkQuotes ($a_query)
 Check quotes.
static checkColon ($a_query)
 Check colon.

Protected Attributes

 $query_string
 $parsed_query

Detailed Description

Lucene query parser.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 35 of file class.ilLuceneQueryParser.php.

Constructor & Destructor Documentation

ilLuceneQueryParser::__construct (   $a_query_string)

Constructor.

Parameters
stringquery string
Returns

Reimplemented in ilLuceneAdvancedQueryParser.

Definition at line 46 of file class.ilLuceneQueryParser.php.

{
$this->query_string = $a_query_string;
}

Member Function Documentation

static ilLuceneQueryParser::checkAllowedCharacters (   $query)
staticprotected

Check allowed characters.

Exceptions
LuceneQueryParserException

Definition at line 131 of file class.ilLuceneQueryParser.php.

References $query.

{
if(preg_match('/[^\pL0-9_+\-:.()\"*?&§€|!{}\[\]\^~\\@#\/$%\'= ]/u',$query) != 0)
{
throw new ilLuceneQueryParserException('lucene_err_allowed_characters');
}
return true;
}
static ilLuceneQueryParser::checkAmpersands (   $query)
staticprotected

Check ampersands.

Exceptions
LuceneQueryParserException

Definition at line 157 of file class.ilLuceneQueryParser.php.

References $query.

{
if(preg_match('/[&]{2}/',$query) > 0)
{
if(preg_match('/^([\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+( && )?[\pL0-9_+\-:.()\"*?|!{}\[\]\^~\\@#\/$%\'=]+[ ]*)+$/u',$query) == 0)
{
throw new ilLuceneQueryParserException('lucene_err_ampersand');
}
}
return true;
}
static ilLuceneQueryParser::checkANDORNOT (   $a_query)
staticprotected

Check AND OR NOT.

Exceptions
LuceneQueryParserException

Definition at line 286 of file class.ilLuceneQueryParser.php.

{
return true;
if(preg_match('/^([\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@\/#$%\'=]+\s*((AND )|(OR )|(AND NOT )|(NOT ))?[\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@\/#$%\'=]+[ ]*)+$/u',$a_query) == 0)
{
throw new ilLuceneQueryParserException('lucene_err_and_or_not');
}
return true;
}
static ilLuceneQueryParser::checkAsterisk (   $query)
staticprotected

Check asterisk.

Exceptions
LuceneQueryParserException

Definition at line 144 of file class.ilLuceneQueryParser.php.

References $query.

{
if(preg_match('/^[\*]*$|[\s]\*|^\*[^\s]/',$query) != 0)
{
throw new ilLuceneQueryParserException('lucene_err_asterisk');
}
return true;
}
static ilLuceneQueryParser::checkCaret (   $query)
staticprotected

Check carets.

Exceptions
LuceneQueryParserException

Definition at line 173 of file class.ilLuceneQueryParser.php.

References $query.

Referenced by validateQuery().

{
if(preg_match('/[^\\\]\^([^\s]*[^0-9.]+)|[^\\\]\^$/',$query) != 0)
{
throw new ilLuceneQueryParserException('lucene_err_caret');
}
return true;
}

+ Here is the caller graph for this function:

static ilLuceneQueryParser::checkColon (   $a_query)
staticprotected

Check colon.

Exceptions
LuceneQueryParserException

Definition at line 329 of file class.ilLuceneQueryParser.php.

{
if(preg_match('/[^\\\\s]:[\s]|[^\\\\s]:$|[\s][^\\]?:|^[^\\\\s]?:/',$a_query) != 0)
{
throw new ilLuceneQueryParserException('lucene_err_colon');
}
return true;
}
static ilLuceneQueryParser::checkExclamationMark (   $query)
staticprotected

Check exclamation marks (replacement for NOT)

Exceptions
LuceneQueryParserException

Definition at line 199 of file class.ilLuceneQueryParser.php.

References $query.

{
if(preg_match('/^[^!]*$|^([\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+( ! )?[\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+[ ]*)+$/u',$query,$matches) == 0)
{
throw new ilLuceneQueryParserException('lucene_err_exclamation_mark');
}
return true;
}
static ilLuceneQueryParser::checkParenthesis (   $a_query)
staticprotected

Check parenthesis.

Exceptions
LuceneQueryParserException

Definition at line 225 of file class.ilLuceneQueryParser.php.

Referenced by validateQuery().

{
$hasLft = false;
$hasRgt = false;
$matchLft = 0;
$matchRgt = 0;
$tmp = array();
if(($matchLft = preg_match_all('/[(]/',$a_query,$tmp)) > 0)
{
$hasLft = true;
}
if(($matchRgt = preg_match_all('/[)]/',$a_query,$tmp)) > 0)
{
$hasRgt = true;
}
if(!$hasLft || !$hasRgt)
{
return true;
}
if(($hasLft && !$hasRgt) || ($hasRgt && !$hasLft))
{
throw new ilLuceneQueryParserException('lucene_err_parenthesis_not_closed');
}
if($matchLft !== $matchRgt)
{
throw new ilLuceneQueryParserException('lucene_err_parenthesis_not_closed');
}
if(preg_match('/\(\s*\)/',$a_query) > 0)
{
throw new ilLuceneQueryParserException('lucene_err_parenthesis_empty');
}
return true;
}

+ Here is the caller graph for this function:

static ilLuceneQueryParser::checkPlusMinus (   $a_query)
staticprotected

Check plus minus.

Exceptions
LuceneQueryParserException

Definition at line 272 of file class.ilLuceneQueryParser.php.

{
if(preg_match('/^[^\n+\-]*$|^([+-]?\s*[\pL0-9_:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+[ ]?)+$/u',$a_query) == 0)
{
throw new ilLuceneQueryParserException('lucene_err_plus_minus');
}
return true;
}
static ilLuceneQueryParser::checkQuestionMark (   $query)
staticprotected

Check question mark (wild card single character)

Exceptions
LuceneQueryParserException

Definition at line 212 of file class.ilLuceneQueryParser.php.

References $query.

{
if(preg_match('/^(\?)|([^\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]\?+)/u',$query,$matches) != 0)
{
throw new ilLuceneQueryParserException('lucene_err_question_mark');
}
return true;
}
static ilLuceneQueryParser::checkQuotes (   $a_query)
staticprotected

Check quotes.

Exceptions
LuceneQueryParserException

Definition at line 302 of file class.ilLuceneQueryParser.php.

Referenced by validateQuery().

{
$matches = preg_match_all('/"/',$a_query,$tmp);
if($matches == 0)
{
return true;
}
if(($matches % 2) > 0)
{
throw new ilLuceneQueryParserException('lucene_err_quotes');
}
if(preg_match('/"\s*"/',$a_query) > 0)
{
throw new ilLuceneQueryParserException('lucene_err_quotes_not_empty');
}
return true;
}

+ Here is the caller graph for this function:

static ilLuceneQueryParser::checkSquiggle (   $query)
staticprotected

Check squiggles.

Exceptions
LuceneQueryParserException

Definition at line 186 of file class.ilLuceneQueryParser.php.

References $query.

Referenced by validateQuery().

{
if(preg_match('/[^\\\]*~[^\s]*[^0-9\s]+/',$query,$matches) != 0)
{
throw new ilLuceneQueryParserException('lucene_err_squiggle');
}
return true;
}

+ Here is the caller graph for this function:

ilLuceneQueryParser::getQuery ( )

get query

Returns

Definition at line 82 of file class.ilLuceneQueryParser.php.

References $parsed_query.

{
}
ilLuceneQueryParser::parse ( )

parse query string

Returns

Reimplemented in ilLuceneAdvancedQueryParser, and ilMailLuceneQueryParser.

Definition at line 55 of file class.ilLuceneQueryParser.php.

Referenced by ilLuceneUserSearchGUI\performSearch(), and ilLuceneSearchGUI\showSavedResults().

{
$this->parsed_query = preg_replace_callback('/(owner:)\s?([A-Za-z0-9_\.\+\*\@!\$\%\~\-]+)/',array($this,'replaceOwnerCallback'),$this->query_string);
}

+ Here is the caller graph for this function:

ilLuceneQueryParser::parseAutoWildcard ( )

Append asterisk for remote search from global search form field.

Returns
boolean

Definition at line 64 of file class.ilLuceneQueryParser.php.

{
$this->parsed_query = trim($this->query_string);
if(stristr($this->parsed_query, '*'))
{
return TRUE;
}
if(substr($this->parsed_query, -1) !== '"')
{
$this->parsed_query .= '*';
}
return TRUE;
}
ilLuceneQueryParser::replaceOwnerCallback (   $matches)
protected

Replace owner callback (preg_replace_callback)

Definition at line 90 of file class.ilLuceneQueryParser.php.

References ilObjUser\_loginExists().

{
if(isset($matches[2]))
{
if($usr_id = ilObjUser::_loginExists($matches[2]))
{
return $matches[1].$usr_id;
}
}
return $matches[0];
}

+ Here is the call graph for this function:

static ilLuceneQueryParser::validateQuery (   $a_query)
static
Exceptions
LuceneQueryParserException

Definition at line 106 of file class.ilLuceneQueryParser.php.

References checkCaret(), checkParenthesis(), checkQuotes(), and checkSquiggle().

Referenced by ilMailQuickFilterInputGUI\checkInput(), and ilLuceneQueryInputGUI\checkInput().

{
// TODO
// First replace all quote characters
#ilLuceneQueryParser::checkAllowedCharacters($a_query);
#ilLuceneQueryParser::checkAsterisk($a_query);
#ilLuceneQueryParser::checkAmpersands($a_query);
#ilLuceneQueryParser::checkExclamationMark($a_query);
#ilLuceneQueryParser::checkQuestionMark($a_query);
#ilLuceneQueryParser::checkPlusMinus($a_query);
#ilLuceneQueryParser::checkANDORNOT($a_query);
#ilLuceneQueryParser::checkColon($a_query);
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilLuceneQueryParser::$parsed_query
protected

Definition at line 38 of file class.ilLuceneQueryParser.php.

Referenced by getQuery().

ilLuceneQueryParser::$query_string
protected

Definition at line 37 of file class.ilLuceneQueryParser.php.

Referenced by ilMailLuceneQueryParser\parse().


The documentation for this class was generated from the following file: