50 $this->config = $config;
51 $this->hooks = $hooks;
82 if (empty($query_parts) || empty(array_filter(
$fields))) {
95 if (!empty($entity_subtype) && is_string($entity_subtype)) {
101 if ($this->hooks->hasHandler(
'search:results', $search_type)) {
127 $options[
'search_type'] = $search_type;
135 $options[
'_elgg_search_service_normalize_options'] =
true;
174 $query = htmlspecialchars(
$query, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401,
'UTF-8');
177 $words = preg_split(
'/\s+/',
$query);
178 $words = array_map(
function ($e) {
193 $options[
'query_parts'] = array_unique(array_filter($parts));
211 'private_settings' => [],
216 $clean_field_property_types =
function ($new_fields) use ($default_fields) {
217 $property_types = array_keys($default_fields);
218 foreach ($property_types as $property_type) {
219 if (empty($new_fields[$property_type])) {
220 $new_fields[$property_type] = [];
222 $new_fields[$property_type] = array_unique($new_fields[$property_type]);
229 $merge_fields =
function ($new_fields) use (&
$fields, $clean_field_property_types) {
230 if (empty($new_fields) || !is_array($new_fields)) {
234 $new_fields = $clean_field_property_types($new_fields);
240 $normalized_options = $this->normalizeTypeSubtypeOptions(
$options);
242 $type_subtype_pairs =
elgg_extract(
'type_subtype_pairs', $normalized_options);
243 if (!empty($type_subtype_pairs)) {
244 foreach ($type_subtype_pairs as $entity_type => $entity_subtypes) {
245 $result = $this->hooks->trigger(
'search:fields', $entity_type,
$options, $default_fields);
252 foreach ($entity_subtypes as $entity_subtype) {
253 $result = $this->hooks->trigger(
'search:fields',
"{$entity_type}:{$entity_subtype}",
$options, $default_fields);
272 foreach (
$fields as $property_type => $property_type_fields) {
273 if (empty(
$options[
'fields'][$property_type])) {
274 $options[
'fields'][$property_type] = [];
278 $allowed = array_intersect($property_type_fields, (array)
$options[
'fields'][$property_type]);
279 $options[
'fields'][$property_type] = array_values(array_unique($allowed));
301 if (is_string($sort)) {
308 elgg_deprecated_notice(
"Setting the 'order' option for elgg_search() is deprecated use 'sort_by'",
'4.2');
310 $sort[
'direction'] = $order;
339 $populate_where =
function ($where, $part) use ($partial_match) {
340 $where->values = $partial_match ?
"%{$part}%" : $part;
341 $where->comparison =
'LIKE';
343 $where->case_sensitive =
false;
348 $attribute_ands = [];
349 foreach ($query_parts as $part) {
351 $where->names = $attribute;
352 $populate_where($where, $part);
353 $attribute_ands[] = $where->prepare($qb, $alias);
355 $ors[] = $qb->
merge($attribute_ands,
'AND');
362 foreach ($query_parts as $part) {
364 $populate_where($where, $part);
365 $metadata_ands[] = $where->prepare($qb, $md_alias);
367 $ors[] = $qb->
merge($metadata_ands,
'AND');
370 if (!empty($annotations)) {
371 $annotations_ands = [];
373 foreach ($query_parts as $part) {
375 $populate_where($where, $part);
376 $annotations_ands[] = $where->prepare($qb, $an_alias);
378 $ors[] = $qb->
merge($annotations_ands,
'AND');
381 if (!empty($private_settings)) {
382 $private_settings_ands = [];
384 foreach ($query_parts as $part) {
386 $populate_where($where, $part);
387 $private_settings_ands[] = $where->prepare($qb, $ps_alias);
389 $ors[] = $qb->
merge($private_settings_ands,
'AND');
392 return $qb->
merge($ors,
'OR');
normalizeOptions(array $options=[])
Normalize options.
elgg_deprecated_notice(string $msg, string $dep_version)
Log a notice about deprecated use of a function, view, etc.
__construct(Config $config, PluginHooksService $hooks, Database $db)
Constructor.
Builds quereis for matching entities by their attributes.
Database abstraction query builder.
Builds queries for matching annotations against their properties.
prepareSortOptions(array $options=[])
Normalizes sort options.
normalizeQuery(array $options=[])
Normalize query parts.
prepareSearchOptions(array $options=[])
Prepare ege* options.
if(!$entity instanceof\ElggUser) $fields
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
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.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
joinPrivateSettingsTable($from_alias= '', $from_column= 'guid', $name=null, $join_type= 'inner', $joined_alias=null)
Join private settings 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.
joinMetadataTable($from_alias= '', $from_column= 'guid', $name=null, $join_type= 'inner', $joined_alias=null)
Join metadata table from alias and return joined table alias.
Builds queries for filtering entties by their properties in private_settings table.
normalizeSearchFields(array $options=[])
Normalizes an array of search fields.
$attributes
Elgg AJAX loader.