ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $lng, ilSearchSettings\getInstance(), MIN_WORD_LENGTH, setAllowedWildcards(), setMinWordLength(), and settings().

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)) {
77  }
78 
79  $this->setAllowedWildcards(false);
80  }
const MIN_WORD_LENGTH
Minimum of characters required for search.
settings()
Definition: settings.php:2
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 229 of file class.ilQueryParser.php.

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

Referenced by parse().

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

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

172  {
173  $counter = 0;
174  $tmp_str = "";
175  foreach ($this->getQuotedWords(true) as $word) {
176  if ($counter++) {
177  $tmp_str .= (" " . strtoupper($this->getCombination()) . " ");
178  }
179  $tmp_str .= $word;
180  }
181  return $tmp_str;
182  }
getQuotedWords($with_quotation=false)
$counter
+ 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 94 of file class.ilQueryParser.php.

References $min_word_length.

Referenced by parse(), and validate().

95  {
97  }
+ 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.

References array.

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

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

◆ getWords()

ilQueryParser::getWords ( )

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

References array.

Referenced by validate().

155  {
156  return $this->words ? $this->words : array();
157  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ parse()

ilQueryParser::parse ( )

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

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

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

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 141 of file class.ilQueryParser.php.

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

◆ setGlobalMinLength()

ilQueryParser::setGlobalMinLength (   $a_value)

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

100  {
101  if ($a_value !== null) {
102  $a_value = (int) $a_value;
103  if ($a_value < 1) {
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 82 of file class.ilQueryParser.php.

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

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

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

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

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