ILIAS  release_4-4 Revision
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  $this->quoted_words[] = ilUtil::prepareDBString($word);
264  }
265 
266  if(!$this->getAllowedWildcards())
267  {
268  // #14768
269  foreach($this->quoted_words as $idx => $word)
270  {
271  if(!stristr($word, '\\'))
272  {
273  $word = str_replace('%', '\%', $word);
274  $word = str_replace('_', '\_', $word);
275  }
276  $this->quoted_words[$idx] = $word;
277  }
278  }
279  }
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 133 of file class.ilQueryParser.php.

References getMessage().

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

◆ getAllowedWildcards()

ilQueryParser::getAllowedWildcards ( )

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

References $wildcards_allowed.

Referenced by __parseQuotation(), and parse().

121  {
123  }
+ Here is the caller graph for this function:

◆ getCombination()

ilQueryParser::getCombination ( )

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

References $combination.

Referenced by getLuceneQueryString().

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

◆ getGlobalMinLength()

ilQueryParser::getGlobalMinLength ( )

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

References $global_min_length.

Referenced by validate().

111  {
113  }
+ Here is the caller graph for this function:

◆ getLuceneQueryString()

ilQueryParser::getLuceneQueryString ( )

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

References getCombination(), and getQuotedWords().

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

◆ getMessage()

ilQueryParser::getMessage ( )

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

References $message.

Referenced by appendMessage(), and validate().

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

◆ getMinWordLength()

ilQueryParser::getMinWordLength ( )

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

References $min_word_length.

Referenced by parse(), and validate().

93  {
95  }
+ Here is the caller graph for this function:

◆ getQueryString()

ilQueryParser::getQueryString ( )

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

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

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

◆ getQuotedWords()

ilQueryParser::getQuotedWords (   $with_quotation = false)

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

Referenced by getLuceneQueryString().

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

◆ getWords()

ilQueryParser::getWords ( )

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

Referenced by validate().

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

◆ ilQueryParser()

ilQueryParser::ilQueryParser (   $a_query_str)

Constructor public.

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

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

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

◆ parse()

ilQueryParser::parse ( )

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

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

190  {
191  $this->words = array();
192 
193  #if(!strlen($this->getQueryString()))
194  #{
195  # return false;
196  #}
197 
198  $words = explode(' ',trim($this->getQueryString()));
199  foreach($words as $word)
200  {
201  if(!strlen(trim($word)))
202  {
203  continue;
204  }
205 
206  if(strlen(trim($word)) < $this->getMinWordLength())
207  {
208  $this->setMessage(sprintf($this->lng->txt('search_minimum_info'), $this->getMinWordLength()));
209  continue;
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 115 of file class.ilQueryParser.php.

Referenced by ilQueryParser().

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

◆ setCombination()

ilQueryParser::setCombination (   $a_combination)

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

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

◆ setGlobalMinLength()

ilQueryParser::setGlobalMinLength (   $a_value)

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

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

◆ setMessage()

ilQueryParser::setMessage (   $a_msg)

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

Referenced by parse(), and validate().

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

◆ setMinWordLength()

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

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

References $GLOBALS.

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

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

◆ validate()

ilQueryParser::validate ( )

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

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

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

Field Documentation

◆ $combination

ilQueryParser::$combination

Definition at line 49 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 48 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 46 of file class.ilQueryParser.php.

◆ $quoted_words

ilQueryParser::$quoted_words = array()

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

◆ $settings

ilQueryParser::$settings = null
protected

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

◆ $wildcards_allowed

ilQueryParser::$wildcards_allowed
protected

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

Referenced by getAllowedWildcards().


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