ILIAS  release_8 Revision v8.24
class.ilAbstractSearch.php
Go to the documentation of this file.
1<?php
18declare(strict_types=1);
19
20abstract class ilAbstractSearch
21{
22 protected ilDBInterface $db;
25
29 protected array $object_types = array('cat','dbk','crs','fold','frm','grp','lm','sahs','glo','mep','htlm','exc','file','qpl','tst','svy','spl',
30 'chat','webr','mcst','sess','pg','st','wiki','book', 'copa', 'lso',
31 'rcat', 'rcrs', 'rfil', 'rglo', 'rgrp', 'rlm', 'rtst', 'rwik');
32
36 private array $id_filter = [];
37
41 private array $fields = [];
42
43
44
45 public function __construct(ilQueryParser $qp_obj)
46 {
47 global $DIC;
48
49 $this->db = $DIC->database();
50 $this->query_parser = $qp_obj;
51 $this->search_result = new ilSearchResult();
52 }
53
54 public function setFields(array $a_fields): void
55 {
56 $this->fields = $a_fields;
57 }
58
62 public function getFields(): array
63 {
64 return $this->fields;
65 }
66
67 public function setFilter(array $a_filter): void
68 {
69 $this->object_types = $a_filter;
70 }
71
72 public function setIdFilter(array $a_id_filter): void
73 {
74 $this->id_filter = $a_id_filter;
75 }
76
80 public function getIdFilter(): array
81 {
82 return $this->id_filter;
83 }
84
85 public function appendToFilter(string $a_type): void
86 {
87 if (!in_array($a_type, $this->object_types)) {
88 $this->object_types[] = $a_type;
89 }
90 }
91
92
96 public function getFilter(): array
97 {
99 }
100
101 public function __createLocateString(): string
102 {
103 if ($this->query_parser->getCombination() == ilQueryParser::QP_COMBINATION_OR) {
104 return '';
105 }
106 if (count($this->fields) > 1) {
107 $tmp_fields = [];
108 foreach ($this->fields as $field) {
109 $tmp_fields[] = array($field,'text');
110 }
111 $complete_str = $this->db->concat($tmp_fields);
112 } else {
113 $complete_str = $this->fields[0];
114 }
115
116 $counter = 0;
117 $locate = '';
118 foreach ($this->query_parser->getQuotedWords() as $word) {
119 $word = str_replace('\%', '%', $word);
120 $word = str_replace('\_', '_', $word);
121
122 $locate .= ',';
123 $locate .= $this->db->locate($this->db->quote($word, 'text'), $complete_str);
124 $locate .= (' found' . $counter++);
125 $locate .= ' ';
126 }
127
128 return $locate;
129 }
130
131 public function __prepareFound(object $row): array
132 {
133 if ($this->query_parser->getCombination() == 'or') {
134 return array();
135 }
136 $counter = 0;
137 $found = [];
138 foreach ($this->query_parser->getQuotedWords() as $word) {
139 $res_found = "found" . $counter++;
140 $found[] = (int) $row->$res_found;
141 }
142 return $found;
143 }
144
145 abstract public function performSearch(): ?ilSearchResult;
146}
setIdFilter(array $a_id_filter)
setFields(array $a_fields)
appendToFilter(string $a_type)
ilSearchResult $search_result
__construct(ilQueryParser $qp_obj)
setFilter(array $a_filter)
global $DIC
Definition: feed.php:28
$errors fields
Definition: imgupload.php:67
Interface ilDBInterface.