ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilQueryParser Class Reference
+ Collaboration diagram for ilQueryParser:

Public Member Functions

 __construct ($a_query_str)
 Constructor @access public. More...
 
 setMinWordLength ($a_length, $a_force=false)
 
 getMinWordLength ()
 
 setGlobalMinLength ($a_value)
 
 getGlobalMinLength ()
 
 setAllowedWildcards ($a_value)
 
 getAllowedWildcards ()
 
 setMessage ($a_msg)
 
 getMessage ()
 
 appendMessage ($a_msg)
 
 setCombination ($a_combination)
 
 getCombination ()
 
 getQueryString ()
 
 getWords ()
 
 getQuotedWords ($with_quotation=false)
 
 getLuceneQueryString ()
 
 parse ()
 
 __parseQuotation ()
 
 validate ()
 

Data Fields

const MIN_WORD_LENGTH = 3
 Minimum of characters required for search. More...
 
 $lng = null
 
 $min_word_length = 0
 
 $global_min_length = null
 
 $query_str
 
 $quoted_words = array()
 
 $message
 
 $combination
 

Protected Attributes

 $settings = null
 
 $wildcards_allowed
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilQueryParser::__construct (   $a_query_str)

Constructor @access public.

Definition at line 61 of file class.ilQueryParser.php.

62 {
63 global $lng;
64
65 define('MIN_WORD_LENGTH',self::MIN_WORD_LENGTH);
66
67 $this->lng = $lng;
68
69 $this->query_str = $a_query_str;
70 $this->message = '';
71
72 include_once './Services/Search/classes/class.ilSearchSettings.php';
74
75 if(!$this->setMinWordLength(1))
76 {
78 }
79
80 $this->setAllowedWildcards(false);
81 }
setMinWordLength($a_length, $a_force=false)
const MIN_WORD_LENGTH
Minimum of characters required for search.
setAllowedWildcards($a_value)
settings()
Definition: settings.php:2

References $lng, ilSearchSettings\getInstance(), MIN_WORD_LENGTH, setAllowedWildcards(), setMinWordLength(), and settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ __parseQuotation()

ilQueryParser::__parseQuotation ( )

Definition at line 246 of file class.ilQueryParser.php.

247 {
248 if(!strlen($this->getQueryString()))
249 {
250 $this->quoted_words[] = '';
251 return false;
252 }
253 $query_str = $this->getQueryString();
254 while(preg_match("/\".*?\"/",$query_str,$matches))
255 {
256 $query_str = str_replace($matches[0],'',$query_str);
257 $this->quoted_words[] = ilUtil::prepareDBString($matches[0]);
258 }
259
260 // Parse the rest
261 $words = explode(' ',trim($query_str));
262 foreach($words as $word)
263 {
264 if(!strlen(trim($word)))
265 {
266 continue;
267 }
268
269 $this->quoted_words[] = ilUtil::prepareDBString($word);
270 }
271
272 if(!$this->getAllowedWildcards())
273 {
274 // #14768
275 foreach($this->quoted_words as $idx => $word)
276 {
277 if(!stristr($word, '\\'))
278 {
279 $word = str_replace('%', '\%', $word);
280 $word = str_replace('_', '\_', $word);
281 }
282 $this->quoted_words[$idx] = $word;
283 }
284 }
285 }
static prepareDBString($a_str)
prepare a string for db writing (insert/update)

References $query_str, getAllowedWildcards(), getQueryString(), and ilUtil\prepareDBString().

Referenced by parse().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendMessage()

ilQueryParser::appendMessage (   $a_msg)

Definition at line 137 of file class.ilQueryParser.php.

138 {
139 if(strlen($this->getMessage()))
140 {
141 $this->message .= '<br />';
142 }
143 $this->message .= $a_msg;
144 }

References getMessage().

+ Here is the call graph for this function:

◆ getAllowedWildcards()

ilQueryParser::getAllowedWildcards ( )

Definition at line 124 of file class.ilQueryParser.php.

125 {
127 }

References $wildcards_allowed.

Referenced by __parseQuotation(), and parse().

+ Here is the caller graph for this function:

◆ getCombination()

ilQueryParser::getCombination ( )

Definition at line 150 of file class.ilQueryParser.php.

151 {
152 return $this->combination;
153 }

References $combination.

Referenced by getLuceneQueryString().

+ Here is the caller graph for this function:

◆ getGlobalMinLength()

ilQueryParser::getGlobalMinLength ( )

Definition at line 114 of file class.ilQueryParser.php.

115 {
117 }

References $global_min_length.

Referenced by validate().

+ Here is the caller graph for this function:

◆ getLuceneQueryString()

ilQueryParser::getLuceneQueryString ( )

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

181 {
182 $counter = 0;
183 $tmp_str = "";
184 foreach($this->getQuotedWords(true) as $word) {
185 if($counter++)
186 {
187 $tmp_str .= (" ".strtoupper($this->getCombination())." ");
188 }
189 $tmp_str .= $word;
190 }
191 return $tmp_str;
192 }
getQuotedWords($with_quotation=false)
$counter

References $counter, getCombination(), and getQuotedWords().

+ Here is the call graph for this function:

◆ getMessage()

ilQueryParser::getMessage ( )

Definition at line 133 of file class.ilQueryParser.php.

134 {
135 return $this->message;
136 }

References $message.

Referenced by appendMessage(), and validate().

+ Here is the caller graph for this function:

◆ getMinWordLength()

ilQueryParser::getMinWordLength ( )

Definition at line 96 of file class.ilQueryParser.php.

97 {
99 }

References $min_word_length.

Referenced by parse(), and validate().

+ Here is the caller graph for this function:

◆ getQueryString()

ilQueryParser::getQueryString ( )

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

156 {
157 return trim($this->query_str);
158 }

Referenced by __parseQuotation(), parse(), and validate().

+ Here is the caller graph for this function:

◆ getQuotedWords()

ilQueryParser::getQuotedWords (   $with_quotation = false)

Definition at line 164 of file class.ilQueryParser.php.

165 {
166 if($with_quotation)
167 {
168 return $this->quoted_words ? $this->quoted_words : array();
169 }
170 else
171 {
172 foreach($this->quoted_words as $word)
173 {
174 $tmp_word[] = str_replace('\"','',$word);
175 }
176 return $tmp_word ? $tmp_word : array();
177 }
178 }

Referenced by getLuceneQueryString(), and ilAdvancedMDFieldDefinitionText\searchObjects().

+ Here is the caller graph for this function:

◆ getWords()

ilQueryParser::getWords ( )

Definition at line 159 of file class.ilQueryParser.php.

160 {
161 return $this->words ? $this->words : array();
162 }

Referenced by validate().

+ Here is the caller graph for this function:

◆ parse()

ilQueryParser::parse ( )

Definition at line 193 of file class.ilQueryParser.php.

194 {
195 $this->words = array();
196
197 #if(!strlen($this->getQueryString()))
198 #{
199 # return false;
200 #}
201
202 $words = explode(' ',trim($this->getQueryString()));
203 foreach($words as $word)
204 {
205 if(!strlen(trim($word)))
206 {
207 continue;
208 }
209
210 if(strlen(trim($word)) < $this->getMinWordLength())
211 {
212 $this->setMessage(sprintf($this->lng->txt('search_minimum_info'), $this->getMinWordLength()));
213 continue;
214 }
215
216 $this->words[] = ilUtil::prepareDBString($word);
217 }
218
219 $fullstr = trim($this->getQueryString());
220 if (!in_array($fullstr, $this->words))
221 {
222 $this->words[] = ilUtil::prepareDBString($fullstr);
223 }
224
225 if(!$this->getAllowedWildcards())
226 {
227 // #14768
228 foreach($this->words as $idx => $word)
229 {
230 if(!stristr($word, '\\'))
231 {
232 $word = str_replace('%', '\%', $word);
233 $word = str_replace('_', '\_', $word);
234 }
235 $this->words[$idx] = $word;
236 }
237 }
238
239 // Parse strings like && 'A "B C D" E' as 'A' && 'B C D' && 'E'
240 // Can be used in LIKE search or fulltext search > MYSQL 4.0
241 $this->__parseQuotation();
242
243 return true;
244 }
sprintf('%.4f', $callTime)

References __parseQuotation(), getAllowedWildcards(), getMinWordLength(), getQueryString(), ilUtil\prepareDBString(), setMessage(), and sprintf.

+ Here is the call graph for this function:

◆ setAllowedWildcards()

ilQueryParser::setAllowedWildcards (   $a_value)

Definition at line 119 of file class.ilQueryParser.php.

120 {
121 $this->wildcards_allowed = (bool)$a_value;
122 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setCombination()

ilQueryParser::setCombination (   $a_combination)

Definition at line 146 of file class.ilQueryParser.php.

147 {
148 $this->combination = $a_combination;
149 }

◆ setGlobalMinLength()

ilQueryParser::setGlobalMinLength (   $a_value)

Definition at line 101 of file class.ilQueryParser.php.

102 {
103 if($a_value !== null)
104 {
105 $a_value = (int)$a_value;
106 if($a_value < 1)
107 {
108 return;
109 }
110 }
111 $this->global_min_length = $a_value;
112 }

◆ setMessage()

ilQueryParser::setMessage (   $a_msg)

Definition at line 129 of file class.ilQueryParser.php.

130 {
131 $this->message = $a_msg;
132 }

Referenced by parse(), and validate().

+ Here is the caller graph for this function:

◆ setMinWordLength()

ilQueryParser::setMinWordLength (   $a_length,
  $a_force = false 
)

Definition at line 83 of file class.ilQueryParser.php.

84 {
85 // Due to a bug in mysql fulltext search queries with min_word_legth < 3
86 // might freeze the system.
87 // Thus min_word_length cannot be set to values < 3 if the mysql fulltext is used.
88 if(!$a_force and $this->settings->enabledIndex() and $a_length < 3)
89 {
90 ilLoggerFactory::getLogger('src')->debug('Disabled min word length');
91 return false;
92 }
93 $this->min_word_length = $a_length;
94 return true;
95 }
static getLogger($a_component_id)
Get component logger.

References ilLoggerFactory\getLogger(), and settings().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate()

ilQueryParser::validate ( )

Definition at line 287 of file class.ilQueryParser.php.

288 {
289 // Words with less than 3 characters
290 if(strlen($this->getMessage()))
291 {
292 return false;
293 }
294 // No search string given
295 if($this->getMinWordLength() and !count($this->getWords()))
296 {
297 $this->setMessage($this->lng->txt('msg_no_search_string'));
298 return false;
299 }
300 // No search string given
301 if($this->getGlobalMinLength() and strlen(str_replace('"', '', $this->getQueryString())) < $this->getGlobalMinLength())
302 {
303 $this->setMessage(sprintf($this->lng->txt('search_minimum_info'), $this->getGlobalMinLength()));
304 return false;
305 }
306
307 return true;
308 }

References getGlobalMinLength(), getMessage(), getMinWordLength(), getQueryString(), getWords(), setMessage(), and sprintf.

+ Here is the call graph for this function:

Field Documentation

◆ $combination

ilQueryParser::$combination

Definition at line 53 of file class.ilQueryParser.php.

Referenced by getCombination().

◆ $global_min_length

ilQueryParser::$global_min_length = null

Definition at line 48 of file class.ilQueryParser.php.

Referenced by getGlobalMinLength().

◆ $lng

ilQueryParser::$lng = null

Definition at line 45 of file class.ilQueryParser.php.

Referenced by __construct().

◆ $message

ilQueryParser::$message

Definition at line 52 of file class.ilQueryParser.php.

Referenced by getMessage().

◆ $min_word_length

ilQueryParser::$min_word_length = 0

Definition at line 47 of file class.ilQueryParser.php.

Referenced by getMinWordLength().

◆ $query_str

ilQueryParser::$query_str

Definition at line 50 of file class.ilQueryParser.php.

Referenced by __parseQuotation().

◆ $quoted_words

ilQueryParser::$quoted_words = array()

Definition at line 51 of file class.ilQueryParser.php.

◆ $settings

ilQueryParser::$settings = null
protected

Definition at line 54 of file class.ilQueryParser.php.

◆ $wildcards_allowed

ilQueryParser::$wildcards_allowed
protected

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

Referenced by getAllowedWildcards().

◆ MIN_WORD_LENGTH

const ilQueryParser::MIN_WORD_LENGTH = 3

Minimum of characters required for search.

Definition at line 43 of file class.ilQueryParser.php.

Referenced by __construct().


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