ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilQueryParser Class Reference
+ Collaboration diagram for ilQueryParser:

Public Member Functions

 __construct (string $a_query_str)
 
 setMinWordLength (int $a_length)
 
 getMinWordLength ()
 
 setGlobalMinLength (int $a_value)
 
 getGlobalMinLength ()
 
 setAllowedWildcards (bool $a_value)
 
 getAllowedWildcards ()
 
 setMessage (string $a_msg)
 
 getMessage ()
 
 appendMessage (string $a_msg)
 
 setCombination (string $a_combination)
 
 getCombination ()
 
 getQueryString ()
 
 getWords ()
 
 getQuotedWords (bool $with_quotation=false)
 
 getLuceneQueryString ()
 
 parse ()
 
 __parseQuotation ()
 
 validate ()
 

Data Fields

const MIN_WORD_LENGTH = 3
 Minimum of characters required for search. More...
 
const QP_COMBINATION_AND = 'and'
 
const QP_COMBINATION_OR = 'or'
 

Protected Attributes

ilLanguage $lng
 
ilSearchSettings $settings
 

Private Attributes

int $min_word_length = 0
 
int $global_min_length = 0
 
string $query_str
 
array $quoted_words = array()
 
string $message
 
string $combination = ''
 
bool $wildcards_allowed
 
array $words
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilQueryParser::__construct ( string  $a_query_str)

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

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

58  {
59  global $DIC;
60 
61  $this->lng = $DIC->language();
63 
64  if (!defined('MIN_WORD_LENGTH')) {
65  define('MIN_WORD_LENGTH', self::MIN_WORD_LENGTH);
66  }
67 
68 
69  $this->query_str = $a_query_str;
70  $this->message = '';
71 
72  $this->setMinWordLength(1);
73 
74  $this->setAllowedWildcards(false);
75  }
setMinWordLength(int $a_length)
global $DIC
Definition: shib_login.php:22
setAllowedWildcards(bool $a_value)
+ Here is the call graph for this function:

Member Function Documentation

◆ __parseQuotation()

ilQueryParser::__parseQuotation ( )

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

References getAllowedWildcards(), and getQueryString().

Referenced by parse().

