ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilMailLuceneQueryParser.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  protected array $fields = [];
24 
25  public function parse(): void
26  {
27  if ($this->getFields()) {
28  $queried_fields = [];
29  $token_operator = ' OR ';
30  if (ilSearchSettings::getInstance()->getDefaultOperator() === ilSearchSettings::OPERATOR_AND) {
31  $token_operator = ' AND ';
32  }
33 
34  foreach ($this->getFields() as $field => $status) {
35  if (!$status) {
36  continue;
37  }
38 
39  $field_query = '';
40  $tokens = array_map(trim(...), explode(' ', $this->query_string));
41  foreach ($tokens as $token) {
42  if ($field_query !== '') {
43  $field_query .= $token_operator;
44  }
45  $field_query .= '(' . $field . ':' . $token . ')';
46  }
47 
48  $queried_fields[] = '(' . $field_query . ')';
49  }
50 
51  if ($queried_fields !== []) {
52  $this->parsed_query = implode(' OR ', $queried_fields);
53  return;
54  }
55  }
56 
57  parent::parse();
58  }
59 
60  public function setFields(array $fields): void
61  {
62  $this->fields = $fields;
63  }
64 
65  public function getFields(): array
66  {
67  return $this->fields;
68  }
69 }
$token
Definition: xapitoken.php:70