ILIAS  release_4-4 Revision
ilLuceneQueryParser Class Reference

Lucene query parser. More...

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

Public Member Functions

 __construct ($a_query_string)
 Constructor. More...
 
 parse ()
 parse query string More...
 
 getQuery ()
 get query More...
 

Static Public Member Functions

static validateQuery ($a_query)
 

Protected Member Functions

 replaceOwnerCallback ($matches)
 Replace owner callback (preg_replace_callback) More...
 

Static Protected Member Functions

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

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

◆ __construct()

ilLuceneQueryParser::__construct (   $a_query_string)

Constructor.

Parameters
stringquery string
Returns

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

47  {
48  $this->query_string = $a_query_string;
49  }

Member Function Documentation

◆ checkAllowedCharacters()

static ilLuceneQueryParser::checkAllowedCharacters (   $query)
staticprotected

Check allowed characters.

Exceptions
LuceneQueryParserException

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

References $query.

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

◆ checkAmpersands()

static ilLuceneQueryParser::checkAmpersands (   $query)
staticprotected

Check ampersands.

Exceptions
LuceneQueryParserException

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

References $query.

140  {
141  if(preg_match('/[&]{2}/',$query) > 0)
142  {
143  if(preg_match('/^([\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+( && )?[\pL0-9_+\-:.()\"*?|!{}\[\]\^~\\@#\/$%\'=]+[ ]*)+$/u',$query) == 0)
144  {
145  throw new ilLuceneQueryParserException('lucene_err_ampersand');
146  }
147  }
148  return true;
149  }

◆ checkANDORNOT()

static ilLuceneQueryParser::checkANDORNOT (   $a_query)
staticprotected

Check AND OR NOT.

Exceptions
LuceneQueryParserException

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

269  {
270  return true;
271 
272  if(preg_match('/^([\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@\/#$%\'=]+\s*((AND )|(OR )|(AND NOT )|(NOT ))?[\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@\/#$%\'=]+[ ]*)+$/u',$a_query) == 0)
273  {
274  throw new ilLuceneQueryParserException('lucene_err_and_or_not');
275  }
276  return true;
277  }

◆ checkAsterisk()

static ilLuceneQueryParser::checkAsterisk (   $query)
staticprotected

Check asterisk.

Exceptions
LuceneQueryParserException

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

References $query.

127  {
128  if(preg_match('/^[\*]*$|[\s]\*|^\*[^\s]/',$query) != 0)
129  {
130  throw new ilLuceneQueryParserException('lucene_err_asterisk');
131  }
132  return true;
133  }

◆ checkCaret()

static ilLuceneQueryParser::checkCaret (   $query)
staticprotected

Check carets.

Exceptions
LuceneQueryParserException

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

References $query.

Referenced by validateQuery().

156  {
157  if(preg_match('/[^\\\]\^([^\s]*[^0-9.]+)|[^\\\]\^$/',$query) != 0)
158  {
159  throw new ilLuceneQueryParserException('lucene_err_caret');
160  }
161  return true;
162  }
+ Here is the caller graph for this function:

◆ checkColon()

static ilLuceneQueryParser::checkColon (   $a_query)
staticprotected

Check colon.

Exceptions
LuceneQueryParserException

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

312  {
313  if(preg_match('/[^\\\\s]:[\s]|[^\\\\s]:$|[\s][^\\]?:|^[^\\\\s]?:/',$a_query) != 0)
314  {
315  throw new ilLuceneQueryParserException('lucene_err_colon');
316  }
317  return true;
318  }

◆ checkExclamationMark()

static ilLuceneQueryParser::checkExclamationMark (   $query)
staticprotected

Check exclamation marks (replacement for NOT)

Exceptions
LuceneQueryParserException

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

References $query.

182  {
183  if(preg_match('/^[^!]*$|^([\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+( ! )?[\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+[ ]*)+$/u',$query,$matches) == 0)
184  {
185  throw new ilLuceneQueryParserException('lucene_err_exclamation_mark');
186  }
187  return true;
188  }

◆ checkParenthesis()

static ilLuceneQueryParser::checkParenthesis (   $a_query)
staticprotected

Check parenthesis.

Exceptions
LuceneQueryParserException

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

Referenced by validateQuery().

