ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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

Reimplemented in ilLuceneAdvancedQueryParser.

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 131 of file class.ilLuceneQueryParser.php.

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

References $query.

◆ checkAmpersands()

static ilLuceneQueryParser::checkAmpersands (   $query)
staticprotected

Check ampersands.

Exceptions
LuceneQueryParserException

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

158 {
159 if(preg_match('/[&]{2}/',$query) > 0)
160 {
161 if(preg_match('/^([\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+( && )?[\pL0-9_+\-:.()\"*?|!{}\[\]\^~\\@#\/$%\'=]+[ ]*)+$/u',$query) == 0)
162 {
163 throw new ilLuceneQueryParserException('lucene_err_ampersand');
164 }
165 }
166 return true;
167 }

References $query.

◆ checkANDORNOT()

static ilLuceneQueryParser::checkANDORNOT (   $a_query)
staticprotected

Check AND OR NOT.

Exceptions
LuceneQueryParserException

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

287 {
288 return true;
289
290 if(preg_match('/^([\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@\/#$%\'=]+\s*((AND )|(OR )|(AND NOT )|(NOT ))?[\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@\/#$%\'=]+[ ]*)+$/u',$a_query) == 0)
291 {
292 throw new ilLuceneQueryParserException('lucene_err_and_or_not');
293 }
294 return true;
295 }

◆ checkAsterisk()

static ilLuceneQueryParser::checkAsterisk (   $query)
staticprotected

Check asterisk.

Exceptions
LuceneQueryParserException

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

145 {
146 if(preg_match('/^[\*]*$|[\s]\*|^\*[^\s]/',$query) != 0)
147 {
148 throw new ilLuceneQueryParserException('lucene_err_asterisk');
149 }
150 return true;
151 }

References $query.

◆ checkCaret()

static ilLuceneQueryParser::checkCaret (   $query)
staticprotected

Check carets.

Exceptions
LuceneQueryParserException

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

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

References $query.

Referenced by validateQuery().

+ Here is the caller graph for this function:

◆ checkColon()

static ilLuceneQueryParser::checkColon (   $a_query)
staticprotected

Check colon.

Exceptions
LuceneQueryParserException

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

330 {
331 if(preg_match('/[^\\\\s]:[\s]|[^\\\\s]:$|[\s][^\\]?:|^[^\\\\s]?:/',$a_query) != 0)
332 {
333 throw new ilLuceneQueryParserException('lucene_err_colon');
334 }
335 return true;
336 }

◆ checkExclamationMark()

static ilLuceneQueryParser::checkExclamationMark (   $query)
staticprotected

Check exclamation marks (replacement for NOT)

Exceptions
LuceneQueryParserException

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

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

References $query.

◆ checkParenthesis()

static ilLuceneQueryParser::checkParenthesis (   $a_query)
staticprotected

Check parenthesis.

Exceptions
LuceneQueryParserException

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

226 {
227 $hasLft = false;
228 $hasRgt = false;
229
230 $matchLft = 0;
231 $matchRgt = 0;
232
233 $tmp = array();
234
235 if(($matchLft = preg_match_all('/[(]/',$a_query,$tmp)) > 0)
236 {
237 $hasLft = true;
238 }
239 if(($matchRgt = preg_match_all('/[)]/',$a_query,$tmp)) > 0)
240 {
241 $hasRgt = true;
242 }
243
244 if(!$hasLft || !$hasRgt)
245 {
246 return true;
247 }
248
249
250 if(($hasLft && !$hasRgt) || ($hasRgt && !$hasLft))
251 {
252 throw new ilLuceneQueryParserException('lucene_err_parenthesis_not_closed');
253 }
254
255 if($matchLft !== $matchRgt)
256 {
257 throw new ilLuceneQueryParserException('lucene_err_parenthesis_not_closed');
258 }
259
260 if(preg_match('/\‍(\s*\‍)/',$a_query) > 0)
261 {
262 throw new ilLuceneQueryParserException('lucene_err_parenthesis_empty');
263 }
264 return true;
265 }

Referenced by validateQuery().

+ Here is the caller graph for this function:

◆ checkPlusMinus()

static ilLuceneQueryParser::checkPlusMinus (   $a_query)
staticprotected

Check plus minus.

Exceptions
LuceneQueryParserException

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

273 {
274 if(preg_match('/^[^\n+\-]*$|^([+-]?\s*[\pL0-9_:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]+[ ]?)+$/u',$a_query) == 0)
275 {
276 throw new ilLuceneQueryParserException('lucene_err_plus_minus');
277 }
278 return true;
279 }

◆ checkQuestionMark()

static ilLuceneQueryParser::checkQuestionMark (   $query)
staticprotected

Check question mark (wild card single character)

Exceptions
LuceneQueryParserException

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

213 {
214 if(preg_match('/^(\?)|([^\pL0-9_+\-:.()\"*?&|!{}\[\]\^~\\@#\/$%\'=]\?+)/u',$query,$matches) != 0)
215 {
216 throw new ilLuceneQueryParserException('lucene_err_question_mark');
217 }
218 return true;
219 }

References $query.

◆ checkQuotes()

static ilLuceneQueryParser::checkQuotes (   $a_query)
staticprotected

Check quotes.

Exceptions
LuceneQueryParserException

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

303 {
304 $matches = preg_match_all('/"/',$a_query,$tmp);
305
306 if($matches == 0)
307 {
308 return true;
309 }
310
311 if(($matches % 2) > 0)
312 {
313 throw new ilLuceneQueryParserException('lucene_err_quotes');
314 }
315
316 if(preg_match('/"\s*"/',$a_query) > 0)
317 {
318 throw new ilLuceneQueryParserException('lucene_err_quotes_not_empty');
319 }
320 return true;
321 }

Referenced by validateQuery().

+ Here is the caller graph for this function:

◆ checkSquiggle()

static ilLuceneQueryParser::checkSquiggle (   $query)
staticprotected

Check squiggles.

Exceptions
LuceneQueryParserException

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

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

References $query.

Referenced by validateQuery().

+ Here is the caller graph for this function:

◆ getQuery()

ilLuceneQueryParser::getQuery ( )

get query

Returns

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

References $parsed_query.

◆ parse()

ilLuceneQueryParser::parse ( )

parse query string

Returns

Reimplemented in ilMailLuceneQueryParser, and ilLuceneAdvancedQueryParser.

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

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

◆ 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 {
69 return TRUE;
70 }
71 if(substr($this->parsed_query, -1) !== '"')
72 {
73 $this->parsed_query .= '*';
74 }
75 return TRUE;
76 }

◆ replaceOwnerCallback()

ilLuceneQueryParser::replaceOwnerCallback (   $matches)
protected

Replace owner callback (preg_replace_callback)

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

91 {
92 if(isset($matches[2]))
93 {
94 if($usr_id = ilObjUser::_loginExists($matches[2]))
95 {
96 return $matches[1].$usr_id;
97 }
98 }
99 return $matches[0];
100 }
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...

References ilObjUser\_loginExists().

+ Here is the call graph for this function:

◆ validateQuery()

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

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

107 {
108 // TODO
109 // First replace all quote characters
110
111
112 #ilLuceneQueryParser::checkAllowedCharacters($a_query);
113 #ilLuceneQueryParser::checkAsterisk($a_query);
114 #ilLuceneQueryParser::checkAmpersands($a_query);
117 #ilLuceneQueryParser::checkExclamationMark($a_query);
118 #ilLuceneQueryParser::checkQuestionMark($a_query);
120 #ilLuceneQueryParser::checkPlusMinus($a_query);
121 #ilLuceneQueryParser::checkANDORNOT($a_query);
123 #ilLuceneQueryParser::checkColon($a_query);
124 return true;
125 }
static checkParenthesis($a_query)
Check parenthesis.
static checkSquiggle($query)
Check squiggles.
static checkQuotes($a_query)
Check quotes.
static checkCaret($query)
Check carets.

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

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

+ 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: