ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 ()
 
 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 130 of file class.ilLuceneQueryParser.php.

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

References $query.

◆ checkAmpersands()

static ilLuceneQueryParser::checkAmpersands (   $query)
staticprotected

Check ampersands.

Exceptions
LuceneQueryParserException

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

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

References $query.

◆ checkANDORNOT()

static ilLuceneQueryParser::checkANDORNOT (   $a_query)
staticprotected

Check AND OR NOT.

Exceptions
LuceneQueryParserException

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

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

◆ checkAsterisk()

static ilLuceneQueryParser::checkAsterisk (   $query)
staticprotected

Check asterisk.

Exceptions
LuceneQueryParserException

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

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

References $query.

◆ checkCaret()

static ilLuceneQueryParser::checkCaret (   $query)
staticprotected

Check carets.

Exceptions
LuceneQueryParserException

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

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

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

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

◆ checkExclamationMark()

static ilLuceneQueryParser::checkExclamationMark (   $query)
staticprotected

Check exclamation marks (replacement for NOT)

Exceptions
LuceneQueryParserException

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

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

References $query.

◆ checkParenthesis()

static ilLuceneQueryParser::checkParenthesis (   $a_query)
staticprotected

Check parenthesis.

Exceptions
LuceneQueryParserException

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

217 {
218 $hasLft = false;
219 $hasRgt = false;
220
221 $matchLft = 0;
222 $matchRgt = 0;
223
224 $tmp = array();
225
226 if (($matchLft = preg_match_all('/[(]/', $a_query, $tmp)) > 0) {
227 $hasLft = true;
228 }
229 if (($matchRgt = preg_match_all('/[)]/', $a_query, $tmp)) > 0) {
230 $hasRgt = true;
231 }
232
233 if (!$hasLft || !$hasRgt) {
234 return true;
235 }
236
237
238 if (($hasLft && !$hasRgt) || ($hasRgt && !$hasLft)) {
239 throw new ilLuceneQueryParserException('lucene_err_parenthesis_not_closed');
240 }
241
242 if ($matchLft !== $matchRgt) {
243 throw new ilLuceneQueryParserException('lucene_err_parenthesis_not_closed');
244 }
245
246 if (preg_match('/\‍(\s*\‍)/', $a_query) > 0) {
247 throw new ilLuceneQueryParserException('lucene_err_parenthesis_empty');
248 }
249 return true;
250 }

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

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

◆ checkQuestionMark()

static ilLuceneQueryParser::checkQuestionMark (   $query)
staticprotected

Check question mark (wild card single character)

Exceptions
LuceneQueryParserException

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

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

References $query.

◆ checkQuotes()

static ilLuceneQueryParser::checkQuotes (   $a_query)
staticprotected

Check quotes.

Exceptions
LuceneQueryParserException

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

286 {
287 $matches = preg_match_all('/"/', $a_query, $tmp);
288
289 if ($matches == 0) {
290 return true;
291 }
292
293 if (($matches % 2) > 0) {
294 throw new ilLuceneQueryParserException('lucene_err_quotes');
295 }
296
297 if (preg_match('/"\s*"/', $a_query) > 0) {
298 throw new ilLuceneQueryParserException('lucene_err_quotes_not_empty');
299 }
300 return true;
301 }

Referenced by validateQuery().

+ Here is the caller graph for this function:

◆ checkSquiggle()

static ilLuceneQueryParser::checkSquiggle (   $query)
staticprotected

Check squiggles.

Exceptions
LuceneQueryParserException

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

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

References $query.

Referenced by validateQuery().

+ Here is the caller graph for this function:

◆ getQuery()

ilLuceneQueryParser::getQuery ( )

get query

Returns

Definition at line 83 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

!!!DIC refactoring-script warning.!!! There is an isolated 'global' whithout any variable behind. Either this is a comment, or something is seriously wrong

Returns
boolean

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

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

◆ replaceOwnerCallback()

ilLuceneQueryParser::replaceOwnerCallback (   $matches)
protected

Replace owner callback (preg_replace_callback)

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

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

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