67 if (empty($query_parts) || empty(array_filter(
$fields))) {
76 throw new DomainException(
"'{$entity_type}' is not a valid entity type");
80 if (!empty($entity_subtype) && is_string($entity_subtype)) {
86 if ($this->events->hasHandler(
'search:results', $search_type)) {
87 $results = $this->events->triggerResults(
'search:results', $search_type,
$options);
112 $options[
'search_type'] = $search_type;
120 $options[
'_elgg_search_service_normalize_options'] =
true;
157 $query = htmlspecialchars(
$query, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401,
'UTF-8');
160 $words = preg_split(
'/\s+/',
$query);
161 $words = array_map(
function ($e) {
176 $options[
'query_parts'] = array_unique(array_filter($parts));
198 $clean_field_property_types =
function ($new_fields) use ($default_fields) {
199 $property_types = array_keys($default_fields);
200 foreach ($property_types as $property_type) {
201 if (empty($new_fields[$property_type])) {
202 $new_fields[$property_type] = [];
204 $new_fields[$property_type] = array_unique($new_fields[$property_type]);
211 $merge_fields =
function ($new_fields) use (&
$fields, $clean_field_property_types) {
212 if (empty($new_fields) || !is_array($new_fields)) {
216 $new_fields = $clean_field_property_types($new_fields);
222 $normalized_options = $this->normalizeTypeSubtypeOptions(
$options);
224 $type_subtype_pairs =
elgg_extract(
'type_subtype_pairs', $normalized_options);
225 if (!empty($type_subtype_pairs)) {
226 foreach ($type_subtype_pairs as $entity_type => $entity_subtypes) {
227 $result = $this->events->triggerResults(
'search:fields', $entity_type,
$options, $default_fields);
234 foreach ($entity_subtypes as $entity_subtype) {
235 $result = $this->events->triggerResults(
'search:fields',
"{$entity_type}:{$entity_subtype}",
$options, $default_fields);
254 foreach (
$fields as $property_type => $property_type_fields) {
255 if (empty(
$options[
'fields'][$property_type])) {
256 $options[
'fields'][$property_type] = [];
260 $allowed = array_intersect($property_type_fields, (array)
$options[
'fields'][$property_type]);
261 $options[
'fields'][$property_type] = array_values(array_unique($allowed));
287 $populate_where =
function ($where, $part) use ($partial_match) {
288 $where->values = $partial_match ?
"%{$part}%" : $part;
289 $where->comparison =
'LIKE';
291 $where->case_sensitive =
false;
296 $attribute_ands = [];
297 foreach ($query_parts as $part) {
299 $where->names = $attribute;
300 $populate_where($where, $part);
301 $attribute_ands[] = $where->prepare($qb, $alias);
304 $ors[] = $qb->
merge($attribute_ands,
'AND');
311 foreach ($query_parts as $part) {
313 $populate_where($where, $part);
314 $metadata_ands[] = $where->prepare($qb, $md_alias);
317 $ors[] = $qb->
merge($metadata_ands,
'AND');
320 if (!empty($annotations)) {
321 $annotations_ands = [];
323 foreach ($query_parts as $part) {
325 $populate_where($where, $part);
326 $annotations_ands[] = $where->prepare($qb, $an_alias);
329 $ors[] = $qb->
merge($annotations_ands,
'AND');
332 return $qb->
merge($ors,
'OR');
joinAnnotationTable(string $from_alias= '', string $from_column= 'guid', $name=null,?string $join_type= 'inner', string $joined_alias=null)
Join annotations table from alias and return joined table alias.
normalizeOptions(array $options=[])
Normalize options.
__construct(protected Config $config, protected EventsService $events, protected Database $db)
Constructor.
Builds quereis for matching entities by their attributes.
Exception thrown if a value does not adhere to a defined valid data domain.
Database abstraction query builder.
Builds queries for matching annotations against their properties.
normalizeQuery(array $options=[])
Normalize query parts.
prepareSearchOptions(array $options=[])
Prepare ege* options.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
$config
Advanced site settings, debugging section.
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
$fields
Save the configuration of the security.txt contents.
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
search(array $options=[])
Returns search results as an array of entities, as a batch, or a count, depending on parameters given...
joinMetadataTable(string $from_alias= '', string $from_column= 'guid', $name=null,?string $join_type= 'inner', string $joined_alias=null)
Join metadata table from alias and return joined table alias.
merge($parts=null, $boolean= 'AND')
Merges multiple composite expressions with a boolean.
buildSearchWhereQuery(QueryBuilder $qb, $alias, $fields, $query_parts, $partial_match=true)
Builds search clause.
normalizeSearchFields(array $options=[])
Normalizes an array of search fields.
$attributes
Elgg AJAX loader.