ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilQueryParser Class Reference
+ Collaboration diagram for ilQueryParser:

Public Member Functions

 __construct ($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

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

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

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

62  {
63  global $DIC;
64 
65  $lng = $DIC['lng'];
66 
67  define('MIN_WORD_LENGTH', self::MIN_WORD_LENGTH);
68 
69  $this->lng = $lng;
70 
71  $this->query_str = $a_query_str;
72  $this->message = '';
73 
74  include_once './Services/Search/classes/class.ilSearchSettings.php';
76 
77  if (!$this->setMinWordLength(1)) {
79  }
80 
81  $this->setAllowedWildcards(false);
82  }
settings()
Definition: settings.php:2
global $DIC
Definition: saml.php:7
const MIN_WORD_LENGTH
Minimum of characters required for search.
setMinWordLength($a_length, $a_force=false)
setAllowedWildcards($a_value)
+ Here is the call graph for this function:

Member Function Documentation

◆ __parseQuotation()

ilQueryParser::__parseQuotation ( )

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

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

Referenced by parse().

232  {
233  if (!strlen($this->getQueryString())) {
234  $this->quoted_words[] = '';
235  return false;
236  }
237  $query_str = $this->getQueryString();
238  while (preg_match("/\".*?\"/", $query_str, $matches)) {
239  $query_str = str_replace($matches[0], '', $query_str);
240  $this->quoted_words[] = ilUtil::prepareDBString($matches[0]);
241  }
242 
243  // Parse the rest
244  $words = explode(' ', trim($query_str));
245  foreach ($words as $word) {
246  if (!strlen(trim($word))) {
247  continue;
248  }
249 
250  $this->quoted_words[] = ilUtil::prepareDBString($word);
251  }
252 
253  if (!$this->getAllowedWildcards()) {
254  // #14768
255  foreach ($this->quoted_words as $idx => $word) {
256  if (!stristr($word, '\\')) {
257  $word = str_replace('%', '\%', $word);
258  $word = str_replace('_', '\_', $word);
259  }
260  $this->quoted_words[$idx] = $word;
261  }
262  }
263  }
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 135 of file class.ilQueryParser.php.

References getMessage().

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

◆ getAllowedWildcards()

ilQueryParser::getAllowedWildcards ( )

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

References $wildcards_allowed.

Referenced by __parseQuotation(), and parse().

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

◆ getCombination()

ilQueryParser::getCombination ( )

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

References $combination.

Referenced by getLuceneQueryString().

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

◆ getGlobalMinLength()

ilQueryParser::getGlobalMinLength ( )

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

References $global_min_length.

Referenced by validate().

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

◆ getLuceneQueryString()

ilQueryParser::getLuceneQueryString ( )

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

References getCombination(), and getQuotedWords().

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

◆ getMessage()

ilQueryParser::getMessage ( )

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

References $message.

Referenced by appendMessage(), and validate().

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

◆ getMinWordLength()

ilQueryParser::getMinWordLength ( )

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

References $min_word_length.

Referenced by parse(), and validate().

97  {
99  }
+ Here is the caller graph for this function:

◆ getQueryString()

ilQueryParser::getQueryString ( )

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

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

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

◆ getQuotedWords()

ilQueryParser::getQuotedWords (   $with_quotation = false)

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

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

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

◆ getWords()

ilQueryParser::getWords ( )

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

Referenced by validate().

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

◆ parse()

ilQueryParser::parse ( )

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

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

186  {
187  $this->words = array();
188 
189  #if(!strlen($this->getQueryString()))
190  #{
191  # return false;
192  #}
193 
194  $words = explode(' ', trim($this->getQueryString()));
195  foreach ($words as $word) {
196  if (!strlen(trim($word))) {
197  continue;
198  }
199 
200  if (strlen(trim($word)) < $this->getMinWordLength()) {
201  $this->setMessage(sprintf($this->lng->txt('search_minimum_info'), $this->getMinWordLength()));
202  continue;
203  }
204 
205  $this->words[] = ilUtil::prepareDBString($word);
206  }
207 
208  $fullstr = trim($this->getQueryString());
209  if (!in_array($fullstr, $this->words)) {
210  $this->words[] = ilUtil::prepareDBString($fullstr);
211  }
212 
213  if (!$this->getAllowedWildcards()) {
214  // #14768
215  foreach ($this->words as $idx => $word) {
216  if (!stristr($word, '\\')) {
217  $word = str_replace('%', '\%', $word);
218  $word = str_replace('_', '\_', $word);
219  }
220  $this->words[$idx] = $word;
221  }
222  }
223 
224  // Parse strings like && 'A "B C D" E' as 'A' && 'B C D' && 'E'
225  // Can be used in LIKE search or fulltext search > MYSQL 4.0
226  $this->__parseQuotation();
227 
228  return true;
229  }
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 117 of file class.ilQueryParser.php.

Referenced by __construct().

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

◆ setCombination()

ilQueryParser::setCombination (   $a_combination)

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

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

◆ setGlobalMinLength()

ilQueryParser::setGlobalMinLength (   $a_value)

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

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

◆ setMessage()

ilQueryParser::setMessage (   $a_msg)

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

Referenced by parse(), and validate().

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

◆ setMinWordLength()

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

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

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

Referenced by __construct(), and ilObjectCopyGUI\searchSource().

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

◆ validate()

ilQueryParser::validate ( )

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

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

266  {
267  // Words with less than 3 characters
268  if (strlen($this->getMessage())) {
269  return false;
270  }
271  // No search string given
272  if ($this->getMinWordLength() and !count($this->getWords())) {
273  $this->setMessage($this->lng->txt('msg_no_search_string'));
274  return false;
275  }
276  // No search string given
277  if ($this->getGlobalMinLength() and strlen(str_replace('"', '', $this->getQueryString())) < $this->getGlobalMinLength()) {
278  $this->setMessage(sprintf($this->lng->txt('search_minimum_info'), $this->getGlobalMinLength()));
279  return false;
280  }
281 
282  return true;
283  }
+ 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(), and ilUserAutoComplete\setResultField().


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