ILIAS  release_4-3 Revision
 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
 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

 $parsed_query

Private Attributes

 $query_string

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 113 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 139 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 268 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 126 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 155 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 311 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 181 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 207 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 254 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 194 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 284 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 168 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 64 of file class.ilLuceneQueryParser.php.

References $parsed_query.

{
}
ilLuceneQueryParser::parse ( )

parse query string

Returns

Reimplemented in ilLuceneAdvancedQueryParser.

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

Referenced by 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::replaceOwnerCallback (   $matches)
protected

Replace owner callback (preg_replace_callback)

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

References $usr_id, and 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 88 of file class.ilLuceneQueryParser.php.

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

Referenced by 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
private

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


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