208  {
209  $hasLft = false;
210  $hasRgt = false;
211 
212  $matchLft = 0;
213  $matchRgt = 0;
214 
215  $tmp = array();
216 
217  if(($matchLft = preg_match_all('/[(]/',$a_query,$tmp)) > 0)
218  {
219  $hasLft = true;
220  }
221  if(($matchRgt = preg_match_all('/[)]/',$a_query,$tmp)) > 0)
222  {
223  $hasRgt = true;
224  }
225 
226  if(!$hasLft || !$hasRgt)
227  {
228  return true;
229  }
230 
231 
232  if(($hasLft && !$hasRgt) || ($hasRgt && !$hasLft))
233  {
234  throw new ilLuceneQueryParserException('lucene_err_parenthesis_not_closed');
235  }
236 
237  if($matchLft !== $matchRgt)
238  {
239  throw new ilLuceneQueryParserException('lucene_err_parenthesis_not_closed');
240  }
241 
242  if(preg_match('/\(\s*\)/',$a_query) > 0)
243  {
244  throw new ilLuceneQueryParserException('lucene_err_parenthesis_empty');
245  }
246  return true;
247  }
+ Here is the caller graph for this function:

◆ checkPlusMinus()

static ilLuceneQueryParser::checkPlusMinus (   $a_query)
staticprotected

Check plus minus.

Exceptions
LuceneQueryParserException

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

255  {
256  if(preg_match('/^[^\n+\-]*$|^([+-]?\s*[\pL0-9_:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+[ ]?)+$/u',$a_query) == 0)
257  {
258  throw new ilLuceneQueryParserException('lucene_err_plus_minus');
259  }
260  return true;
261  }

◆ checkQuestionMark()

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.

195  {
196  if(preg_match('/^(\?)|([^\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]\?+)/u',$query,$matches) != 0)
197  {
198  throw new ilLuceneQueryParserException('lucene_err_question_mark');
199  }
200  return true;
201  }

◆ checkQuotes()

static ilLuceneQueryParser::checkQuotes (   $a_query)
staticprotected

Check quotes.

Exceptions
LuceneQueryParserException

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

Referenced by validateQuery().

285  {
286  $matches = preg_match_all('/"/',$a_query,$tmp);
287 
288  if($matches == 0)
289  {
290  return true;
291  }
292 
293  if(($matches % 2) > 0)
294  {
295  throw new ilLuceneQueryParserException('lucene_err_quotes');
296  }
297 
298  if(preg_match('/"\s*"/',$a_query) > 0)
299  {
300  throw new ilLuceneQueryParserException('lucene_err_quotes_not_empty');
301  }
302  return true;
303  }
+ Here is the caller graph for this function:

◆ checkSquiggle()

static ilLuceneQueryParser::checkSquiggle (   $query)
staticprotected

Check squiggles.

Exceptions
LuceneQueryParserException

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

References $query.

Referenced by validateQuery().

169  {
170  if(preg_match('/[^\\\]*~[^\s]*[^0-9\s]+/',$query,$matches) != 0)
171  {
172  throw new ilLuceneQueryParserException('lucene_err_squiggle');
173  }
174  return true;
175  }
+ Here is the caller graph for this function:

◆ getQuery()

ilLuceneQueryParser::getQuery ( )

get query

Returns

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

References $parsed_query.

◆ parse()

ilLuceneQueryParser::parse ( )

parse query string

Returns

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

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

56  {
57  $this->parsed_query = preg_replace_callback('/(owner:)\s?([A-Za-z0-9_\.\+\*\@!\$\%\~\-]+)/',array($this,'replaceOwnerCallback'),$this->query_string);
58  }
+ Here is the caller graph for this function:

◆ replaceOwnerCallback()

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().

73  {
74  if(isset($matches[2]))
75  {
76  if($usr_id = ilObjUser::_loginExists($matches[2]))
77  {
78  return $matches[1].$usr_id;
79  }
80  }
81  return $matches[0];
82  }
static _loginExists($a_login, $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
+ Here is the call graph for this function:

◆ validateQuery()

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 ilMailQuickFilterInputGUI\checkInput(), and ilLuceneQueryInputGUI\checkInput().

89  {
90  // TODO
91  // First replace all quote characters
92 
93 
94  #ilLuceneQueryParser::checkAllowedCharacters($a_query);
95  #ilLuceneQueryParser::checkAsterisk($a_query);
96  #ilLuceneQueryParser::checkAmpersands($a_query);
99  #ilLuceneQueryParser::checkExclamationMark($a_query);
100  #ilLuceneQueryParser::checkQuestionMark($a_query);
102  #ilLuceneQueryParser::checkPlusMinus($a_query);
103  #ilLuceneQueryParser::checkANDORNOT($a_query);
105  #ilLuceneQueryParser::checkColon($a_query);
106  return true;
107  }
static checkSquiggle($query)
Check squiggles.
static checkCaret($query)
Check carets.
static checkQuotes($a_query)
Check quotes.
static checkParenthesis($a_query)
Check parenthesis.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $parsed_query

ilLuceneQueryParser::$parsed_query
protected

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

Referenced by getQuery().

◆ $query_string

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: