49 $this->config = $config;
50 $this->events = $events;
81 if (empty($query_parts) || empty(array_filter(
$fields))) {
90 throw new DomainException(
"'{$entity_type}' is not a valid entity type");
94 if (!empty($entity_subtype) && is_string($entity_subtype)) {
100 if ($this->events->hasHandler(
'search:results', $search_type)) {
101 $results = $this->events->triggerResults(
'search:results', $search_type,
$options);
126 $options[
'search_type'] = $search_type;
134 $options[
'_elgg_search_service_normalize_options'] =
true;
171 $query = htmlspecialchars(
$query, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401,
'UTF-8');
174 $words = preg_split(
'/\s+/',
$query);
175 $words = array_map(
function ($e) {
190 $options[
'query_parts'] = array_unique(array_filter($parts));
212 $clean_field_property_types =
function ($new_fields) use ($default_fields) {
213 $property_types = array_keys($default_fields);
214 foreach ($property_types as $property_type) {
215 if (empty($new_fields[$property_type])) {
216 $new_fields[$property_type] = [];
218 $new_fields[$property_type] = array_unique($new_fields[$property_type]);
225 $merge_fields =
function ($new_fields) use (&
$fields, $clean_field_property_types) {
226 if (empty($new_fields) || !is_array($new_fields)) {
230 $new_fields = $clean_field_property_types($new_fields);
236 $normalized_options = $this->normalizeTypeSubtypeOptions(
$options);
238 $type_subtype_pairs =
elgg_extract(
'type_subtype_pairs', $normalized_options);
239 if (!empty($type_subtype_pairs)) {
240 foreach ($type_subtype_pairs as $entity_type => $entity_subtypes) {
241 $result = $this->events->triggerResults(
'search:fields', $entity_type,
$options, $default_fields);
248 foreach ($entity_subtypes as $entity_subtype) {
249 $result = $this->events->triggerResults(
'search:fields',
"{$entity_type}:{$entity_subtype}",
$options, $default_fields);
268 foreach (
$fields as $property_type => $property_type_fields) {
269 if (empty(
$options[
'fields'][$property_type])) {
270 $options[
'fields'][$property_type] = [];
274 $allowed = array_intersect($property_type_fields, (array)
$options[
'fields'][$property_type]);
275 $options[
'fields'][$property_type] = array_values(array_unique($allowed));
301 $populate_where =
function ($where, $part) use ($partial_match) {
302 $where->values = $partial_match ?
"%{$part}%" : $part;
303 $where->comparison =
'LIKE';
305 $where->case_sensitive =
false;
310 $attribute_ands = [];
311 foreach ($query_parts as $part) {
313 $where->names = $attribute;
314 $populate_where($where, $part);
315 $attribute_ands[] = $where->prepare($qb, $alias);
318 $ors[] = $qb->
merge($attribute_ands,
'AND');
325 foreach ($query_parts as $part) {
327 $populate_where($where, $part);
328 $metadata_ands[] = $where->prepare($qb, $md_alias);
331 $ors[] = $qb->
merge($metadata_ands,
'AND');
334 if (!empty($annotations)) {
335 $annotations_ands = [];
337 foreach ($query_parts as $part) {
339 $populate_where($where, $part);
340 $annotations_ands[] = $where->prepare($qb, $an_alias);
343 $ors[] = $qb->
merge($annotations_ands,
'AND');
346 return $qb->
merge($ors,
'OR');
normalizeOptions(array $options=[])
Normalize options.
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.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
$fields
Save the configuration of the security.txt contents.
search(array $options=[])
Returns search results as an array of entities, as a batch, or a count, depending on parameters given...
joinAnnotationTable($from_alias= '', $from_column= 'guid', $name=null, $join_type= 'inner', $joined_alias=null)
Join annotations table from alias and return joined table alias.
__construct(Config $config, EventsService $events, Database $db)
Constructor.
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.
joinMetadataTable($from_alias= '', $from_column= 'guid', $name=null, $join_type= 'inner', $joined_alias=null)
Join metadata table from alias and return joined table alias.
normalizeSearchFields(array $options=[])
Normalizes an array of search fields.
$attributes
Elgg AJAX loader.