ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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...
 
 parseAutoWildcard ()
 Append asterisk for remote search from global search form field. 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 127 of file class.ilLuceneQueryParser.php.

References $query.

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

◆ checkAmpersands()

static ilLuceneQueryParser::checkAmpersands (   $query)
staticprotected

Check ampersands.

Exceptions
LuceneQueryParserException

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

References $query.

152  {
153  if (preg_match('/[&]{2}/', $query) > 0) {
154  if (preg_match('/^([\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+( && )?[\pL0-9_+\-:.()\"*?|!{}\[\]\^~\\@#\/$%\'=]+[ ]*)+$/u', $query) == 0) {
155  throw new ilLuceneQueryParserException('lucene_err_ampersand');
156  }
157  }
158  return true;
159  }
$query

◆ checkANDORNOT()

static ilLuceneQueryParser::checkANDORNOT (   $a_query)
staticprotected

Check AND OR NOT.

Exceptions
LuceneQueryParserException

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

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

◆ checkAsterisk()

static ilLuceneQueryParser::checkAsterisk (   $query)
staticprotected

Check asterisk.

Exceptions
LuceneQueryParserException

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

References $query.

140  {
141  if (preg_match('/^[\*]*$|[\s]\*|^\*[^\s]/', $query) != 0) {
142  throw new ilLuceneQueryParserException('lucene_err_asterisk');
143  }
144  return true;
145  }
$query

◆ checkCaret()

static ilLuceneQueryParser::checkCaret (   $query)
staticprotected

Check carets.

Exceptions
LuceneQueryParserException

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

References $query.

Referenced by validateQuery().

166  {
167  if (preg_match('/[^\\\]\^([^\s]*[^0-9.]+)|[^\\\]\^$/', $query) != 0) {
168  throw new ilLuceneQueryParserException('lucene_err_caret');
169  }
170  return true;
171  }
$query
+ Here is the caller graph for this function:

◆ checkColon()

static ilLuceneQueryParser::checkColon (   $a_query)
staticprotected

Check colon.

Exceptions
LuceneQueryParserException

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

307  {
308  if (preg_match('/[^\\\\s]:[\s]|[^\\\\s]:$|[\s][^\\]?:|^[^\\\\s]?:/', $a_query) != 0) {
309  throw new ilLuceneQueryParserException('lucene_err_colon');
310  }
311  return true;
312  }

◆ checkExclamationMark()

static ilLuceneQueryParser::checkExclamationMark (   $query)
staticprotected

Check exclamation marks (replacement for NOT)

Exceptions
LuceneQueryParserException

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

References $query.

190  {
191  if (preg_match('/^[^!]*$|^([\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+( ! )?[\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+[ ]*)+$/u', $query, $matches) == 0) {
192  throw new ilLuceneQueryParserException('lucene_err_exclamation_mark');
193  }
194  return true;
195  }
$query

◆ checkParenthesis()

static ilLuceneQueryParser::checkParenthesis (   $a_query)
staticprotected

Check parenthesis.

Exceptions
LuceneQueryParserException

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

References array.

Referenced by validateQuery().

214  {
215  $hasLft = false;
216  $hasRgt = false;
217 
218  $matchLft = 0;
219  $matchRgt = 0;
220 
221  $tmp = array();
222 
223  if (($matchLft = preg_match_all('/[(]/', $a_query, $tmp)) > 0) {
224  $hasLft = true;
225  }
226  if (($matchRgt = preg_match_all('/[)]/', $a_query, $tmp)) > 0) {
227  $hasRgt = true;
228  }
229 
230  if (!$hasLft || !$hasRgt) {
231  return true;
232  }
233 
234 
235  if (($hasLft && !$hasRgt) || ($hasRgt && !$hasLft)) {
236  throw new ilLuceneQueryParserException('lucene_err_parenthesis_not_closed');
237  }
238 
239  if ($matchLft !== $matchRgt) {
240  throw new ilLuceneQueryParserException('lucene_err_parenthesis_not_closed');
241  }
242 
243  if (preg_match('/\(\s*\)/', $a_query) > 0) {
244  throw new ilLuceneQueryParserException('lucene_err_parenthesis_empty');
245  }
246  return true;
247  }
Create styles array
The data for the language used.
+ 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  throw new ilLuceneQueryParserException('lucene_err_plus_minus');
258  }
259  return true;
260  }

◆ checkQuestionMark()

static ilLuceneQueryParser::checkQuestionMark (   $query)
staticprotected

Check question mark (wild card single character)

Exceptions
LuceneQueryParserException

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

References $query.

202  {
203  if (preg_match('/^(\?)|([^\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]\?+)/u', $query, $matches) != 0) {
204  throw new ilLuceneQueryParserException('lucene_err_question_mark');
205  }
206  return true;
207  }
$query

◆ checkQuotes()

static ilLuceneQueryParser::checkQuotes (   $a_query)
staticprotected

Check quotes.

Exceptions
LuceneQueryParserException

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

Referenced by validateQuery().

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

◆ checkSquiggle()

static ilLuceneQueryParser::checkSquiggle (   $query)
staticprotected

Check squiggles.

Exceptions
LuceneQueryParserException

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

References $query.

Referenced by validateQuery().

178  {
179  if (preg_match('/[^\\\]*~[^\s]*[^0-9\s]+/', $query, $matches) != 0) {
180  throw new ilLuceneQueryParserException('lucene_err_squiggle');
181  }
182  return true;
183  }
$query
+ Here is the caller graph for this function:

◆ getQuery()

ilLuceneQueryParser::getQuery ( )

get query

Returns

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

References $parsed_query.

◆ parse()

ilLuceneQueryParser::parse ( )

parse query string

Returns

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

References array.

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  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ parseAutoWildcard()

ilLuceneQueryParser::parseAutoWildcard ( )

Append asterisk for remote search from global search form field.

Returns
boolean

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

65  {
66  $this->parsed_query = trim($this->query_string);
67  if (stristr($this->parsed_query, '*')) {
68  return true;
69  }
70  if (substr($this->parsed_query, -1) !== '"') {
71  $this->parsed_query .= '*';
72  }
73  return true;
74  }

◆ replaceOwnerCallback()

ilLuceneQueryParser::replaceOwnerCallback (   $matches)
protected

Replace owner callback (preg_replace_callback)

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

References ilObjUser\_loginExists().

89  {
90  if (isset($matches[2])) {
91  if ($usr_id = ilObjUser::_loginExists($matches[2])) {
92  return $matches[1] . $usr_id;
93  }
94  }
95  return $matches[0];
96  }
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 102 of file class.ilLuceneQueryParser.php.

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

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

103  {
104  // TODO
105  // First replace all quote characters
106 
107 
108  #ilLuceneQueryParser::checkAllowedCharacters($a_query);
109  #ilLuceneQueryParser::checkAsterisk($a_query);
110  #ilLuceneQueryParser::checkAmpersands($a_query);
113  #ilLuceneQueryParser::checkExclamationMark($a_query);
114  #ilLuceneQueryParser::checkQuestionMark($a_query);
116  #ilLuceneQueryParser::checkPlusMinus($a_query);
117  #ilLuceneQueryParser::checkANDORNOT($a_query);
119  #ilLuceneQueryParser::checkColon($a_query);
120  return true;
121  }
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: