ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
ilQueryParser Class Reference
+ Collaboration diagram for ilQueryParser:

Public Member Functions

 ilQueryParser ($a_query_str)
 Constructor 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

 $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.

Member Function Documentation

◆ __parseQuotation()

ilQueryParser::__parseQuotation ( )

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

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

Referenced by parse().

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

◆ appendMessage()

ilQueryParser::appendMessage (   $a_msg)

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

References getMessage().

133  {
134  if(strlen($this->getMessage()))
135  {
136  $this->message .= '<br />';
137  }
138  $this->message .= $a_msg;
139  }
+ Here is the call graph for this function:

◆ getAllowedWildcards()

ilQueryParser::getAllowedWildcards ( )

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

References $wildcards_allowed.

Referenced by __parseQuotation(), and parse().

120  {
122  }
+ Here is the caller graph for this function:

◆ getCombination()

ilQueryParser::getCombination ( )

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

References $combination.

Referenced by getLuceneQueryString().

146  {
147  return $this->combination;
148  }
+ Here is the caller graph for this function:

◆ getGlobalMinLength()

ilQueryParser::getGlobalMinLength ( )

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

References $global_min_length.

Referenced by validate().

110  {
112  }
+ Here is the caller graph for this function:

◆ getLuceneQueryString()

ilQueryParser::getLuceneQueryString ( )

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

References getCombination(), and getQuotedWords().

176  {
177  $counter = 0;
178  $tmp_str = "";
179  foreach($this->getQuotedWords(true) as $word) {
180  if($counter++)
181  {
182  $tmp_str .= (" ".strtoupper($this->getCombination())." ");
183  }
184  $tmp_str .= $word;
185  }
186  return $tmp_str;
187  }
getQuotedWords($with_quotation=false)
+ Here is the call graph for this function:

◆ getMessage()

ilQueryParser::getMessage ( )

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

References $message.

Referenced by appendMessage(), and validate().

129  {
130  return $this->message;
131  }
+ Here is the caller graph for this function:

◆ getMinWordLength()

ilQueryParser::getMinWordLength ( )

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

References $min_word_length.

Referenced by parse(), and validate().

92  {
94  }
+ Here is the caller graph for this function:

◆ getQueryString()

ilQueryParser::getQueryString ( )

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

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

151  {
152  return trim($this->query_str);
153  }
+ Here is the caller graph for this function:

◆ getQuotedWords()

ilQueryParser::getQuotedWords (   $with_quotation = false)

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

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

160  {
161  if($with_quotation)
162  {
163  return $this->quoted_words ? $this->quoted_words : array();
164  }
165  else
166  {
167  foreach($this->quoted_words as $word)
168  {
169  $tmp_word[] = str_replace('\"','',$word);
170  }
171  return $tmp_word ? $tmp_word : array();
172  }
173  }
+ Here is the caller graph for this function:

◆ getWords()

ilQueryParser::getWords ( )

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

Referenced by validate().

155  {
156  return $this->words ? $this->words : array();
157  }
+ Here is the caller graph for this function:

◆ ilQueryParser()

ilQueryParser::ilQueryParser (   $a_query_str)

Constructor public.

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

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

57  {
58  global $lng;
59 
60  define(MIN_WORD_LENGTH,3);
61 
62  $this->lng =& $lng;
63 
64  $this->query_str = $a_query_str;
65  $this->message = '';
66 
67  include_once './Services/Search/classes/class.ilSearchSettings.php';
68  $this->settings = ilSearchSettings::getInstance();
69 
70  if(!$this->setMinWordLength(1))
71  {
72  $this->setMinWordLength(MIN_WORD_LENGTH);
73  }
74 
75  $this->setAllowedWildcards(false);
76  }
setMinWordLength($a_length, $a_force=false)
setAllowedWildcards($a_value)
+ Here is the call graph for this function:

◆ parse()

ilQueryParser::parse ( )

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

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

189  {
190  $this->words = array();
191 
192  #if(!strlen($this->getQueryString()))
193  #{
194  # return false;
195  #}
196 
197  $words = explode(' ',trim($this->getQueryString()));
198  foreach($words as $word)
199  {
200  if(!strlen(trim($word)))
201  {
202  continue;
203  }
204 
205  if(strlen(trim($word)) < $this->getMinWordLength())
206  {
207  $this->setMessage(sprintf($this->lng->txt('search_minimum_info'), $this->getMinWordLength()));
208  continue;
209  }
210 
211  $this->words[] = ilUtil::prepareDBString($word);
212  }
213 
214  $fullstr = trim($this->getQueryString());
215  if (!in_array($fullstr, $this->words))
216  {
217  $this->words[] = ilUtil::prepareDBString($fullstr);
218  }
219 
220  if(!$this->getAllowedWildcards())
221  {
222  // #14768
223  foreach($this->words as $idx => $word)
224  {
225  if(!stristr($word, '\\'))
226  {
227  $word = str_replace('%', '\%', $word);
228  $word = str_replace('_', '\_', $word);
229  }
230  $this->words[$idx] = $word;
231  }
232  }
233 
234  // Parse strings like && 'A "B C D" E' as 'A' && 'B C D' && 'E'
235  // Can be used in LIKE search or fulltext search > MYSQL 4.0
236  $this->__parseQuotation();
237 
238  return true;
239  }
static prepareDBString($a_str)
prepare a string for db writing (insert/update)
+ Here is the call graph for this function:

◆ setAllowedWildcards()

ilQueryParser::setAllowedWildcards (   $a_value)

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

Referenced by ilQueryParser().

115  {
116  $this->wildcards_allowed = (bool)$a_value;
117  }
+ Here is the caller graph for this function:

◆ setCombination()

ilQueryParser::setCombination (   $a_combination)

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

142  {
143  $this->combination = $a_combination;
144  }

◆ setGlobalMinLength()

ilQueryParser::setGlobalMinLength (   $a_value)

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

97  {
98  if($a_value !== null)
99  {
100  $a_value = (int)$a_value;
101  if($a_value < 1)
102  {
103  return;
104  }
105  }
106  $this->global_min_length = $a_value;
107  }

◆ setMessage()

ilQueryParser::setMessage (   $a_msg)

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

Referenced by parse(), and validate().

125  {
126  $this->message = $a_msg;
127  }
+ Here is the caller graph for this function:

◆ setMinWordLength()

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

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

References $GLOBALS.

Referenced by ilQueryParser(), ilAuthShibbolethSettingsGUI\loadRule(), and ilObjectCopyGUI\searchSource().

79  {
80  // Due to a bug in mysql fulltext search queries with min_word_legth < 3
81  // might freeze the system.
82  // Thus min_word_length cannot be set to values < 3 if the mysql fulltext is used.
83  if(!$a_force and $this->settings->enabledIndex() and $a_length < 3)
84  {
85  $GLOBALS['ilLog']->write(__METHOD__.': Disabled min word length');
86  return false;
87  }
88  $this->min_word_length = $a_length;
89  return true;
90  }
$GLOBALS['ct_recipient']
+ Here is the caller graph for this function:

◆ validate()

ilQueryParser::validate ( )

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

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

283  {
284  // Words with less than 3 characters
285  if(strlen($this->getMessage()))
286  {
287  return false;
288  }
289  // No search string given
290  if($this->getMinWordLength() and !count($this->getWords()))
291  {
292  $this->setMessage($this->lng->txt('msg_no_search_string'));
293  return false;
294  }
295  // No search string given
296  if($this->getGlobalMinLength() and strlen(str_replace('"', '', $this->getQueryString())) < $this->getGlobalMinLength())
297  {
298  $this->setMessage(sprintf($this->lng->txt('search_minimum_info'), $this->getGlobalMinLength()));
299  return false;
300  }
301 
302  return true;
303  }
+ Here is the call graph for this function:

Field Documentation

◆ $combination

ilQueryParser::$combination

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

Referenced by getCombination().

◆ $global_min_length

ilQueryParser::$global_min_length = null

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

Referenced by getGlobalMinLength().

◆ $lng

ilQueryParser::$lng = null

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

Referenced by ilQueryParser().

◆ $message

ilQueryParser::$message

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

Referenced by getMessage().

◆ $min_word_length

ilQueryParser::$min_word_length = 0

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

Referenced by getMinWordLength().

◆ $query_str

ilQueryParser::$query_str

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

◆ $quoted_words

ilQueryParser::$quoted_words = array()

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

◆ $settings

ilQueryParser::$settings = null
protected

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

◆ $wildcards_allowed

ilQueryParser::$wildcards_allowed
protected

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

Referenced by getAllowedWildcards().


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