218  : bool
219  {
220  if (!strlen($this->getQueryString())) {
221  $this->quoted_words[] = '';
222  return false;
223  }
224  $query_str = $this->getQueryString();
225  while (preg_match("/\".*?\"/", $query_str, $matches)) {
226  $query_str = str_replace($matches[0], '', $query_str);
227  $this->quoted_words[] = $matches[0];
228  }
229 
230  // Parse the rest
231  $words = explode(' ', trim($query_str));
232  foreach ($words as $word) {
233  if (!strlen(trim($word))) {
234  continue;
235  }
236 
237  $this->quoted_words[] = $word;
238  }
239 
240  if (!$this->getAllowedWildcards()) {
241  // #14768
242  foreach ($this->quoted_words as $idx => $word) {
243  if (!stristr($word, '\\')) {
244  $word = str_replace('%', '\%', $word);
245  $word = str_replace('_', '\_', $word);
246  }
247  $this->quoted_words[$idx] = $word;
248  }
249  }
250  return true;
251  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendMessage()

ilQueryParser::appendMessage ( string  $a_msg)

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

References getMessage().

119  : void
120  {
121  if (strlen($this->getMessage())) {
122  $this->message .= '<br />';
123  }
124  $this->message .= $a_msg;
125  }
+ Here is the call graph for this function:

◆ getAllowedWildcards()

ilQueryParser::getAllowedWildcards ( )

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

References $wildcards_allowed.

Referenced by __parseQuotation(), and parse().

106  : bool
107  {
109  }
+ Here is the caller graph for this function:

◆ getCombination()

ilQueryParser::getCombination ( )

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

References $combination.

Referenced by getLuceneQueryString().

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

◆ getGlobalMinLength()

ilQueryParser::getGlobalMinLength ( )

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

References $global_min_length.

Referenced by validate().

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

◆ getLuceneQueryString()

ilQueryParser::getLuceneQueryString ( )

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

References getCombination(), and getQuotedWords().

164  : string
165  {
166  $counter = 0;
167  $tmp_str = "";
168  foreach ($this->getQuotedWords(true) as $word) {
169  if ($counter++) {
170  $tmp_str .= (" " . strtoupper($this->getCombination()) . " ");
171  }
172  $tmp_str .= $word;
173  }
174  return $tmp_str;
175  }
getQuotedWords(bool $with_quotation=false)
+ Here is the call graph for this function:

◆ getMessage()

ilQueryParser::getMessage ( )

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

References $message.

Referenced by appendMessage(), and validate().

115  : string
116  {
117  return $this->message;
118  }
+ Here is the caller graph for this function:

◆ getMinWordLength()

ilQueryParser::getMinWordLength ( )

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

References $min_word_length.

Referenced by parse(), and validate().

82  : int
83  {
85  }
+ Here is the caller graph for this function:

◆ getQueryString()

ilQueryParser::getQueryString ( )

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

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

136  : string
137  {
138  return trim($this->query_str);
139  }
+ Here is the caller graph for this function:

◆ getQuotedWords()

ilQueryParser::getQuotedWords ( bool  $with_quotation = false)
Returns
string[]

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

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

152  : array
153  {
154  if ($with_quotation) {
155  return $this->quoted_words ?: [];
156  }
157 
158  foreach ($this->quoted_words as $word) {
159  $tmp_word[] = str_replace("\"", '', $word);
160  }
161  return $tmp_word ?? [];
162  }
+ Here is the caller graph for this function:

◆ getWords()

ilQueryParser::getWords ( )
Returns
string[]

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

Referenced by validate().

144  : array
145  {
146  return $this->words ?? array();
147  }
+ Here is the caller graph for this function:

◆ parse()

ilQueryParser::parse ( )

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

References __parseQuotation(), getAllowedWildcards(), getMinWordLength(), getQueryString(), ILIAS\Repository\lng(), and setMessage().

176  : bool
177  {
178  $this->words = array();
179 
180 
181  $words = explode(' ', trim($this->getQueryString()));
182  foreach ($words as $word) {
183  if (!strlen(trim($word))) {
184  continue;
185  }
186 
187  if (strlen(trim($word)) < $this->getMinWordLength()) {
188  $this->setMessage(sprintf($this->lng->txt('search_minimum_info'), $this->getMinWordLength()));
189  continue;
190  }
191 
192  $this->words[] = $word;
193  }
194 
195  $fullstr = trim($this->getQueryString());
196  if (!in_array($fullstr, $this->words)) {
197  $this->words[] = $fullstr;
198  }
199 
200  if (!$this->getAllowedWildcards()) {
201  // #14768
202  foreach ($this->words as $idx => $word) {
203  if (!stristr($word, '\\')) {
204  $word = str_replace('%', '\%', $word);
205  $word = str_replace('_', '\_', $word);
206  }
207  $this->words[$idx] = $word;
208  }
209  }
210 
211  // Parse strings like && 'A "B C D" E' as 'A' && 'B C D' && 'E'
212  // Can be used in LIKE search or fulltext search > MYSQL 4.0
213  $this->__parseQuotation();
214 
215  return true;
216  }
setMessage(string $a_msg)
+ Here is the call graph for this function:

◆ setAllowedWildcards()

ilQueryParser::setAllowedWildcards ( bool  $a_value)

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

Referenced by __construct().

101  : void
102  {
103  $this->wildcards_allowed = $a_value;
104  }
+ Here is the caller graph for this function:

◆ setCombination()

ilQueryParser::setCombination ( string  $a_combination)

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

127  : void
128  {
129  $this->combination = $a_combination;
130  }

◆ setGlobalMinLength()

ilQueryParser::setGlobalMinLength ( int  $a_value)

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

87  : void
88  {
89  if ($a_value < 1) {
90  return;
91  }
92 
93  $this->global_min_length = $a_value;
94  }

◆ setMessage()

ilQueryParser::setMessage ( string  $a_msg)

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

Referenced by parse(), and validate().

111  : void
112  {
113  $this->message = $a_msg;
114  }
+ Here is the caller graph for this function:

◆ setMinWordLength()

ilQueryParser::setMinWordLength ( int  $a_length)

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

Referenced by __construct(), ilLDAPSettingsGUI\loadRoleAssignmentRule(), ilAuthShibbolethSettingsGUI\loadRule(), and ilUserStartingPointGUI\saveStartingPoint().

77  : void
78  {
79  $this->min_word_length = $a_length;
80  }
+ Here is the caller graph for this function:

◆ validate()

ilQueryParser::validate ( )

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

References getGlobalMinLength(), getMessage(), getMinWordLength(), getQueryString(), getWords(), ILIAS\Repository\lng(), and setMessage().

253  : bool
254  {
255  // Words with less than 3 characters
256  if (strlen($this->getMessage())) {
257  return false;
258  }
259  // No search string given
260  if ($this->getMinWordLength() and !count($this->getWords())) {
261  $this->setMessage($this->lng->txt('msg_no_search_string'));
262  return false;
263  }
264  // No search string given
265  if ($this->getGlobalMinLength() and strlen(str_replace('"', '', $this->getQueryString())) < $this->getGlobalMinLength()) {
266  $this->setMessage(sprintf($this->lng->txt('search_minimum_info'), $this->getGlobalMinLength()));
267  return false;
268  }
269 
270  return true;
271  }
setMessage(string $a_msg)
+ Here is the call graph for this function:

Field Documentation

◆ $combination

string ilQueryParser::$combination = ''
private

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

Referenced by getCombination().

◆ $global_min_length

int ilQueryParser::$global_min_length = 0
private

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

Referenced by getGlobalMinLength().

◆ $lng

ilLanguage ilQueryParser::$lng
protected

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

◆ $message

string ilQueryParser::$message
private

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

Referenced by getMessage().

◆ $min_word_length

int ilQueryParser::$min_word_length = 0
private

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

Referenced by getMinWordLength().

◆ $query_str

string ilQueryParser::$query_str
private

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

◆ $quoted_words

array ilQueryParser::$quoted_words = array()
private

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

◆ $settings

ilSearchSettings ilQueryParser::$settings
protected

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

◆ $wildcards_allowed

bool ilQueryParser::$wildcards_allowed
private

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

Referenced by getAllowedWildcards().

◆ $words

array ilQueryParser::$words
private

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

◆ MIN_WORD_LENGTH

const ilQueryParser::MIN_WORD_LENGTH = 3

Minimum of characters required for search.

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

Referenced by ilUserAutoComplete\getList().

◆ QP_COMBINATION_AND

◆ QP_COMBINATION_OR


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