ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 34 of file class.ilQueryParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilQueryParser::__construct (   $a_query_str)

Constructor public.

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

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

58  {
59  global $DIC;
60 
61  $lng = $DIC['lng'];
62 
63  define('MIN_WORD_LENGTH', self::MIN_WORD_LENGTH);
64 
65  $this->lng = $lng;
66 
67  $this->query_str = $a_query_str;
68  $this->message = '';
69 
70  include_once './Services/Search/classes/class.ilSearchSettings.php';
72 
73  if (!$this->setMinWordLength(1)) {
75  }
76 
77  $this->setAllowedWildcards(false);
78  }
settings()
Definition: settings.php:2
const MIN_WORD_LENGTH
Minimum of characters required for search.
global $DIC
Definition: goto.php:24
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 228 of file class.ilQueryParser.php.

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

Referenced by parse().

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

References getMessage().

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

◆ getAllowedWildcards()

ilQueryParser::getAllowedWildcards ( )

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

References $wildcards_allowed.

Referenced by __parseQuotation(), and parse().

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

◆ getCombination()

ilQueryParser::getCombination ( )

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

References $combination.

Referenced by getLuceneQueryString().

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

◆ getGlobalMinLength()

ilQueryParser::getGlobalMinLength ( )

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

References $global_min_length.

Referenced by validate().

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

◆ getLuceneQueryString()

ilQueryParser::getLuceneQueryString ( )

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

References getCombination(), and getQuotedWords().

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

◆ getMessage()

ilQueryParser::getMessage ( )

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

References $message.

Referenced by appendMessage(), and validate().

128  {
129  return $this->message;
130  }
+ 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 148 of file class.ilQueryParser.php.

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

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

◆ getQuotedWords()

ilQueryParser::getQuotedWords (   $with_quotation = false)

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

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

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

◆ getWords()

ilQueryParser::getWords ( )

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

Referenced by validate().

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

◆ parse()

ilQueryParser::parse ( )

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

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

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

Referenced by __construct().

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

◆ setCombination()

ilQueryParser::setCombination (   $a_combination)

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

140  {
141  $this->combination = $a_combination;
142  }

◆ setGlobalMinLength()

ilQueryParser::setGlobalMinLength (   $a_value)

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

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

◆ setMessage()

ilQueryParser::setMessage (   $a_msg)

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

Referenced by parse(), and validate().

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

◆ setMinWordLength()

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

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

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

Referenced by __construct(), ilLDAPSettingsGUI\loadRoleAssignmentRule(), ilAuthShibbolethSettingsGUI\loadRule(), and ilObjectCopyGUI\searchSource().

81  {
82  // Due to a bug in mysql fulltext search queries with min_word_legth < 3
83  // might freeze the system.
84  // Thus min_word_length cannot be set to values < 3 if the mysql fulltext is used.
85  if (!$a_force and $this->settings->enabledIndex() and $a_length < 3) {
86  ilLoggerFactory::getLogger('src')->debug('Disabled min word length');
87  return false;
88  }
89  $this->min_word_length = $a_length;
90  return true;
91  }
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 262 of file class.ilQueryParser.php.

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

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

Referenced by getGlobalMinLength().

◆ $lng

ilQueryParser::$lng = null

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

Referenced by __construct().

◆ $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 43 of file class.ilQueryParser.php.

Referenced by getMinWordLength().

◆ $query_str

ilQueryParser::$query_str

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

Referenced by __parseQuotation().

◆ $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().

◆ MIN_WORD_LENGTH

const ilQueryParser::MIN_WORD_LENGTH = 3

Minimum of characters required for search.

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

Referenced by __construct(), and ilUserAutoComplete\setResultField().


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